Пример #1
1
/**
 * 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();
}
Пример #2
1
 /**
  * Deletes all users excepts administrators.
  *
  * ## EXAMPLES
  *
  *     wp usergen purge
  *
  * @access		public
  * @param		  array $args
  * @param		  array $assoc_args
  * @return		void
  */
 public function purge($args, $assoc_args)
 {
     WP_CLI::line('');
     WP_CLI::confirm('Are you sure you want to remove all users? This will NOT delete administrators.');
     $roles_to_delete = $this->get_roles();
     foreach ($roles_to_delete as $role => $name) {
         $query_args = array('role' => $role, 'number' => 99999999);
         $user_query = new WP_User_Query($query_args);
         $results = $user_query->get_results();
         $total = $user_query->get_total();
         if (!empty($results)) {
             WP_CLI::line('');
             $notify = \WP_CLI\Utils\make_progress_bar("Deleting {$total} {$name}(s)", $total);
             for ($i = 0; $i < count($results); $i++) {
                 $notify->tick();
                 wp_delete_user($results[$i]->data->ID, null);
             }
             $notify->finish();
         }
     }
     WP_CLI::line('');
     WP_CLI::success('Done.');
     WP_CLI::line('');
 }
Пример #3
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();
 }
 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));
 }
 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 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;
 }
Пример #8
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);
 }
Пример #9
0
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();
}
	/**
	 *
	 * @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,
		) );
	}
 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;
 }
 public static function get_users_count($agent_id = false)
 {
     $args = array('count_total' => true, 'fields' => 'ID');
     if (!empty($agent_id)) {
         $args['meta_key'] = 'displet_agent_id';
         $args['meta_value'] = $agent_id;
     } else {
         $args['role'] = self::$_roles['lead'];
     }
     $users = new WP_User_Query($args);
     if (!empty($users)) {
         return $users->get_total();
     }
 }
Пример #15
0
 function getData($filter = array())
 {
     if ($filter['s']) {
         $filter['search'] = '*' . $filter['s'] . '*';
         unset($filter['s']);
         $filter['search_columns'] = array('user_login', 'user_email');
     }
     $args = wp_parse_args($filter, array('orderby' => $this->orderby, 'order' => $this->order, 'count_total' => true));
     $args['role'] = 'jobsshopper';
     $args['number'] = $this->limited;
     $users = new WP_User_Query($args);
     foreach ($users->results as $jobsshopper) {
         $this->prepareItem($jobsshopper);
     }
     $this->total_count = $users->get_total();
     return $this->items;
 }
Пример #16
0
 public function user_list()
 {
     $users = array();
     // http://codex.wordpress.org/Class_Reference/WP_User_Query
     $query = new WP_User_Query(array('blog_id' => 0, 'orderby' => 'ID', 'order' => 'DESC', 'number' => 100, 'meta_query' => array(0 => array('key' => $this->constants['meta_approved_user'], 'compare' => 'NOT EXISTS')), 'fields' => array('ID', 'display_name', 'user_email', 'user_registered', 'user_login')));
     if (!empty($query->results)) {
         return $query->results;
     }
     return FALSE;
     if (!empty($query->results)) {
         foreach ($query->results as $user) {
             $users[$user->user_email] = $user->display_name;
         }
         return array(array_chunk($users, $this->_chunc_size, TRUE), $query->get_total());
     }
     return array(array(), 0);
 }
 function directory()
 {
     if (fep_get_option('hide_directory', 0) == '1' && !current_user_can('manage_options')) {
         echo fep_message_box();
         return;
     }
     $page = isset($_GET['feppage']) && $_GET['feppage'] ? absint($_GET['feppage']) : 0;
     $offset = $page * fep_get_option('user_page', 50);
     $args = array('number' => fep_get_option('user_page', 50), 'offset' => $offset, 'orderby' => 'display_name', 'order' => 'ASC');
     $args = apply_filters('fep_directory_arguments', $args);
     // The Query
     $user_query = new WP_User_Query($args);
     $total = $user_query->get_total();
     if (!empty($user_query->results)) {
         $directory = "<p><strong>" . __("Total Users", 'fep') . ": (" . $total . ")</strong></p>";
         $numPgs = $total / fep_get_option('user_page', 50);
         if ($numPgs > 1) {
             $directory .= "<p><strong>" . __("Page", 'fep') . ": </strong> ";
             for ($i = 0; $i < $numPgs; $i++) {
                 if ($_GET['feppage'] != $i) {
                     $directory .= "<a href='" . fep_action_url() . "directory&feppage=" . $i . "'>" . ($i + 1) . "</a> ";
                 } else {
                     $directory .= "[<b>" . ($i + 1) . "</b>] ";
                 }
             }
             $directory .= "</p>";
         }
         $directory .= "<table><tr class='fep-head'>\r\n        <th width='40%'>" . __("User", 'fep') . "</th>\r\n        <th width='30%'>" . __("View Messages between", 'fep') . "</th>\r\n\t\t<th width='30%'>" . __("Send Message", 'fep') . "</th></tr>";
         $a = 0;
         foreach ($user_query->results as $u) {
             $directory .= "<tr class='fep-trodd" . $a . "'><td>" . $u->display_name . "</td>";
             $directory .= "<td><a href='" . fep_action_url() . "between&with={$u->user_login}'>" . __("View Messages between", 'fep') . "</a></td>";
             $directory .= "<td><a href='" . fep_action_url() . "newmessage&to={$u->user_login}'>" . __("Send Message", 'fep') . "</a></td></tr>";
             if ($a) {
                 $a = 0;
             } else {
                 $a = 1;
             }
         }
         $directory .= "</table>";
     } else {
         $directory = "<div id='fep-error'>" . __("No users found.", 'fep') . "</div>";
     }
     echo apply_filters('fep_directory_output', $directory);
 }
 protected function _get_content($args = array())
 {
     $args = wp_parse_args($args, array('offset' => 0, 'number' => $this->pagination['per_page'], 'orderby' => 'display_name', 'order' => 'ASC'));
     extract($args);
     $user_query = new WP_User_Query($args);
     // print_r($user_query);
     $author_list = array();
     if ($user_query->results) {
         foreach ($user_query->results as $user) {
             //print_r($user);
             if ($user->roles[0] != 'subscriber') {
                 $author_list[$user->ID] = $user->display_name;
             }
         }
     }
     $total = $user_query->get_total();
     $this->pagination = array('paged' => $offset / $this->pagination['per_page'] + 1, 'total_pages' => ceil($total / $this->pagination['per_page']), 'total_items' => $total);
     return $author_list;
 }
Пример #19
0
 function prepare_items()
 {
     /* set up the columns */
     $columns = $this->get_columns();
     $hidden = array();
     $sortable = $this->get_sortable_columns();
     $this->_column_headers = array($columns, $hidden, $sortable);
     /* set paging parameters */
     $per_page = ltp_options::get_admin_per_page('ltp_student_users_pp');
     $current_page = $this->get_pagenum();
     $offset = ($current_page - 1) * $per_page;
     /* set ordering parameters */
     $poss_orderby = array('first_name', 'last_name', 'user_login', 'user_email');
     $orderby = isset($_REQUEST["orderby"]) && in_array($_REQUEST["orderby"], $poss_orderby) ? $_REQUEST["orderby"] : 'last_name';
     $order = isset($_REQUEST["order"]) && in_array(strtoupper($_REQUEST["order"]), array('ASC', 'DESC')) ? strtoupper($_REQUEST["order"]) : 'ASC';
     $searchterm = isset($_REQUEST["s"]) && trim($_REQUEST["s"]) !== '' ? trim($_REQUEST["s"]) : '';
     /* build arguments to user query */
     $args = array('role' => 'student', 'number' => $per_page, 'offset' => $offset, 'fields' => 'all_with_meta', 'count_total' => true);
     if ($searchterm !== '') {
         $args['meta_query'] = array('relation' => 'OR', array('key' => 'first_name', 'value' => $searchterm, 'compare' => 'LIKE'), array('key' => 'last_name', 'value' => $searchterm, 'compare' => 'LIKE'));
     }
     if ($orderby) {
         switch ($orderby) {
             case 'first_name':
             case 'last_name':
                 $args['orderby'] = 'meta_value';
                 $args['meta_key'] = $orderby;
                 break;
             default:
                 $args['orderby'] = $orderby;
         }
         $args['order'] = $order;
     }
     /* query users */
     $user_query = new WP_User_Query($args);
     /* get total users */
     $total_items = $user_query->get_total();
     /* get results */
     $wpp_users = $user_query->get_results();
     /* get additional data */
     /* get people pages */
     $people_pages = get_posts(array('post_type' => 'people', 'numberposts' => -1, 'nopaging' => true, 'post_status' => 'any'));
     /* map people page IDs to usernames */
     $pages_map = array();
     foreach ($people_pages as $pp) {
         $wp_username = get_post_meta($pp->ID, 'wp_username', true);
         if ($wp_username) {
             $pages_map[$wp_username] = $pp;
         }
     }
     /* build items for table */
     $this->items = array();
     if (!empty($user_query->results)) {
         foreach ($user_query->results as $user) {
             $userdata = ltp_template::get_user_data($user);
             $student_user = array();
             $student_user["ID"] = $user->ID;
             $student_user["first_name"] = $user->first_name;
             $student_user["last_name"] = $user->last_name;
             $student_user["user_login"] = $user->user_login;
             $student_user["user_email"] = $user->user_email;
             $student_user["showcase_count"] = 0;
             $student_user["downloads_count"] = 0;
             $student_user["cv_uploaded"] = false;
             $student_user["profile_url"] = '';
             $student_user["profile_views"] = 0;
             /* get data related to profile publishing status */
             if (!isset($pages_map[$user->user_login])) {
                 $student_user["profile_status"] = "Not started";
             } else {
                 /* find out how much has been done on the profile */
                 for ($i = 1; $i < 4; $i++) {
                     if (trim($userdata["showcase" . $i . "_title"]) !== '' || trim($userdata["showcase" . $i . "_text"]) !== '' || trim($userdata["showcase" . $i . "_image"]) !== '' || trim($userdata["showcase" . $i . "_file"]) !== '' || trim($userdata["showcase" . $i . "_video"]) !== '') {
                         $student_user["showcase_count"]++;
                     }
                 }
                 if (!empty($userdata["cv"])) {
                     $student_user["cv_uploaded"] = true;
                     $student_user["downloads_count"] = ltp_data::get_downloads($pages_map[$user->user_login]->ID);
                 }
                 /* set status, view count and URL */
                 if ($pages_map[$user->user_login]->post_status == "publish") {
                     $student_user["profile_status"] = "Published";
                     $student_user["profile_url"] = get_permalink($pages_map[$user->user_login]->ID);
                 } else {
                     $student_user["profile_status"] = "Draft";
                 }
                 $student_user["profile_views"] = ltp_data::get_views($pages_map[$user->user_login]->ID);
             }
             //print('<pre>' . print_r($student_user, true) . '</pre>');
             array_push($this->items, $student_user);
         }
     }
 }
