예제 #1
0
 /**
  * Ajax callback function to search users, used on exclude setting page
  *
  * @uses \WP_User_Query
  */
 public function get_users()
 {
     if (!defined('DOING_AJAX') || !current_user_can($this->plugin->admin->settings_cap)) {
         return;
     }
     check_ajax_referer('stream_get_users', 'nonce');
     $response = (object) array('status' => false, 'message' => esc_html__('There was an error in the request', 'stream'));
     $search = '';
     if (isset($_POST['find'])) {
         // @TODO: Make this pass phpcs
         $search = esc_html(wp_unslash(trim($_POST['find'])));
         // input var okay
     }
     $request = (object) array('find' => $search);
     add_filter('user_search_columns', array($this, 'add_display_name_search_columns'), 10, 3);
     $users = new WP_User_Query(array('search' => "*{$request->find}*", 'search_columns' => array('user_login', 'user_nicename', 'user_email', 'user_url'), 'orderby' => 'display_name', 'number' => $this->plugin->admin->preload_users_max));
     remove_filter('user_search_columns', array($this, 'add_display_name_search_columns'), 10);
     if (0 === $users->get_total()) {
         wp_send_json_error($response);
     }
     $response->status = true;
     $response->message = '';
     $response->users = array();
     foreach ($users->results as $key => $user) {
         $author = new Author($user->ID);
         $args = array('id' => $author->ID, 'text' => $author->display_name);
         $args['tooltip'] = esc_attr(sprintf(__("ID: %d\nUser: %s\nEmail: %s\nRole: %s", 'stream'), $author->id, $author->user_login, $author->user_email, ucwords($author->get_role())));
         $args['icon'] = $author->get_avatar_src(32);
         $response->users[] = $args;
     }
     if (empty($search) || preg_match('/wp|cli|system|unknown/i', $search)) {
         $author = new Author(0);
         $response->users[] = array('id' => $author->id, 'text' => $author->get_display_name(), 'icon' => $author->get_avatar_src(32), 'tooltip' => esc_html__('Actions performed by the system when a user is not logged in (e.g. auto site upgrader, or invoking WP-CLI without --user)', 'stream'));
     }
     wp_send_json_success($response);
 }
예제 #2
0
 public function get_users_record_meta($authors)
 {
     $authors_records = array();
     foreach ($authors as $user_id => $args) {
         $author = new Author($user_id);
         $authors_records[$user_id] = array('text' => $author->get_display_name(), 'id' => $user_id, 'label' => $author->get_display_name(), 'icon' => $author->get_avatar_src(32), 'title' => '');
     }
     return $authors_records;
 }