public static function get_users() { if (!defined('DOING_AJAX') || !current_user_can(MainWP_WP_Stream_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', 'mainwp-child-reports')); $search = isset($_POST['find']) ? wp_unslash(trim($_POST['find'])) : ''; $request = (object) array('find' => $search); add_filter('user_search_columns', array(__CLASS__, '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' => MainWP_WP_Stream_Admin::PRELOAD_AUTHORS_MAX)); remove_filter('user_search_columns', array(__CLASS__, 'add_display_name_search_columns'), 10); if (0 === $users->get_total()) { wp_send_json_error($response); } $response->status = true; $response->message = ''; $response->users = array(); require_once MAINWP_WP_STREAM_INC_DIR . 'class-wp-stream-author.php'; foreach ($users->results as $key => $user) { $author = new MainWP_WP_Stream_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", 'mainwp-child-reports'), $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 MainWP_WP_Stream_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)', 'mainwp-child-reports')); } wp_send_json_success($response); }
public static function get_authors_record_meta($authors) { require_once MAINWP_WP_STREAM_INC_DIR . 'class-wp-stream-author.php'; $authors_records = array(); foreach ($authors as $user_id => $args) { $author = new MainWP_WP_Stream_Author($user_id); $disabled = isset($args['disabled']) ? $args['disabled'] : null; $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' => '', 'disabled' => $disabled); } return $authors_records; }