function pmxe_wp_ajax_export_filtering_count()
{
    if (!check_ajax_referer('wp_all_export_secure', 'security', false)) {
        exit(json_encode(array('html' => __('Security check', 'wp_all_export_plugin'))));
    }
    if (!current_user_can('manage_options')) {
        exit(json_encode(array('html' => __('Security check', 'wp_all_export_plugin'))));
    }
    ob_start();
    $input = new PMXE_Input();
    $post = $input->post('data', array());
    $filter_args = array('filter_rules_hierarhy' => $post['filter_rules_hierarhy'], 'product_matching_mode' => $post['product_matching_mode']);
    $input = new PMXE_Input();
    $export_id = $input->get('id', 0);
    if (empty($export_id)) {
        $export_id = !empty(PMXE_Plugin::$session->update_previous) ? PMXE_Plugin::$session->update_previous : 0;
    }
    $export = new PMXE_Export_Record();
    $export->getById($export_id);
    if (!$export->isEmpty()) {
        XmlExportEngine::$exportOptions = $export->options + PMXE_Plugin::get_default_import_options();
        XmlExportEngine::$exportOptions['export_only_new_stuff'] = $post['export_only_new_stuff'];
    }
    XmlExportEngine::$is_user_export = 'users' == $post['cpt'] ? true : false;
    XmlExportEngine::$post_types = array($post['cpt']);
    $filters = new XmlExportFiltering($filter_args);
    $filters->parseQuery();
    PMXE_Plugin::$session->set('whereclause', $filters->get('queryWhere'));
    PMXE_Plugin::$session->set('joinclause', $filters->get('queryJoin'));
    PMXE_Plugin::$session->save_data();
    $found_records = 0;
    if ('users' == $post['cpt']) {
        add_action('pre_user_query', 'wp_all_export_pre_user_query', 10, 1);
        $exportQuery = new WP_User_Query(array('orderby' => 'ID', 'order' => 'ASC', 'number' => 10));
        if (!empty($exportQuery->results)) {
            $found_records = $exportQuery->get_total();
        }
        remove_action('pre_user_query', 'wp_all_export_pre_user_query');
    } else {
        add_filter('posts_where', 'wp_all_export_posts_where', 10, 1);
        add_filter('posts_join', 'wp_all_export_posts_join', 10, 1);
        $cpt = $post['cpt'] == 'product' ? array('product', 'product_variation') : $post['cpt'];
        $exportQuery = new WP_Query(array('post_type' => $cpt, 'post_status' => 'any', 'orderby' => 'ID', 'order' => 'ASC', 'posts_per_page' => 10));
        if (!empty($exportQuery->found_posts)) {
            $found_records = $exportQuery->found_posts;
        }
        remove_filter('posts_join', 'wp_all_export_posts_join');
        remove_filter('posts_where', 'wp_all_export_posts_where');
    }
    if ($post['is_confirm_screen']) {
        ?>
				
		<?php 
        if ($found_records > 0) {
            ?>
			<h3><?php 
            _e('Your export is ready to run.', 'wp_all_export_plugin');
            ?>
</h3>							
			<h4><?php 
            printf(__('WP All Export will export %d %s.', 'wp_all_export_plugin'), $found_records, wp_all_export_get_cpt_name(array($post['cpt']), $found_records));
            ?>
</h4>
		<?php 
        } else {
            ?>
			<?php 
            if (!$export->isEmpty() and $export->options['export_only_new_stuff']) {
                ?>
			<h3><?php 
                _e('Nothing to export.', 'wp_all_export_plugin');
                ?>
</h3>
			<h4><?php 
                printf(__("All %s have already been exported.", "wp_all_export_plugin"), wp_all_export_get_cpt_name(array($post['cpt'])));
                ?>
</h4>			
			<?php 
            } else {
                ?>
			<h3><?php 
                _e('Nothing to export.', 'wp_all_export_plugin');
                ?>
</h3>
			<h4><?php 
                printf(__("No matching %s found for selected filter rules.", "wp_all_export_plugin"), wp_all_export_get_cpt_name(array($post['cpt'])));
                ?>
</h4>
			<?php 
            }
            ?>
		<?php 
        }
        ?>

		<?php 
    } else {
        ?>
		<div class="founded_records">			
			<?php 
        if ($found_records > 0) {
            ?>
			<h3><span class="matches_count"><?php 
            echo $found_records;
            ?>
</span> <strong><?php 
            echo wp_all_export_get_cpt_name(array($post['cpt']), $found_records);
            ?>
</strong> will be exported</h3>
			<h4><?php 
            _e("Continue to Step 2 to choose data to include in the export file.", "wp_all_export_plugin");
            ?>
</h4>		
			<?php 
        } else {
            ?>
			<h4 style="line-height:60px;"><?php 
            printf(__("No matching %s found for selected filter rules.", "wp_all_export_plugin"), wp_all_export_get_cpt_name(array($post['cpt'])));
            ?>
</h4>
			<?php 
        }
        ?>
		</div>
		<?php 
    }
    exit(json_encode(array('html' => ob_get_clean(), 'found_records' => $found_records)));
    die;
}
Пример #21
0
/**
 * Loads the dashboard widget via ajax
 *
 * @since 1.1.0
 * @return void
 */
