0

$all_user[] = array("count"=>"#","uid"=>"User ID","uname"=>"User Name","dname"=>"Display Name","email"=>"Email","fname"=>"Full Name","role"=>"User Role","rdate"=>"Registration Date");
  $args = array( 'role__in' => array( 'um_admins', 'um_grow' ) );
 $users = get_users($args);
 $role = '';
 $count = 1;
 foreach($users as $user){
  $user_meta = get_userdata($user->ID);
  $full_name = $user_meta->first_name.' '.$user_meta->last_name;
  // get_user_meta( $user->ID, 'first_name', true ).' '.get_user_meta( $user->ID, 'last_name', true );
  $user_roles = $user->roles;
  if ( in_array( 'um_admins', $user_roles, true ) ) {
      $role = 'Admins';
  }elseif(in_array( 'um_grow', $user_roles, true )){
   $role = 'Growers';
  }
   $all_user[] = array("count"=>$count,"uid"=>$user->data->ID,"uname"=>$user->data->user_login,"dname"=>$user->data->display_name,"email"=>$user->data->user_email,
   "fname"=>$full_name,"role"=>$role,"rdate"=>$user->data->user_registered);
  $count++;
 }
 echo json_encode($all_user);

Jagdish Sarma Asked question March 27, 2023
Add a Comment