How do I list in the backend all users that were assigned to a custom role?

User queries There is a WP_User_Query, analogous to WP_Query for posts: $wp_user_search = new WP_User_Query( array( ‘role’ => ‘editor’ ) ); $editors = $wp_user_search->get_results(); Usually this returns an array of row objects from the user table: echo ‘<ul>’; foreach ($editors as $editor): echo ‘<li>’.$edtior->display_name.'</li>’; endforeach; echo ‘</ul>’; However you can specify it to instead return … Read more

Allow Administrator role access to custom capabilities [duplicate]

Referring to the Codex entry for this, I suggest using another hook. They use the ‘admin_init’ action: function add_theme_caps() { $role = get_role( ‘author’ ); // gets the author role $role->add_cap( ‘edit_others_posts’ ); // would allow the author to edit others’ posts for current theme only } add_action( ‘admin_init’, ‘add_theme_caps’);

Hide Menu items base on capability

Create a custom walker. Redefine the method start_el() only: function start_el( &$output, $item, $depth, $args ) { if ( ‘Your secret item title’ !== $item->title or current_user_can( ‘administrator’ ) ) { parent::start_el( &$output, $item, $depth, $args ); } } Please mind that this is just pseudo code. I can not give it a test at … Read more

Only allow administrators and editors to access wp-admin

You’re correct in that you should be checking for a capability. However, manage options is only given to administrators by default. You should check against a capability that both editors and administrators have such as delete_others_posts. function restrict_admin(){ //if not administrator, kill WordPress execution and provide a message if ( ! current_user_can( ‘delete_others_posts’ ) ) … Read more

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