I am working on a multi-user WordPress setup and have made it so a particular type of user can only add/edit users that they have authored. The code for this like this:

function isa_pre_user_query( $user_search ) {
if ( current_user_can( 'contributor' ) ) { 
    global $wpdb;

    $user_search->query_where = str_replace(
        'WHERE 1=1', 
        "WHERE 1=1 AND {$wpdb->users}.ID IN (
          SELECT {$wpdb->usermeta}.user_id FROM $wpdb->usermeta 
          WHERE {$wpdb->usermeta}.meta_key = '{$wpdb->prefix}capabilities'
          AND {$wpdb->usermeta}.meta_value LIKE '%editor%' )", 
}add_action( 'pre_user_query', 'isa_pre_user_query' );  

This works well but the user counts displays incorrectly.

enter image description here
enter image description here

i renamed all roles as Administrator=>System User,Subscriber=>Salesman,Customer=>Stock Purchaser,Contributor=>Customer Relationship Officer,Editor=>Dealer.
By using above function i successfully listed dealers only to Customer Relationship Officer as cro can add only dealer. So how can i change user count and show only dealer count and all for dealer count. Please can anybody suggest me a way to do this.


After searching I created a hook for that and that hook is:

add_filter("views_users", 'custom_editor_counts', 10, 1);

function custom_editor_counts($views) {
    if ( current_user_can( 'contributor' ) ) {
        return $views;
        return $views;

This works for me.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.