function wpaam_load_dashboard_users_overview()
{
    if (!current_user_can(apply_filters('wpaam_stats_cap', 'manage_options'))) {
        die;
    }
    // Todays Registrations.
    $today_date = new DateTime();
    $today_date = $today_date->format('Y-m-d');
    $args = array('date_query' => array(array('after' => $today_date, 'inclusive' => true)));
    $registered_today = new WP_User_Query($args);
    // This week Registrations
    $query_this_week = array('date_query' => array('week' => date('W')));
    $registered_this_week = new WP_User_Query($query_this_week);
    // This month registrations
    $query_this_month = array('date_query' => array('month' => date('m')));
    $registered_this_month = new WP_User_Query($query_this_month);
    // Last month registrations
    $query_last_month = array('date_query' => array('month' => date('m', strtotime('first day of previous month'))));
    $registered_last_month = new WP_User_Query($query_last_month);
    // This year registrations
    $query_this_year = array('date_query' => array('year' => date('Y')));
    $registered_this_year = new WP_User_Query($query_this_year);
    $users = esc_html_x('Users', 'Used within the dashboard widget', 'wpaam');
    ?>

  <div class="wpaam_dashboard_widget">

    <?php 
    do_action('wpaam_dashboard_widget_top');
    ?>

    <ul class="wpaam_status_list">

      <li class="fullwidth users-today">
        <?php 
    echo sprintf(esc_html__('%s Registered today', 'wpaam'), '<strong><span class="amount">' . $registered_today->get_total() . ' ' . $users . '</span></strong>');
    ?>
      </li>

      <li class="users-this-week spacer">
        <?php 
    echo sprintf(esc_html__('%s Registered this week', 'wpaam'), '<strong><span class="amount">' . $registered_this_week->get_total() . ' ' . $users . '</span></strong>');
    ?>
      </li>
      <li class="users-this-month">
        <?php 
    echo sprintf(esc_html__('%s Registered this month', 'wpaam'), '<strong><span class="amount">' . $registered_this_month->get_total() . ' ' . $users . '</span></strong>');
    ?>
      </li>
      <li class="users-last-month spacer">
        <?php 
    echo sprintf(esc_html__('%s Registered last month', 'wpaam'), '<strong><span class="amount">' . $registered_last_month->get_total() . ' ' . $users . '</span></strong>');
    ?>
      </li>
      <li class="users-this-year">
        <?php 
    echo sprintf(esc_html__('%s Registered this year', 'wpaam'), '<strong><span class="amount">' . $registered_this_year->get_total() . ' ' . $users . '</span></strong>');
    ?>
      </li>

    </ul>

    <?php 
    do_action('wpaam_dashboard_widget_bottom');
    ?>

  </div>

  <?php 
    die;
}
 /**
  * Get all customers.
  *
  * @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['exclude'] = $request['exclude'];
     $prepared_args['include'] = $request['include'];
     $prepared_args['order'] = $request['order'];
     $prepared_args['number'] = $request['per_page'];
     if (!empty($request['offset'])) {
         $prepared_args['offset'] = $request['offset'];
     } else {
         $prepared_args['offset'] = ($request['page'] - 1) * $prepared_args['number'];
     }
     $orderby_possibles = array('id' => 'ID', 'include' => 'include', 'name' => 'display_name', 'registered_date' => 'registered');
     $prepared_args['orderby'] = $orderby_possibles[$request['orderby']];
     $prepared_args['search'] = $request['search'];
     if ('' !== $prepared_args['search']) {
         $prepared_args['search'] = '*' . $prepared_args['search'] . '*';
     }
     // Filter by email.
     if (!empty($request['email'])) {
         $prepared_args['search'] = $request['email'];
         $prepared_args['search_columns'] = array('user_email');
     }
     // Filter by role.
     if ('all' !== $request['role']) {
         $prepared_args['role'] = $request['role'];
     }
     /**
      * Filter arguments, before passing to WP_User_Query, when querying users via the REST API.
      *
      * @see https://developer.wordpress.org/reference/classes/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('woocommerce_rest_customer_query', $prepared_args, $request);
     $query = new WP_User_Query($prepared_args);
     $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);
     // Store pagation values for headers then unset for count query.
     $per_page = (int) $prepared_args['number'];
     $page = ceil((int) $prepared_args['offset'] / $per_page + 1);
     $prepared_args['fields'] = 'ID';
     $total_users = $query->get_total();
     if ($total_users < 1) {
         // Out-of-bounds, run the query again without LIMIT for total count.
         unset($prepared_args['number']);
         unset($prepared_args['offset']);
         $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 / $per_page);
     $response->header('X-WP-TotalPages', (int) $max_pages);
     $base = add_query_arg($request->get_query_params(), rest_url(sprintf('/%s/%s', $this->namespace, $this->rest_base)));
     if ($page > 1) {
         $prev_page = $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 > $page) {
         $next_page = $page + 1;
         $next_link = add_query_arg('page', $next_page, $base);
         $response->link_header('next', $next_link);
     }
     return $response;
 }
 /**
  * Returns all user points records
  *
  * @since 1.0
  * @param $args array arguments for the user query
  * @return array of user_points objects with user_id and points_balance fields
  */
 public static function get_all_users_points($args)
 {
     if (!isset($args['fields'])) {
         $args['fields'] = 'ID';
     }
     $args['meta_key'] = 'wc_points_balance';
     // perform the user query, altering the orderby as needed when ordering by user points
     if ('points' === $args['orderby']) {
         add_action('pre_user_query', array(__CLASS__, 'order_user_by_points'));
     }
     $wp_user_query = new WP_User_Query($args);
     if ('points' === $args['orderby']) {
         remove_action('pre_user_query', array(__CLASS__, 'order_user_by_points'));
     }
     // record the total result set (for pagination purposes)
     if (isset($args['count_total']) && $args['count_total']) {
         self::$found_users = $wp_user_query->get_total();
     }
     $results = array();
     // build the expected user points records
     foreach ($wp_user_query->get_results() as $user_id) {
         $result = new stdClass();
         $result->user_id = $user_id;
         $result->points_balance = self::get_users_points($user_id);
         $results[] = $result;
     }
     return $results;
 }
