set_role has no effect

You can use wp_update_user to update the role for your newly created user. if ( !username_exists( ‘mytestuser’ ) ) { $user_id = wp_create_user(‘mytestuser’, ‘testpass345′,’[email protected]’); $user_id = wp_update_user( array( ‘ID’ => $user_id, ‘role’ => ‘author’ ) ); } Further reading at WordPress Codex. Or, you can remove the current role and assign a new one: if … Read more

Add a new subscriber role using a function

A subscriber has only 1 capability namely: read To create a new (custom)role just add following code-lines in functions.php. Please make back-up first and so on…. When added to functions.php go into the back-end and check if you can add an (new or existing) user to this role. When all is working you can delete … Read more

How to display user role

Change: $user_roles = $current_user->roles; with $user = new WP_User( $user_id ); $user_roles = $user->roles; and the $user_id should e the actual user id who’s role you are trying to get. Update, Sorry i just read the author template part so try this: //first get the current author whos page you are viewing if(isset($_GET[‘author_name’])) $curauth = … Read more

Custom Roll/Custom Post Type – Can’t Select Categories

I had the same problem, a custom role couldn’t assign categories to my CPT. When doing register_taxonomy(), I added these capabilities: ‘capabilities’ => array ( ‘manage_terms’ => ‘manage_options’, //by default only admin ‘edit_terms’ => ‘manage_options’, ‘delete_terms’ => ‘manage_options’, ‘assign_terms’ => ‘edit_cpt-type’ // can edit cpt-type i.e. custom role ), Hope this helps to people and … Read more

Ajax call in wordpress not working for subscriber user in front site

For non-admin users to be able to use an ajax function, you need to also include a second hook using wp_ajax_nopriv So right after this: add_action(‘wp_ajax_add_category_bookly’, ‘add_category_bookly_callback’); you should include this: add_action(‘wp_ajax_nopriv_add_category_bookly’, ‘add_category_bookly_callback’);

Checking for user role in a custom plugin

Why it doesn’t work for a Plugin: It doesn’t work for plugin because by the time WordPress executes $current_user = wp_get_current_user(); in a plugin, the function wp_get_current_user() isn’t defined yet. WordPress loads that plugin file before it defines those user related functions. However, it works for theme because WordPress loads theme after it defines and … Read more

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