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
1 Answer
Reset to default 1You 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.