Thursday, September 1, 2022
HomeWordPress DevelopmentIs there a approach to take away/disguise the record of admins with...

Is there a approach to take away/disguise the record of admins with out SQL queries with ‘pre_user_query’ if a consumer has list_user caps however not admin caps?


There are examples on WordPress Stackexchange that recommend code equivalent to:

/** Disguise Administrator From Person Record **/
operate isa_pre_user_query( $user_search ) {
    if ( !current_user_can( 'administrator' ) ) { // Is Not Administrator - Take away Administrator
        international $wpdb;

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

add_action( 'pre_user_query', 'isa_pre_user_query' );

There’s additionally a tutorial from Misha Rudrastyh with an identical method.

Is there a approach to obtain an identical consequence with a local WordPress operate?

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments