PHP WP_User_Query Code Examples

PHP WP_User_Query - 30 examples found. These are the top rated real world PHP examples of WP_User_Query extracted from open source projects. You can rate examples to help us improve the quality of examples
Frequently Used Methods
Example #1
1
/**
 * Retrieve users by role.
 *
 * @since	1.0
 * @param	str	$role	Name of the role to retrieve.
 * @return	mixed
 */
function kbs_get_users_by_role($role = array('support_agent', 'support_manager'))
{
    global $wpdb;
    $user_query = new WP_User_Query(array('orderby' => 'display_name', 'role__in' => $role));
    $users = $user_query->get_results();
    return $users;
}
/**
 * Returns a count of clients.
 *
 * @since	1.4
 * @param	bool	$inactive		True to include inactive clients, false to ignore.
 * @return	int		Client count.
 */
function mdjm_client_count($inactive = true)
{
    $roles = array('client');
    if ($inactive) {
        $roles[] = 'inactive_client';
    }
    $args = array('role__in' => $roles, 'count_total' => true);
    $clients = new WP_User_Query($args);
    return $clients->get_total();
}
function rcp_count_members($level = '', $status = 'active', $recurring = null, $search = '')
{
    global $wpdb;
    if ($status == 'free') {
        if (!empty($level)) {
            $args = array('meta_query' => array(array('key' => 'rcp_subscription_level', 'value' => $level), array('key' => 'rcp_status', 'value' => 'free')));
        } else {
            $args = array('meta_query' => array(array('key' => 'rcp_status', 'value' => 'free')));
        }
    } else {
        if (!empty($level)) {
            $args = array('meta_query' => array(array('key' => 'rcp_subscription_level', 'value' => $level), array('key' => 'rcp_status', 'value' => $status)));
        } else {
            $args = array('meta_query' => array(array('key' => 'rcp_status', 'value' => $status)));
        }
    }
    if (!empty($recurring)) {
        if ($recurring == 1) {
            // find non recurring users
            $args['meta_query'][] = array('key' => 'rcp_recurring', 'compare' => 'NOT EXISTS');
        } else {
            // find recurring users
            $args['meta_query'][] = array('key' => 'rcp_recurring', 'value' => 'yes');
        }
    }
    if (!empty($search)) {
        $args['search'] = sanitize_text_field($search);
    }
    $args['fields'] = 'ID';
    $users = new WP_User_Query($args);
    return $users->get_total();
}
Example #4
0
function get_ex_members()
{
    $ex_synergia_member_args = array('role' => 'ex_synergia_member');
    $ex_synergia_member_query = new WP_User_Query($ex_synergia_member_args);
    $ex_synergia_members = $ex_synergia_member_query->get_results();
    return $ex_synergia_members;
}
 private static function maybe_get_leads_count()
 {
     if (!self::$_model['is_single']) {
         $users = new WP_User_Query(self::$_model['user_args']);
         self::$_model['count'] = intval($users->get_total());
     }
 }
 function prepare_items()
 {
     global $role, $usersearch;
     $usersearch = isset($_REQUEST['s']) ? trim($_REQUEST['s']) : '';
     $role = isset($_REQUEST['role']) ? $_REQUEST['role'] : '';
     $per_page = $this->is_site_users ? 'site_users_network_per_page' : 'users_per_page';
     $users_per_page = $this->get_items_per_page($per_page);
     $paged = $this->get_pagenum();
     $args = array('number' => $users_per_page, 'offset' => ($paged - 1) * $users_per_page, 'role' => $role, 'search' => $usersearch, 'fields' => 'all_with_meta');
     if ('' !== $args['search']) {
         $args['search'] = '*' . $args['search'] . '*';
     }
     if ($this->is_site_users) {
         $args['blog_id'] = $this->site_id;
     }
     if (isset($_REQUEST['orderby'])) {
         $args['orderby'] = $_REQUEST['orderby'];
     }
     if (isset($_REQUEST['order'])) {
         $args['order'] = $_REQUEST['order'];
     }
     // Query the user IDs for this page
     $wp_user_search = new WP_User_Query($args);
     $this->items = $wp_user_search->get_results();
     $this->set_pagination_args(array('total_items' => $wp_user_search->get_total(), 'per_page' => $users_per_page));
 }
