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 function log($connector, $message, $args, $object_id, $contexts, $user_id = null) { global $wpdb; if (is_null($user_id)) { $user_id = get_current_user_id(); } require_once MAINWP_WP_STREAM_INC_DIR . 'class-wp-stream-author.php'; $user = new WP_User($user_id); $roles = get_option($wpdb->get_blog_prefix() . 'user_roles'); if (!isset($args['author_meta'])) { $args['author_meta'] = array('user_email' => $user->user_email, 'display_name' => defined('WP_CLI') && empty($user->display_name) ? 'WP-CLI' : $user->display_name, 'user_login' => $user->user_login, 'user_role_label' => !empty($user->roles) ? $roles[$user->roles[0]]['name'] : null, 'agent' => MainWP_WP_Stream_Author::get_current_agent()); if (defined('WP_CLI') && function_exists('posix_getuid')) { $uid = posix_getuid(); $user_info = posix_getpwuid($uid); $args['author_meta']['system_user_id'] = $uid; $args['author_meta']['system_user_name'] = $user_info['name']; } } // Remove meta with null values from being logged $meta = array_filter($args, function ($var) { return !is_null($var); }); $recordarr = array('object_id' => $object_id, 'site_id' => is_multisite() ? get_current_site()->id : 1, 'blog_id' => apply_filters('blog_id_logged', is_network_admin() ? 0 : get_current_blog_id()), 'author' => $user_id, 'author_role' => !empty($user->roles) ? $user->roles[0] : null, 'created' => current_time('mysql', 1), 'summary' => vsprintf($message, $args), 'parent' => self::$instance->prev_record, 'connector' => $connector, 'contexts' => $contexts, 'meta' => $meta, 'ip' => mainwp_wp_stream_filter_input(INPUT_SERVER, 'REMOTE_ADDR', FILTER_VALIDATE_IP)); $record_id = MainWP_WP_Stream_DB::get_instance()->insert($recordarr); return $record_id; }
public static function widget_row($item, $i = null) { require_once MainWP_WP_STREAM_INC_DIR . 'class-wp-stream-author.php'; $author_meta = mainwp_wp_stream_get_meta($item->ID, 'author_meta', true); $author = new MainWP_WP_Stream_Author((int) $item->author, $author_meta); $time_author = sprintf(_x('%1$s ago by <a href="%2$s">%3$s</a>', '1: Time, 2: User profile URL, 3: User display name', 'stream'), human_time_diff(strtotime($item->created)), esc_url($author->get_records_page_url()), esc_html($author->get_display_name())); if ($author->get_agent()) { $time_author .= sprintf(' %s', MainWP_WP_Stream_Author::get_agent_label($author->get_agent())); } $class = isset($i) && $i % 2 ? 'alternate' : ''; ob_start(); ?> <li class="<?php echo esc_html($class); ?> " data-id="<?php echo esc_html($item->ID); ?> "> <div class="record-avatar"> <a href="<?php echo esc_url($author->get_records_page_url()); ?> "> <?php echo $author->get_avatar_img(72); // xss ok ?> </a> </div> <span class="record-meta"><?php echo $time_author; // xss ok ?> </span> <br /> <?php echo esc_html($item->summary); ?> </li><?php return ob_get_clean(); }
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; }