本文整理汇总了PHP中WP_User_Query::get_total方法的典型用法代码示例。如果您正苦于以下问题:PHP WP_User_Query::get_total方法的具体用法?PHP WP_User_Query::get_total怎么用?PHP WP_User_Query::get_total使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WP_User_Query
的用法示例。
在下文中一共展示了WP_User_Query::get_total方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: mdjm_client_count
/**
* 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: purge
/**
* 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: getUsers
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();
}
示例4: isset
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));
}
示例5: maybe_get_leads_count
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());
}
}
示例6: html
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
}
示例7: get_items
/**
* 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: get_users
/**
* 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: rcp_count_members
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();
}
示例10: prepare_items
/**
*
* @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,
) );
}
示例11: getTrackingObject
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;
}
示例12: prepare_items
/**
*
* @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));
}
示例13: callback
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;
}
示例14: get_users_count
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: getData
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;
}