function memberful_private_user_feed_init()
{
    // In case this is not available, just don't carry on with the logic, it should always be here.
    if (!isset($_SERVER['REQUEST_URI'])) {
        return;
    }
    // This is not a case we can verify, so we'll skip
    if (strpos($_SERVER['REQUEST_URI'], memberful_private_user_feed_get_url_identifier()) === false) {
        return;
    }
    // Extract the token from the URL
    $feedUserToken = substr($_SERVER['REQUEST_URI'], strpos($_SERVER['REQUEST_URI'], memberful_private_user_feed_get_url_identifier()) + strlen(memberful_private_user_feed_get_url_identifier()));
    $requiredPlan = memberful_private_user_feed_settings_get_required_plan();
    // We want to allow the private user feed only if the admin has configured it.
    if ($requiredPlan == false) {
        return;
    }
    // The only reliable way to make sure it works on all WP versions
    // We'll take "all" users with the token match.
    $user_query = new WP_User_Query(array('meta_key' => 'memberful_private_user_feed_token', 'meta_value' => $feedUserToken));
    // Get the results from the query
    $users = $user_query->get_results();
    // We have no results.
    if (empty($users)) {
        return;
    }
    // In case somebody actually maps this with their plugin with a hook, we still need to get the first one.
    $user = array_shift($users);
    if (!is_subscribed_to_memberful_plan($requiredPlan, $user->ID)) {
        return;
    }
    // Everything is in order, we'll deliver the feed.
    memberful_private_user_feed_deliver();
}
    function html($sp)
    {
        $list = SPNL()->validate->int($_GET['listID']);
        if ($list > 0) {
            $role_to_sync = get_post_meta($list, 'sync_role', true);
            SendPress_Data::drop_active_subscribers_for_sync($list);
            if ($role_to_sync == 'meta') {
                $meta_key = get_post_meta($list, 'meta-key', true);
                $meta_value = get_post_meta($list, 'meta-value', true);
                $meta_compare = get_post_meta($list, 'meta-compare', true);
                // WP_User_Query arguments
                $args = array('meta_query' => array(array('key' => $meta_key, 'value' => $meta_value, 'compare' => $meta_compare)));
                $user_query = new WP_User_Query($args);
                $blogusers = $user_query->get_total();
            } else {
                $result = count_users();
                foreach ($result['avail_roles'] as $role => $count) {
                    if ($role == $role_to_sync) {
                        $blogusers = $count;
                    }
                }
            }
        }
        //$blogusers = get_users( 'role=' . $role );
        //echo count($blogusers);
        ?>
<div id="taskbar" class="lists-dashboard rounded group"> 


</div>
<input type="hidden" id="post_ID" name="post_ID" value="<?php 
        echo $list;
        ?>
" />
<div class='well' id="sync-wordpress-roles">
<h2><strong><?php 
        _e('Syncing ', 'sendpress');
        ?>
 <?php 
        echo ucwords($role);
        ?>
 <?php 
        _e(' Role to List', 'sendpress');
        ?>
  <?php 
        echo get_the_title($list);
        ?>
 </strong></h2>
<br>

<div class="progress progress-striped active">
	<div class="progress-bar sp-queueit" style="width: 0%;"></div>
</div>
<span id="queue-total">0</span> of <span id="list-total"><?php 
        echo $blogusers;
        ?>
</span>
</div>
<?php 
    }
 /**
  * Get all users
  *
  * @param WP_REST_Request $request Full details about the request.
  * @return WP_Error|WP_REST_Response
  */
 public function get_items($request)
 {
     $prepared_args = array();
     $prepared_args['order'] = $request['order'];
     $prepared_args['number'] = $request['per_page'];
     $prepared_args['offset'] = ($request['page'] - 1) * $prepared_args['number'];
     $orderby_possibles = array('id' => 'ID', 'name' => 'display_name', 'registered_date' => 'registered');
     $prepared_args['orderby'] = $orderby_possibles[$request['orderby']];
     $prepared_args['search'] = $request['search'];
     if (!current_user_can('list_users')) {
         $prepared_args['has_published_posts'] = true;
         // Only display a public subset of information
         $request['context'] = 'embed';
     }
     if ('' !== $prepared_args['search']) {
         $prepared_args['search'] = '*' . $prepared_args['search'] . '*';
     }
     /**
      * Filter arguments, before passing to WP_User_Query, when querying users via the REST API.
      *
      * @see https://codex.wordpress.org/Class_Reference/WP_User_Query
      *
      * @param array           $prepared_args Array of arguments for WP_User_Query.
      * @param WP_REST_Request $request       The current request.
      */
     $prepared_args = apply_filters('rest_user_query', $prepared_args, $request);
     $query = new WP_User_Query($prepared_args);
     if (is_wp_error($query)) {
         return $query;
     }
     $users = array();
     foreach ($query->results as $user) {
         $data = $this->prepare_item_for_response($user, $request);
         $users[] = $this->prepare_response_for_collection($data);
     }
     $response = rest_ensure_response($users);
     unset($prepared_args['number']);
     unset($prepared_args['offset']);
     $prepared_args['fields'] = 'ID';
     $count_query = new WP_User_Query($prepared_args);
     $total_users = $count_query->get_total();
     $response->header('X-WP-Total', (int) $total_users);
     $max_pages = ceil($total_users / $request['per_page']);
     $response->header('X-WP-TotalPages', (int) $max_pages);
     $base = add_query_arg($request->get_query_params(), rest_url('/wp/v2/users'));
     if ($request['page'] > 1) {
         $prev_page = $request['page'] - 1;
         if ($prev_page > $max_pages) {
             $prev_page = $max_pages;
         }
         $prev_link = add_query_arg('page', $prev_page, $base);
         $response->link_header('prev', $prev_link);
     }
     if ($max_pages > $request['page']) {
         $next_page = $request['page'] + 1;
         $next_link = add_query_arg('page', $next_page, $base);
         $response->link_header('next', $next_link);
     }
     return $response;
 }
 /**
  * Rendering the shortcode this class is responsible for.
  *
  * @return string $content
  */
 public function render()
 {
     $all_users = $this->user_query->get_results();
     // if the user has specified more users add them as well.
     if (!empty($this->include)) {
         $included_users_query = new WP_User_Query(array('include' => $this->include));
         $included_users = $included_users_query->get_results();
         if (!empty($included_users)) {
             $merged_users = array_merge($all_users, $included_users);
             $all_users = $this->users_unique($merged_users);
             $all_users = $this->users_sort($all_users);
         }
     }
     // exclude the users not wanted
     if (!empty($this->exclude)) {
         $all_users = $this->exclude_users($all_users, $this->exclude);
     }
     if (!count($all_users) > 0) {
         return '';
     }
     $users_output = '';
     foreach ($all_users as $user) {
         $user_display_name = $this->get_user_public_name($user);
         /**
          * Sensei teachers shortcode list item filter
          *
          * @since 1.9.0
          *
          * @param string $teacher_li the html for the teacher li
          * @param WP_User $user
          */
         $users_output .= apply_filters('sensei_teachers_shortcode_list_item', '<li class="teacher"><a href="' . get_author_posts_url($user->ID) . '">' . $user_display_name . '<a/></li>', $user);
     }
     return '<ul class="sensei-teachers">' . $users_output . '</ul>';
 }
