最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Exclude admin from user list

programmeradmin4浏览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']);

}

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']);

}
Share Improve this question asked Feb 8, 2017 at 9:43 PKGPKG 112 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

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.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论