Learndash change user role after completing the course

Got it fixed. Here is the code: add_action(‘wp_head’, function(){ if(is_user_logged_in()){ $user = wp_get_current_user(); if ( in_array( ‘pre_subscriber’, (array) $user->roles ) ) { $passed = learndash_user_quiz_has_completed($user->ID, 8731, 8388); if($passed){ // Remove role $user->remove_role( ‘pre_subscriber’ ); // Add role $user->add_role( ‘subscriber’ ); } } }} );

Retrieve user roles but exclude default roles

So I ended up using a combination of the array_filter function and the in_array function to retrieve all custom roles like this: <?php function check_roles($userRole) { $default_roles = array(‘Administrator’, ‘Editor’, ‘Author’, ‘Contributor’, ‘Subscriber’); if (!in_array($userRole, $default_roles)) { return $userRole; } } $all_roles = wp_roles()->get_names(); $custom_roles = array_filter($all_roles, ‘check_roles’); foreach ($custom_roles as $role) { echo $role; … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)