Example #11
0
 /**
  * Delete User Role and all User's in role if requested
  * 
  * @param boolean $delete_users
  * 
  * @return boolean
  * 
  * @access public
  */
 public function delete($delete_users = false)
 {
     $role = new WP_Roles();
     if ($this->getId() !== 'administrator') {
         if ($delete_users) {
             if (current_user_can('delete_users')) {
                 //delete users first
                 $users = new WP_User_Query(array('number' => '', 'blog_id' => get_current_blog_id(), 'role' => $this->getId()));
                 foreach ($users->get_results() as $user) {
                     //user can not delete himself
                     if ($user instanceof WP_User && $user->ID != get_current_user_id()) {
                         wp_delete_user($user->ID);
                     }
                 }
                 $role->remove_role($this->getId());
                 $status = true;
             } else {
                 $status = false;
             }
         } else {
             $role->remove_role($this->getId());
             $status = true;
         }
     } else {
         $status = false;
     }
     return $status;
 }
Example #12
0
 /**
  * Ajax callback function to search users that is used on exclude setting page
  *
  * @uses WP_User_Query WordPress User Query class.
  * @return void
  */
 public static function get_users()
 {
     if (!defined('DOING_AJAX') || !current_user_can(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', 'stream'));
     $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' => 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 WP_STREAM_INC_DIR . 'class-wp-stream-author.php';
     foreach ($users->results as $key => $user) {
         $author = new 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", '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 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)', 'stream'));
     }
     wp_send_json_success($response);
 }
 protected function get_user_by_meta_data($meta_key, $meta_value)
 {
     // Query for users based on the meta data
     $user_query = new WP_User_Query(array('meta_key' => $meta_key, 'meta_value' => $meta_value));
     // Get the results from the query, returning the first user
     $users = $user_query->get_results();
     return isset($users[0]) ? $users[0] : 0;
 }
/**
 * Get the customer list.
 *
 * Taken from WooCommerce code at:
 * includes/admin/reports/class-wc-report-customer-list.php:WC_Report_Customer_List->prepare_items()
 *
 * @since 0.1.0
 *
 * @return array User list
 */
function pd_cd_get_customer_users()
{
    $admin_users = new WP_User_Query(array('role' => 'administrator1', 'fields' => 'ID'));
    $manager_users = new WP_User_Query(array('role' => 'shop_manager', 'fields' => 'ID'));
    $query = new WP_User_Query(array('exclude' => array_merge($admin_users->get_results(), $manager_users->get_results())));
    $customers = $query->get_results();
    return $customers;
}
function um_clean_user_basename_filter($value, $raw)
{
    global $wpdb;
    $permalink_base = um_get_option('permalink_base');
    $user_query = new WP_User_Query(array('meta_query' => array('relation' => 'AND', array('key' => 'um_user_profile_url_slug_name_' . $raw), array('key' => 'account_status', 'value' => 'awaiting_admin_review', 'compare' => '!='))));
    $result = current($user_query->get_results());
    $slugname = '';
    if (isset($result->data->ID)) {
        $slugname = get_user_meta($result->data->ID, 'um_user_profile_url_slug_name_' . $raw, true);
        $value = $slugname;
    }
    $value = apply_filters("um_permalink_base_before_filter", $value);
    $raw_value = $value;
    switch ($permalink_base) {
        case 'name':
            if (!empty($value) && strrpos($value, "_") > -1) {
                $value = str_replace('_', '. ', $value);
            }
            if (!empty($value) && strrpos($value, "_") > -1) {
                $value = str_replace('_', '-', $value);
            }
            if (!empty($value) && strrpos($value, ".") > -1 && strrpos($raw_value, "_") <= -1) {
                $value = str_replace('.', ' ', $value);
            }
            $value = apply_filters("um_permalink_base_after_filter_name", $value, $raw_value);
            break;
        case 'name_dash':
            if (!empty($value) && strrpos($value, "-") > -1) {
                $value = str_replace('-', ' ', $value);
            }
            if (!empty($value) && strrpos($value, "_") > -1) {
                $value = str_replace('_', '-', $value);
            }
            // Checks if last name has a dash
            if (!empty($value) && strrpos($value, "_") > -1) {
                $value = str_replace('_', '-', $value);
            }
            $value = apply_filters("um_permalink_base_after_filter_name_dash", $value, $raw_value);
            break;
        case 'name_plus':
            if (!empty($value) && strrpos($value, "+") > -1) {
                $value = str_replace('+', ' ', $value);
            }
            if (!empty($value) && strrpos($value, "_") > -1) {
                $value = str_replace('_', '+', $value);
            }
            $value = apply_filters("um_permalink_base_after_filter_name_plus", $value, $raw_value);
            break;
        default:
            // Checks if last name has a dash
            if (!empty($value) && strrpos($value, "_") > -1 && substr($value, "_") == 1) {
                $value = str_replace('_', '-', $value);
            }
            $value = apply_filters("um_permalink_base_after_filter", $value, $raw_value);
            break;
    }
    return $value;
}
	/**
	 *
	 * @global string $usersearch
	 * @global string $role
	 * @global wpdb   $wpdb
	 * @global string $mode
	 */
	public function prepare_items() {
		global $usersearch, $role, $wpdb, $mode;

		$usersearch = isset( $_REQUEST['s'] ) ? wp_unslash( trim( $_REQUEST['s'] ) ) : '';

		$users_per_page = $this->get_items_per_page( 'users_network_per_page' );

		$role = isset( $_REQUEST['role'] ) ? $_REQUEST['role'] : '';

		$paged = $this->get_pagenum();

		$args = array(
			'number' => $users_per_page,
			'offset' => ( $paged-1 ) * $users_per_page,
			'search' => $usersearch,
			'blog_id' => 0,
			'fields' => 'all_with_meta'
		);

		if ( wp_is_large_network( 'users' ) )
			$args['search'] = ltrim( $args['search'], '*' );

		if ( $role == 'super' ) {
			$logins = implode( "', '", get_super_admins() );
			$args['include'] = $wpdb->get_col( "SELECT ID FROM $wpdb->users WHERE user_login IN ('$logins')" );
		}

		/*
		 * If the network is large and a search is not being performed,
		 * show only the latest users with no paging in order to avoid
		 * expensive count queries.
		 */
		if ( !$usersearch && wp_is_large_network( 'users' ) ) {
			if ( !isset($_REQUEST['orderby']) )
				$_GET['orderby'] = $_REQUEST['orderby'] = 'id';
			if ( !isset($_REQUEST['order']) )
				$_GET['order'] = $_REQUEST['order'] = 'DESC';
			$args['count_total'] = false;
		}

		if ( isset( $_REQUEST['orderby'] ) )
			$args['orderby'] = $_REQUEST['orderby'];

		if ( isset( $_REQUEST['order'] ) )
			$args['order'] = $_REQUEST['order'];

		$mode = empty( $_REQUEST['mode'] ) ? 'list' : $_REQUEST['mode'];

		// Query the user IDs for this page
		$wp_user_search = new WP_User_Query( $args );

		$this->items = $wp_user_search->get_results();

		$this->set_pagination_args( array(
			'total_items' => $wp_user_search->get_total(),
			'per_page' => $users_per_page,
		) );
	}
Example #17
0
 function capture_query($args)
 {
     $args['count_total'] = false;
     $uq = new WP_User_Query();
     $uq->_p2p_capture = true;
     // needed by P2P_URL_Query
     $uq->prepare_query($args);
     return "SELECT {$uq->query_fields} {$uq->query_from} {$uq->query_where} {$uq->query_orderby} {$uq->query_limit}";
 }
Example #18
0
 private function getUsers()
 {
     $adminUsers = new \WP_User_Query(array('role' => 'administrator', 'fields' => 'ID'));
     $managerUsers = new \WP_User_Query(array('role' => 'shop_manager', 'fields' => 'ID'));
     $query = new \WP_User_Query(array('exclude' => array_merge($adminUsers->get_results(), $managerUsers->get_results()), 'number' => $this->csvExportStart ? 0 : 20, 'offset' => $this->csvExportStart ? 0 : ($this->getCurrentPage() - 1) * 20, 'search' => '*' . $this->getSearch() . '*'));
     $this->totalItems = $query->get_total();
     $this->totalPages = ceil($query->get_total() / 20);
     return $query->get_results();
 }
Example #19
0
 public static function fetch($args = array())
 {
     $users = array();
     $q_user = new \WP_User_Query($args);
     foreach ($q_user->get_results() as $user) {
         $users[$user->ID] = new static($user);
     }
     return $users;
 }
Example #20
0
 /**
  * Get users who signed up for a membership.
  *
  * @param array $args
  * @return WP_User_Query
  */
 public function get_members($args)
 {
     global $wpdb;
     $user_query = new WP_User_Query();
     $user_query->prepare_query($args);
     $user_query->query_from .= ' INNER JOIN ' . $this->tbl_members . ' ib_edu_m ON ib_edu_m.user_id = ' . $wpdb->users . '.ID';
     $user_query->query();
     return $user_query;
 }
 public function user_totals()
 {
     // prepare arguments
     $args = array('role' => 'Author');
     // Create the WP_User_Query object
     $wp_user_query = new WP_User_Query($args);
     // Get the results
     $authors = $wp_user_query->get_results();
     return $authors;
 }
/**
 * Get array of all forum mods
 *
 * @since		1.0.0
 * @param		bool $admins_only Return only admins
 * @return		array $staff The array of mods
 */
function edd_bbp_get_all_mods($admins_only = false)
{
    $wp_user_search = new WP_User_Query(array('role' => 'administrator'));
    $staff = $wp_user_search->get_results();
    if (!$admins_only) {
        $wp_user_search = new WP_User_Query(array('role' => 'bbp_moderator'));
        $moderators = $wp_user_search->get_results();
        $staff = array_merge($moderators, $staff);
    }
    return $staff;
}
Example #23
0
 function capture_query($args)
 {
     $args['count_total'] = false;
     $uq = new WP_User_Query();
     $uq->_p2p_capture = true;
     // needed by P2P_URL_Query
     // see http://core.trac.wordpress.org/ticket/21119
     $uq->query_vars = wp_parse_args($args, array('blog_id' => $GLOBALS['blog_id'], 'role' => '', 'meta_key' => '', 'meta_value' => '', 'meta_compare' => '', 'include' => array(), 'exclude' => array(), 'search' => '', 'search_columns' => array(), 'orderby' => 'login', 'order' => 'ASC', 'offset' => '', 'number' => '', 'count_total' => true, 'fields' => 'all', 'who' => ''));
     $uq->prepare_query();
     return "SELECT {$uq->query_fields} {$uq->query_from} {$uq->query_where} {$uq->query_orderby} {$uq->query_limit}";
 }
 public static function getTrackingObject()
 {
     $hash = md5(network_site_url() . '-' . $_SERVER['REMOTE_ADDR']);
     global $blog_id, $wpdb;
     $pts = array();
     foreach (get_post_types(array('public' => true)) as $pt) {
         $count = wp_count_posts($pt);
         $pts[$pt] = $count->publish;
     }
     $comments_count = wp_count_comments();
     $theme_data = wp_get_theme();
     $theme = array('version' => $theme_data->Version, 'name' => $theme_data->Name, 'author' => $theme_data->Author, 'template' => $theme_data->Template);
     if (!function_exists('get_plugin_data')) {
         require_once ABSPATH . 'wp-admin/includes/admin.php';
     }
     $plugins = array();
     foreach (get_option('active_plugins', array()) as $plugin_path) {
         $plugin_info = get_plugin_data(WP_PLUGIN_DIR . '/' . $plugin_path);
         $slug = str_replace('/' . basename($plugin_path), '', $plugin_path);
         $plugins[$slug] = array('version' => $plugin_info['Version'], 'name' => $plugin_info['Name'], 'plugin_uri' => $plugin_info['PluginURI'], 'author' => $plugin_info['AuthorName'], 'author_uri' => $plugin_info['AuthorURI']);
     }
     if (is_multisite()) {
         foreach (get_option('active_sitewide_plugins', array()) as $plugin_path) {
             $plugin_info = get_plugin_data(WP_PLUGIN_DIR . '/' . $plugin_path);
             $slug = str_replace('/' . basename($plugin_path), '', $plugin_path);
             $plugins[$slug] = array('version' => $plugin_info['Version'], 'name' => $plugin_info['Name'], 'plugin_uri' => $plugin_info['PluginURI'], 'author' => $plugin_info['AuthorName'], 'author_uri' => $plugin_info['AuthorURI']);
         }
     }
     $version = explode('.', PHP_VERSION);
     $version = array('major' => $version[0], 'minor' => $version[0] . '.' . $version[1], 'release' => PHP_VERSION);
     $user_query = new WP_User_Query(array('blog_id' => $blog_id, 'count_total' => true));
     $comments_query = new WP_Comment_Query();
     $data = array('_id' => $hash, 'localhost' => $_SERVER['REMOTE_ADDR'] === '127.0.0.1' ? 1 : 0, 'php' => $version, 'site' => array('hash' => $hash, 'version' => get_bloginfo('version'), 'multisite' => is_multisite(), 'users' => $user_query->get_total(), 'lang' => get_locale(), 'wp_debug' => defined('WP_DEBUG') ? WP_DEBUG ? true : false : false, 'memory' => WP_MEMORY_LIMIT), 'pts' => $pts, 'comments' => array('total' => $comments_count->total_comments, 'approved' => $comments_count->approved, 'spam' => $comments_count->spam, 'pings' => $comments_query->query(array('count' => true, 'type' => 'pingback'))), 'options' => apply_filters('redux/tracking/options', array()), 'theme' => $theme, 'redux' => array('mode' => ReduxFramework::$_is_plugin ? 'plugin' : 'theme', 'version' => ReduxFramework::$_version, 'demo_mode' => get_option('ReduxFrameworkPlugin')), 'developer' => apply_filters('redux/tracking/developer', array()), 'plugins' => $plugins);
     $parts = explode(' ', $_SERVER['SERVER_SOFTWARE']);
     $software = array();
     foreach ($parts as $part) {
         if ($part[0] == "(") {
             continue;
         }
         if (strpos($part, '/') !== false) {
             $chunk = explode("/", $part);
             $software[strtolower($chunk[0])] = $chunk[1];
         }
     }
     $software['full'] = $_SERVER['SERVER_SOFTWARE'];
     $data['environment'] = $software;
     if (function_exists('mysql_get_server_info')) {
         $data['environment']['mysql'] = mysql_get_server_info();
     }
     if (empty($data['developer'])) {
         unset($data['developer']);
     }
     return $data;
 }
 /**
  *
  * @global string $usersearch
  * @global string $role
  * @global wpdb   $wpdb
  * @global string $mode
  */
 public function prepare_items()
 {
     global $usersearch, $role, $wpdb, $mode;
     $usersearch = isset($_REQUEST['s']) ? wp_unslash(trim($_REQUEST['s'])) : '';
     $users_per_page = $this->get_items_per_page('users_network_per_page');
     $role = isset($_REQUEST['role']) ? $_REQUEST['role'] : '';
     $paged = $this->get_pagenum();
     $args = array('number' => $users_per_page, 'offset' => ($paged - 1) * $users_per_page, 'search' => $usersearch, 'blog_id' => 0, 'fields' => 'all_with_meta');
     if (wp_is_large_network('users')) {
         $args['search'] = ltrim($args['search'], '*');
     } else {
         if ('' !== $args['search']) {
             $args['search'] = trim($args['search'], '*');
             $args['search'] = '*' . $args['search'] . '*';
         }
     }
     if ($role === 'super') {
         $logins = implode("', '", get_super_admins());
         $args['include'] = $wpdb->get_col("SELECT ID FROM {$wpdb->users} WHERE user_login IN ('{$logins}')");
     }
     /*
      * If the network is large and a search is not being performed,
      * show only the latest users with no paging in order to avoid
      * expensive count queries.
      */
     if (!$usersearch && wp_is_large_network('users')) {
         if (!isset($_REQUEST['orderby'])) {
             $_GET['orderby'] = $_REQUEST['orderby'] = 'id';
         }
         if (!isset($_REQUEST['order'])) {
             $_GET['order'] = $_REQUEST['order'] = 'DESC';
         }
         $args['count_total'] = false;
     }
     if (isset($_REQUEST['orderby'])) {
         $args['orderby'] = $_REQUEST['orderby'];
     }
     if (isset($_REQUEST['order'])) {
         $args['order'] = $_REQUEST['order'];
     }
     if (!empty($_REQUEST['mode'])) {
         $mode = $_REQUEST['mode'] === 'excerpt' ? 'excerpt' : 'list';
         set_user_setting('network_users_list_mode', $mode);
     } else {
         $mode = get_user_setting('network_users_list_mode', 'list');
     }
     /** This filter is documented in wp-admin/includes/class-wp-users-list-table.php */
     $args = apply_filters('users_list_table_query_args', $args);
     // Query the user IDs for this page
     $wp_user_search = new WP_User_Query($args);
     $this->items = $wp_user_search->get_results();
     $this->set_pagination_args(array('total_items' => $wp_user_search->get_total(), 'per_page' => $users_per_page));
 }
 function callback($path = '', $blog_id = 0)
 {
     $blog_id = $this->api->switch_to_blog_and_validate_user($this->api->get_blog_id($blog_id));
     if (is_wp_error($blog_id)) {
         return $blog_id;
     }
     $args = $this->query_args();
     $authors_only = !empty($args['authors_only']);
     if ($args['number'] < 1) {
         $args['number'] = 20;
     } elseif (100 < $args['number']) {
         return new WP_Error('invalid_number', 'The NUMBER parameter must be less than or equal to 100.', 400);
     }
     if ($authors_only) {
         if (empty($args['type'])) {
             $args['type'] = 'post';
         }
         if (!$this->is_post_type_allowed($args['type'])) {
             return new WP_Error('unknown_post_type', 'Unknown post type', 404);
         }
         $post_type_object = get_post_type_object($args['type']);
         if (!$post_type_object || !current_user_can($post_type_object->cap->edit_others_posts)) {
             return new WP_Error('unauthorized', 'User cannot view authors for specified post type', 403);
         }
     } elseif (!current_user_can('list_users')) {
         return new WP_Error('unauthorized', 'User cannot view users for specified site', 403);
     }
     $query = array('number' => $args['number'], 'offset' => $args['offset'], 'order' => $args['order'], 'orderby' => $args['order_by'], 'fields' => 'ID');
     if ($authors_only) {
         $query['who'] = 'authors';
     }
     $user_query = new WP_User_Query($query);
     $return = array();
     foreach (array_keys($this->response_format) as $key) {
         switch ($key) {
             case 'found':
                 $return[$key] = (int) $user_query->get_total();
                 break;
             case 'users':
                 $users = array();
                 foreach ($user_query->get_results() as $u) {
                     $the_user = $this->get_author($u, true);
                     if ($the_user && !is_wp_error($the_user)) {
                         $users[] = $the_user;
                     }
                 }
                 $return[$key] = $users;
                 break;
         }
     }
     return $return;
 }
Example #27
0
/**
 * Displays Adverts author suggest box (when editing advert in wp-admin)
 * 
 * Action: adverts_author_suggest
 * 
 * @since 0.1
 * @return void
 */
function adverts_author_suggest()
{
    // Find users matching user query
    $users = new WP_User_Query(array('search' => '*' . esc_attr($_GET["q"]) . '*', 'search_columns' => array('user_login', 'display_name', 'user_email')));
    $users_found = $users->get_results();
    foreach ($users_found as $user) {
        echo '<span data-id="' . $user->ID . '">' . esc_html($user->display_name) . '</span>';
        echo '<!-- suggest delimeter -->';
    }
    echo '<span data-id="0+"><em>Anonymous</em></span>';
    echo '<!-- suggest delimeter -->';
    exit;
}
 function get_clients()
 {
     $users = array();
     $roles = array('administrator', 'author', 'editor', 'contributor');
     foreach ($roles as $role) {
         $users_query = new WP_User_Query(array('fields' => 'all_with_meta', 'role' => $role, 'orderby' => 'display_name'));
         $results = $users_query->get_results();
         if ($results) {
             $users = array_merge($users, $results);
         }
     }
     return $users;
 }
/**
 * Upgrade store meta for sellers
 * and replace old address meta with new address meta
 *
 * @since 2.3
 *
 * @return void
 */
function upgrade_store_meta_23()
{
    $query = new WP_User_Query(array('role' => 'seller'));
    $sellers = $query->get_results();
    $default_settings = array('store_name' => '', 'location' => '', 'find_address' => '', 'banner' => '', 'phone' => '', 'show_email' => '', 'gravatar' => '', 'payment' => array(), 'social' => array());
    foreach ($sellers as $seller) {
        $current_settings = dokan_get_store_info($seller->ID);
        $current_settings = wp_parse_args($current_settings, $default_settings);
        $old_address = $current_settings['address'];
        $new_address = array('street_1' => $old_address, 'street_2' => '', 'city' => '', 'zip' => '', 'country' => '', 'state' => '');
        $current_settings['address'] = $new_address;
        update_user_meta($seller->ID, 'dokan_profile_settings', $current_settings);
    }
}
function my_calendar_getUsers()
{
    global $blog_id;
    $count = count_users('time');
    $args = array('blog_id' => $blog_id, 'orderby' => 'display_name', 'fields' => array('ID', 'user_nicename', 'display_name'));
    $args = apply_filters('mc_filter_user_arguments', $args, $count);
    $users = new WP_User_Query($args);
    return $users->get_results();
}