0

Hi i'm fairly new to PHP and Wordpress, i'm using a plugin (Users Insight) to list all users on my site.

The problem is, that i don't want to admin to appear in that list.

So far i've found the function that calls to list, but i'm not sure how to edit it so that it exclude the admin role.

 <?php 
    public function get_users($default_fields = null){
    global $wpdb;



    $this->build_query($default_fields);
    $results =  $wpdb->get_results( $this->query );

    $total = $wpdb->get_var( 'SELECT FOUND_ROWS()' );
    $users = $this->db_rows_to_objects($results);



    $all_users = count_users();
    return array('users'=>$users, 'total'=> $total, 'alltotal'=>$all_users['total_users']);

}
0

You could use user_can( $user_id, 'manage_options' ) to gauge the ids in the users array and unset($users->[$x]) the appropriate row.

I would personally use

$users = array();    
foreach ($results as $user)
  if (!user_can( $user->ID, 'manage_options' )) 
    $users[] = $user;

But that's just me.

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.