本文整理汇总了PHP中count_users函数的典型用法代码示例。如果您正苦于以下问题:PHP count_users函数的具体用法?PHP count_users怎么用?PHP count_users使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了count_users函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: users
/**
* Generate users
*
* @param array $args
* @param array $assoc_args
**/
public function users($args, $assoc_args)
{
global $blog_id;
$defaults = array('count' => 100, 'role' => get_option('default_role'));
extract(wp_parse_args($assoc_args, $defaults), EXTR_SKIP);
if ('none' == $role) {
$role = false;
} elseif (is_null(get_role($role))) {
WP_CLI::warning("invalid role.");
exit;
}
$user_count = count_users();
$total = $user_count['total_users'];
$limit = $count + $total;
$notify = new \cli\progress\Bar('Generating users', $count);
for ($i = $total; $i < $limit; $i++) {
$login = sprintf('user_%d_%d', $blog_id, $i);
$name = "User {$i}";
$user_id = wp_insert_user(array('user_login' => $login, 'user_pass' => $login, 'nickname' => $name, 'display_name' => $name, 'role' => $role));
if (false === $role) {
delete_user_option($user_id, 'capabilities');
delete_user_option($user_id, 'user_level');
}
$notify->tick();
}
$notify->finish();
}
示例2: 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
}
示例3: column_usage
function column_usage($item)
{
global $wpdb;
$total = count_users();
$used = $wpdb->get_var("SELECT COUNT(DISTINCT(user_id)) FROM {$wpdb->usermeta} WHERE meta_key = '" . $item['key'] . "' ");
return $used . '/' . $total['total_users'];
}
示例4: bnfw_render_users_dropdown
/**
* Render users dropdown.
*
* @since 1.3.6
*/
function bnfw_render_users_dropdown($selected_users)
{
global $wp_roles;
?>
<optgroup label="User Roles">
<?php
$roles = $wp_roles->get_names();
foreach ($roles as $role) {
$selected = selected(true, in_array('role-' . $role, $selected_users), false);
echo '<option value="role-', $role, '" ', $selected, '>', $role, '</option>';
}
?>
</optgroup>
<optgroup label="Users">
<?php
$user_count = count_users();
// if there are more than 100 users then use AJAX to load them dynamically.
// So just get only the selected users
if (count($selected_users) > 0 && $user_count['total_users'] > 100) {
$users = get_users(array('include' => $selected_users, 'order_by' => 'email', 'fields' => array('ID', 'user_login')));
} else {
$users = get_users(array('order_by' => 'email', 'number' => 100, 'fields' => array('ID', 'user_login')));
}
foreach ($users as $user) {
$selected = selected(true, in_array($user->ID, $selected_users), false);
echo '<option value="', $user->ID, '" ', $selected, '>', $user->user_login, '</option>';
}
}
示例5: get_views
function get_views()
{
global $wp_roles, $role;
if ($this->is_site_users) {
$url = 'site-users.php?id=' . $this->site_id;
switch_to_blog($this->site_id);
$users_of_blog = count_users();
restore_current_blog();
} else {
$url = 'users.php';
$users_of_blog = count_users();
}
$total_users = $users_of_blog['total_users'];
$avail_roles =& $users_of_blog['avail_roles'];
unset($users_of_blog);
$current_role = false;
$class = empty($role) ? ' class="current"' : '';
$role_links = array();
$role_links['all'] = "<a href='{$url}'{$class}>" . sprintf(_nx('All <span class="count">(%s)</span>', 'All <span class="count">(%s)</span>', $total_users, 'users'), number_format_i18n($total_users)) . '</a>';
foreach ($wp_roles->get_names() as $this_role => $name) {
if (!isset($avail_roles[$this_role])) {
continue;
}
$class = '';
if ($this_role == $role) {
$current_role = $role;
$class = ' class="current"';
}
$name = translate_user_role($name);
/* translators: User role name with count */
$name = sprintf(__('%1$s <span class="count">(%2$s)</span>'), $name, number_format_i18n($avail_roles[$this_role]));
$role_links[$this_role] = "<a href='" . esc_url(add_query_arg('role', $this_role, $url)) . "'{$class}>{$name}</a>";
}
return $role_links;
}
示例6: fes_upgrades_screen
function fes_upgrades_screen()
{
$step = isset($_GET['step']) ? absint($_GET['step']) : 1;
$counts = count_users();
$total = isset($counts['total_users']) ? $counts['total_users'] : 1;
$total_steps = round($total / 100, 0);
?>
<div class="wrap">
<h2><?php
_e('Frontend Submissions - Upgrades', 'edd_fes');
?>
</h2>
<div id="edd-upgrade-status">
<p><?php
_e('The upgrade process is running, please be patient. This could take several minutes to complete.', 'edd_fes');
?>
</p>
<p><strong><?php
printf(__('Step %d of approximately %d running', 'edd_fes'), $step, $total_steps);
?>
</div>
<script type="text/javascript">
document.location.href = "index.php?edd_action=<?php
echo $_GET['edd_upgrade'];
?>
&step=<?php
echo absint($_GET['step']);
?>
";
</script>
</div>
<?php
}
示例7: bpdev_members_correct_count
function bpdev_members_correct_count($total_count)
{
$count_users = count_users();
//WP function returns an array of total users and user counts by roles
$total_users = $count_users['total_users'];
//Gets the total number of users
$subscriber_role = array('subscriber');
$customer_role = array('customer');
$total_subscriber_count = 0;
//Initialise total subscriber count to 0
$total_customer_count = 0;
//Initialise total subscriber count to 0
foreach ($count_users['avail_roles'] as $role => $count) {
if (in_array($role, $subscriber_role)) {
//checks if the 'subscriber' role is in the $subscriber_role array
$total_subscriber_count = $count;
//sets the total subscriber count
}
if (in_array($role, $customer_role)) {
//checks if the 'customer' role is in the $subscriber_role array
$total_customer_count = $count;
//sets the total customer count
}
}
$excluded_users_count = $total_subscriber_count + $total_customer_count;
//excluded user count which is the subscriber count and customer count
return $total_count - $excluded_users_count;
//Returns the total member count minus the subscriber and customer count
}
示例8: get_user_count
/**
* Get user count
*
* @param string $role
*
* @return int
*/
public function get_user_count($role = '')
{
$count = count_users();
if ('' !== $role) {
return isset($count['avail_roles'][$role]) ? $count['avail_roles'][$role] : 0;
}
return $count['total_users'];
}
示例9: getTotalPages
public function getTotalPages()
{
if (isset($this->options["id"])) {
return 1;
}
$total = count_users();
$total = $total["total_users"];
$per_page = $this->options["per_page"];
return round($total / $per_page, 0, PHP_ROUND_HALF_UP);
}
示例10: getTable
/**
* Retrieve list of users
*
* Based on filters, get list of users
*
* @return string JSON encoded list of users
*
* @access public
*/
public function getTable()
{
//get total number of users
$total = count_users();
$result = $this->query();
$response = array('recordsTotal' => $total['total_users'], 'recordsFiltered' => $result->get_total(), 'draw' => AAM_Core_Request::request('draw'), 'data' => array());
foreach ($result->get_results() as $user) {
$response['data'][] = array($user->ID, implode(', ', $this->getUserRoles($user->roles)), $user->display_name ? $user->display_name : $user->user_nicename, implode(',', $this->prepareRowActions($user)));
}
return json_encode($response);
}
示例11: retrieveList
/**
* Retrieve list of users
*
* Based on filters, get list of users
*
* @return string JSON encoded list of users
*
* @access public
*/
public function retrieveList()
{
//get total number of users
$total = count_users();
$result = $this->query();
$response = array('iTotalRecords' => $total['total_users'], 'iTotalDisplayRecords' => $result->get_total(), 'sEcho' => aam_Core_Request::request('sEcho'), 'aaData' => array());
foreach ($result->get_results() as $user) {
$response['aaData'][] = array($user->ID, $user->user_login, $user->display_name ? $user->display_name : $user->user_nicename, '', $user->user_status, $this->canManage($user) ? 1 : 0);
}
return json_encode($response);
}
示例12: _wprp_get_content_summary
/**
* Return an array of content summary information
*
* @return array
*/
function _wprp_get_content_summary()
{
$num_posts = wp_count_posts('post');
$num_pages = wp_count_posts('page');
$num_categories = count(get_categories(array('hide_empty' => 0)));
$num_comments = wp_count_comments();
$num_themes = count(wp_get_themes());
$num_plugins = count(get_plugins());
$num_users = count_users();
$content_summary = array('post_count' => !empty($num_posts->publish) ? $num_posts->publish : 0, 'page_count' => !empty($num_pages->publish) ? $num_pages->publish : 0, 'category_count' => $num_categories, 'comment_count' => !empty($num_comments->total_comments) ? $num_comments->total_comments : 0, 'theme_count' => $num_themes, 'plugin_count' => $num_plugins, 'user_count' => !empty($num_users['total_users']) ? $num_users['total_users'] : 0);
return $content_summary;
}
示例13: render
/**
*
* @global array $submenu
* @param string $tmpl
* @param mvb_Model_Manager $parent
* @return string
*/
public static function render($tmpl, $parent)
{
self::$user_summary = count_users();
$list_tmpl = mvb_Model_Template::retrieveSub('DELETE_ROLE_LIST', $tmpl);
$item_tmpl = mvb_Model_Template::retrieveSub('DELETE_ROLE_ITEM', $list_tmpl);
$list = '';
foreach (mvb_Model_API::getRoleList() as $role => $data) {
$list .= self::renderRoleRow($role, $data, $item_tmpl);
}
$list = mvb_Model_Template::replaceSub('DELETE_ROLE_ITEM', $list, $list_tmpl);
return mvb_Model_Template::replaceSub('DELETE_ROLE_LIST', $list, $tmpl);
}
示例14: test_count_users_is_accurate_with_multiple_roles
/**
* @ticket 34495
*
* @dataProvider data_count_users_strategies
*/
public function test_count_users_is_accurate_with_multiple_roles($strategy)
{
// Setup users
$admin = self::factory()->user->create(array('role' => 'administrator'));
$editor = self::factory()->user->create(array('role' => 'editor'));
get_userdata($editor)->add_role('author');
$this->assertEquals(array('editor', 'author'), get_userdata($editor)->roles);
// Test user counts
$count = count_users($strategy);
$this->assertEquals(3, $count['total_users']);
$this->assertEquals(array('administrator' => 2, 'editor' => 1, 'author' => 1, 'none' => 0), $count['avail_roles']);
}
示例15: widget
public function widget($args, $instance)
{
$title = apply_filters('widget_title', $instance['title']);
printf('%s', $args['before_widget']);
if ($title) {
printf('%s', $args['before_title'] . $title . $args['after_title']);
}
echo '<div class="widget-statistic">';
if (class_exists('woocommerce')) {
$result = count_users();
if (isset($result['avail_roles']['customer'])) {
$members = $result['avail_roles']['customer'];
if ($members > 0) {
echo '<div class="market-members">';
echo '<p class="title">' . __('Marketplace Members', 'tokopress') . '</p>';
echo '<p class="statistic">' . number_format($members, 0, '', '.') . '</p>';
echo '</div>';
}
}
$role_seller = '';
if (class_exists('WC_Vendors')) {
$role_seller = 'vendor';
} elseif (class_exists('WeDevs_Dokan')) {
$role_seller = 'seller';
}
if ($role_seller) {
if (isset($result['avail_roles'][$role_seller])) {
$sellers = $result['avail_roles'][$role_seller];
if ($sellers > 2) {
echo '<div class="market-members">';
echo '<p class="title">' . __('Marketplace Sellers', 'tokopress') . '</p>';
echo '<p class="statistic">' . number_format($sellers, 0, '', '.') . '</p>';
echo '</div>';
}
}
}
// $count_posts = count( get_posts( array( 'post_type' => 'product', 'post_status' => 'publish', 'fields' => 'ids', 'posts_per_page' => '-1' ) ) );
$count_posts = wp_count_posts('product');
$count_posts = $count_posts->publish;
$items_title = __('Marketplace Items', 'tokopress');
} else {
$count_posts = wp_count_posts('post');
$count_posts = $count_posts->publish;
$items_title = __('Posts', 'tokopress');
}
echo '<div class="market-items">';
echo '<p class="title">' . $items_title . '</p>';
echo '<p class="statistic">' . number_format($count_posts, 0, '', '.') . '</p>';
echo '</div>';
echo '</div>';
printf('%s', $args['after_widget']);
}