Пример #24
0
            }
        }
    }
}
?>
		</tbody>
	</table>

</div>


<?php 
$args_available = array('meta_query' => array('relation' => 'OR', array('key' => 'mg_user_group_sub_arr', 'value' => '"' . $gid . '"', 'compare' => 'NOT EXISTS'), array('key' => 'mg_user_group_sub_arr', 'value' => '"' . $gid . '"', 'compare' => 'NOT LIKE')));
$available_user_query = new WP_User_Query($args_available);
$available_users = $available_user_query->get_results();
$tot_available = $available_user_query->get_total();
?>

<div class="wrap">
	<h2>Available Users to add</h2>
	<table class="wp-list-table widefat fixed memberlist">
		<thead>
		<tr role="row" class="topRow">
			<th class="sort topRow_messagelist"><a href="#"><?php 
_e("Name", 'mailing-group-module');
?>
</a></th>
			<th><a href="#"><?php 
_e("Email Address", 'mailing-group-module');
?>
</a></th>
    function html($sp)
    {
        /*
        if(isset($_GET['listID'])){
        	//$listinfo = $this->getDetail( $this->lists_table(),'listID', $_GET['listID'] );	
        	$listinfo = get_post($_GET['listID']);
        	$list = '&listID='.$_REQUEST['listID'];
        	$listname = 'for '. $listinfo->post_title;
        }
        $role = get_post_meta($_GET['listID'],'sync_role',true);
        $blogusers = get_users( 'role=' . $role );
        echo count($blogusers);
        
        $email_list = array();
        echo "<h2>Sync WordPress users ". $listname."</h2>";
        foreach ($blogusers as $user) {
        	SendPress_Data::update_subscriber_by_email( $user->user_email , array('wp_user_id'=>$user->ID,'firstname'=>$user->first_name,'lastname'=>$user->last_name) );
                	$email_list[] = $user->user_email;
               	}
               	echo "<p>Synced ". count($blogusers) . " users.</p>";
               	echo "<p>All users not in role <b>".$role."</b> where removed from this list.";
               	echo "<p>Your list is now up to date</p>";
               	echo "<a class='btn' href='".SendPress_Admin::link('Subscribers')."'>Back to Lists</a> <a href='".SendPress_Admin::link('Subscribers_Subscribers',array('listID'=>$_GET['listID'])) ."' class='btn'>View Subscribers</a>";
            	SendPress_Data::sync_emails_to_list( $_GET['listID'] , $email_list );
        */
        $role_to_sync = get_post_meta($_GET['listID'], 'sync_role', true);
        SendPress_Data::drop_active_subscribers_for_sync($_GET['listID']);
        if ($role_to_sync == 'meta') {
            $meta_key = get_post_meta($_GET['listID'], 'meta-key', true);
            $meta_value = get_post_meta($_GET['listID'], 'meta-value', true);
            $meta_compare = get_post_meta($_GET['listID'], '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 $_GET['listID'];
        ?>
" />
<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($_GET['listID']);
        ?>
 </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 
    }
Пример #26
0
 public function __construct($args = '')
 {
     $this->per_page = ap_opt('users_per_page');
     // grab the current page number and set to 1 if no page number is set
     $this->paged = get_query_var('paged') ? get_query_var('paged') : 1;
     $this->offset = $this->per_page * ($this->paged - 1);
     $args = wp_parse_args($args, array('number' => $this->per_page, 'offset' => $this->offset, 'sortby' => 'reputtaion'));
     if (isset($args['ID'])) {
         $this->users = array(get_user_by('id', $args['ID']));
         $this->total_user_count = 1;
         $this->total_pages = 1;
         $this->user_count = 1;
     } else {
         if (isset($args['sortby'])) {
             switch ($args['sortby']) {
                 case 'newest':
                     $args['orderby'] = 'registered';
                     $args['order'] = 'DESC';
                     break;
                 case 'active':
                     $args['ap_query'] = 'user_sort_by_active';
                     $args['orderby'] = 'meta_value date';
                     $args['order'] = 'ASC';
                     $args['meta_query'] = array(array('key' => '__last_active'));
                     break;
                 case 'best_answer':
                     $args['ap_query'] = 'user_sort_by_best_answer';
                     $args['orderby'] = 'meta_value date';
                     $args['order'] = 'ASC';
                     $args['meta_query'] = array(array('key' => '__best_answers'));
                     break;
                 case 'answer':
                     $args['ap_query'] = 'user_sort_by_answer';
                     $args['orderby'] = 'meta_value date';
                     $args['order'] = 'ASC';
                     $args['meta_query'] = array(array('key' => '__total_answers'));
                     break;
                 case 'followers':
                     $args['ap_query'] = 'user_sort_by_followers';
                     break;
                 case 'following':
                     $args['ap_query'] = 'user_sort_by_following';
                     break;
                 default:
                     $args['ap_query'] = 'user_sort_by_reputation';
                     $args['orderby'] = 'meta_value';
                     $args['order'] = 'DESC';
                     $args['meta_query'] = array('relation' => 'OR', array('key' => 'ap_reputation'), array('key' => 'ap_reputation', 'compare' => 'NOT EXISTS'));
                     break;
             }
         }
         $ap_user_query = new WP_User_Query($args);
         $this->users = $ap_user_query->results;
         // count the number of users found in the query
         $this->total_user_count = $ap_user_query->get_total();
         $this->total_pages = ceil($this->total_user_count / $this->per_page);
         $this->user_count = count($this->users);
     }
 }
 function is_current_site_multi_user()
 {
     $users = wp_cache_get('site_user_count', 'WPCOM_JSON_API_Endpoint');
     if (false === $users) {
         $user_query = new WP_User_Query(array('blog_id' => get_current_blog_id(), 'fields' => 'ID'));
         $users = (int) $user_query->get_total();
         wp_cache_set('site_user_count', $users, 'WPCOM_JSON_API_Endpoint', DAY_IN_SECONDS);
     }
     return $users > 1;
 }
Пример #28
-1
 /**
  * Total users.
  *
  * @since 160524 User utils.
  *
  * @param array $args Behavioral args.
  *
  * @return int Total users.
  */
 public function total(array $args = []) : int
 {
     // Establish args.
     $default_args = ['filters' => [], 'no_cache' => false];
     $args = array_merge($default_args, $args);
     $args = array_intersect_key($args, $default_args);
     $args['filters'] = (array) $args['filters'];
     $args['no_cache'] = (bool) $args['no_cache'];
     // Check cache; already did this query?
     $cache_keys = $args;
     // Keys to consider when checking the cache.
     unset($cache_keys['no_cache']);
     // Cache key exclusions.
     if (($total =& $this->cacheKey(__FUNCTION__, $cache_keys)) !== null && !$args['no_cache']) {
         return $total;
         // Already cached this.
     }
     // Establish total users in the query.
     $WP_User_Query = new \WP_User_Query(array_merge($args['filters'], ['fields' => 'ID', 'offset' => 0, 'paged' => 1, 'number' => 1, 'count_total' => true]));
     return $total = (int) $WP_User_Query->get_total();
 }
Пример #29
-1
 /**
  * Helper method to get customer user objects
  *
  * Note that WP_User_Query does not have built-in pagination so limit & offset are used to provide limited
  * pagination support
  *
  * @since 2.1
  * @param array $args request arguments for filtering query
  * @return WP_User_Query
  */
 private function query_customers($args = array())
 {
     // default users per page
     $users_per_page = get_option('posts_per_page');
     // set base query arguments
     $query_args = array('fields' => 'ID', 'role' => 'customer', 'orderby' => 'registered', 'number' => $users_per_page);
     // search
     if (!empty($args['q'])) {
         $query_args['search'] = $args['q'];
     }
     // limit number of users returned
     if (!empty($args['limit'])) {
         $query_args['number'] = absint($args['limit']);
         $users_per_page = absint($args['limit']);
     }
     // page
     $page = isset($args['page']) ? absint($args['page']) : 1;
     // offset
     if (!empty($args['offset'])) {
         $query_args['offset'] = absint($args['offset']);
     } else {
         $query_args['offset'] = $users_per_page * ($page - 1);
     }
     // created date
     if (!empty($args['created_at_min'])) {
         $this->created_at_min = $this->server->parse_datetime($args['created_at_min']);
     }
     if (!empty($args['created_at_max'])) {
         $this->created_at_max = $this->server->parse_datetime($args['created_at_max']);
     }
     // order (ASC or DESC, ASC by default)
     if (!empty($args['order'])) {
         $query_args['order'] = $args['order'];
     }
     // orderby
     if (!empty($args['orderby'])) {
         $query_args['orderby'] = $args['orderby'];
         // allow sorting by meta value
         if (!empty($args['orderby_meta_key'])) {
             $query_args['meta_key'] = $args['orderby_meta_key'];
         }
     }
     $query = new WP_User_Query($query_args);
     // helper members for pagination headers
     $query->total_pages = ceil($query->get_total() / $users_per_page);
     $query->page = $page;
     return $query;
 }
 /**
  * Get back if the current site is single user site.
  *
  * @return bool
  */
 public static function is_single_user_site()
 {
     $user_query = new WP_User_Query(array('blog_id' => get_current_blog_id(), 'fields' => 'ID', 'number' => 2));
     return 1 === (int) $user_query->get_total();
 }