本文整理汇总了PHP中WP_User_Query类的典型用法代码示例。如果您正苦于以下问题:PHP WP_User_Query类的具体用法?PHP WP_User_Query怎么用?PHP WP_User_Query使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了WP_User_Query类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: kbs_get_users_by_role
/**
* 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;
}
示例2: 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();
}
示例3: get_clients
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;
}
示例4: upgrade_store_meta_23
/**
* 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);
}
}
示例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: prepare_items
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));
}
示例7: 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
}
示例8: 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;
}
示例9: render
/**
* 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>';
}
示例10: 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);
}
示例11: memberful_private_user_feed_init
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();
}
示例12: delete
/**
* 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;
}
示例13: get_ex_members
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;
}
示例14: 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();
}
示例15: pd_cd_get_customer_users
/**
* 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;
}