本文整理汇总了PHP中count_many_users_posts函数的典型用法代码示例。如果您正苦于以下问题:PHP count_many_users_posts函数的具体用法?PHP count_many_users_posts怎么用?PHP count_many_users_posts使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了count_many_users_posts函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: test_count_many_users_posts
/**
* @ticket 21431
*/
function test_count_many_users_posts()
{
$user_id_a = self::factory()->user->create(array('role' => 'author'));
$user_id_b = self::factory()->user->create(array('role' => 'author'));
$post_id_a = self::factory()->post->create(array('post_author' => $user_id_a));
$post_id_b = self::factory()->post->create(array('post_author' => $user_id_b));
$post_id_c = self::factory()->post->create(array('post_author' => $user_id_b, 'post_status' => 'private'));
wp_set_current_user($user_id_a);
$counts = count_many_users_posts(array($user_id_a, $user_id_b), 'post', false);
$this->assertEquals(1, $counts[$user_id_a]);
$this->assertEquals(1, $counts[$user_id_b]);
$counts = count_many_users_posts(array($user_id_a, $user_id_b), 'post', true);
$this->assertEquals(1, $counts[$user_id_a]);
$this->assertEquals(1, $counts[$user_id_b]);
wp_set_current_user($user_id_b);
$counts = count_many_users_posts(array($user_id_a, $user_id_b), 'post', false);
$this->assertEquals(1, $counts[$user_id_a]);
$this->assertEquals(2, $counts[$user_id_b]);
$counts = count_many_users_posts(array($user_id_a, $user_id_b), 'post', true);
$this->assertEquals(1, $counts[$user_id_a]);
$this->assertEquals(1, $counts[$user_id_b]);
}
示例2: display_rows
/**
* Generate the list table rows.
*
* @since 3.1.0
* @access public
*/
public function display_rows()
{
// Query the post counts for this page
if (!$this->is_site_users) {
$post_counts = count_many_users_posts(array_keys($this->items));
}
$editable_roles = array_keys(get_editable_roles());
foreach ($this->items as $userid => $user_object) {
if (count($user_object->roles) <= 1) {
$role = reset($user_object->roles);
} elseif ($roles = array_intersect(array_values($user_object->roles), $editable_roles)) {
$role = reset($roles);
} else {
$role = reset($user_object->roles);
}
if (is_multisite() && empty($user_object->allcaps)) {
continue;
}
echo "\n\t" . $this->single_row($user_object, $style = '', $role, isset($post_counts) ? $post_counts[$userid] : 0);
}
}
示例3: display_rows
function display_rows()
{
// Query the post counts for this page
if (!$this->is_site_users) {
$post_counts = count_many_users_posts(array_keys($this->items));
}
$style = '';
foreach ($this->items as $userid => $user_object) {
if ($user_object->roles) {
$role = reset($user_object->roles);
}
if (is_multisite() && empty($role)) {
continue;
}
$style = ' class="alternate"' == $style ? '' : ' class="alternate"';
echo "\n\t", $this->single_row($user_object, $style, $role, isset($post_counts) ? $post_counts[$userid] : 0);
}
}
示例4: wp_redirect
</form>
<?php
break;
default:
if (!empty($_GET['_wp_http_referer'])) {
wp_redirect(remove_query_arg(array('_wp_http_referer', '_wpnonce'), stripslashes($_SERVER['REQUEST_URI'])));
exit;
}
include './admin-header.php';
$usersearch = isset($_GET['usersearch']) ? $_GET['usersearch'] : null;
$userspage = isset($_GET['userspage']) ? $_GET['userspage'] : null;
$role = isset($_GET['role']) ? $_GET['role'] : null;
// Query the user IDs for this page
$wp_user_search = new WP_User_Search($usersearch, $userspage, $role);
// Query the post counts for this page
$post_counts = count_many_users_posts($wp_user_search->get_results());
// Query the users for this page
cache_users($wp_user_search->get_results());
$messages = array();
if (isset($_GET['update'])) {
switch ($_GET['update']) {
case 'del':
case 'del_many':
$delete_count = isset($_GET['delete_count']) ? (int) $_GET['delete_count'] : 0;
$messages[] = '<div id="message" class="updated"><p>' . sprintf(_n('%s user deleted', '%s users deleted', $delete_count), $delete_count) . '</p></div>';
break;
case 'add':
$messages[] = '<div id="message" class="updated"><p>' . __('New user created.') . '</p></div>';
break;
case 'promote':
$messages[] = '<div id="message" class="updated"><p>' . __('Changed roles.') . '</p></div>';
示例5: the_title
<div class="main-box">
<div class="main-box-head">
<h1 class="main-box-title"><?php
the_title();
?>
</h1>
</div>
<div class="main-box-inside">
<?php
$meta = vce_get_page_meta(get_the_ID(), 'authors');
$ids = get_users(array('fields' => 'ID', 'who' => 'authors', 'exclude' => explode(',', $meta['exclude'])));
$users_with_posts = array_filter(count_many_users_posts($ids, 'post'));
$author_args = array('include' => array_keys($users_with_posts), 'order' => $meta['order'], 'orderby' => $meta['orderby']);
$authors = get_users($author_args);
?>
<?php
foreach ($authors as $author) {
?>
<div class="vce-author-card">
<div class="data-image">
<?php
echo get_avatar($author->ID, 112);
?>
示例6: _e
</th>
<th><?php
_e('Status', 'dokan');
?>
</th>
</tr>
</thead>
<tbody>
<?php
$paged = isset($_GET['pagenum']) ? absint($_GET['pagenum']) : 1;
$limit = 20;
$count = 0;
$offset = ($paged - 1) * $limit;
$user_search = new WP_User_Query(array('role' => 'seller', 'number' => $limit, 'offset' => $offset));
$sellers = (array) $user_search->get_results();
$post_counts = count_many_users_posts(wp_list_pluck($sellers, 'ID'), 'product');
if ($sellers) {
foreach ($sellers as $user) {
$info = dokan_get_store_info($user->ID);
$seller_enable = dokan_is_seller_enabled($user->ID);
$edit_link = esc_url(add_query_arg('wp_http_referer', urlencode(wp_unslash($_SERVER['REQUEST_URI'])), get_edit_user_link($user->ID)));
?>
<tr class="<?php
echo $count % 2 == 0 ? 'alternate' : 'odd';
?>
">
<th class="check-column">
<input type="checkbox" class="dokan-withdraw-allcheck" value="<?php
echo $user->ID;
?>
" name="users[]">
示例7: display_rows
/**
* Generate the list table rows.
*
* @since 3.1.0
* @access public
*/
public function display_rows()
{
// Query the post counts for this page
if (!$this->is_site_users) {
$post_counts = count_many_users_posts(array_keys($this->items));
}
foreach ($this->items as $userid => $user_object) {
if (is_multisite() && empty($user_object->allcaps)) {
continue;
}
echo "\n\t" . $this->single_row($user_object, '', '', isset($post_counts) ? $post_counts[$userid] : 0);
}
}
示例8: get_users_post_count
public static function get_users_post_count($user_ids, $post_type = null)
{
$user_ids = $user_ids ? $user_ids : get_users();
$post_type = $post_type ? $post_type : get_post_types();
if (is_array($post_type) && count($post_type) > 1) {
$results = array();
foreach ($post_type as $type) {
$counts = count_many_users_posts($user_ids, $type);
foreach ($counts as $user_id => $count) {
$results[$user_id][$type] = (int) $count;
}
}
return $results;
} else {
$post_type = is_array($post_type) ? $post_type[0] : $post_type;
return count_many_users_posts($user_ids, $post_type);
}
}
示例9: display_rows
function display_rows()
{
// Query the post counts for this page
$style = '';
$post_counts = count_many_users_posts(array_keys($this->items));
foreach ($this->items as $userid => $row_data) {
$style = 'alternate' == $style ? '' : 'alternate';
echo "\n\t", $this->single_row($row_data, $style, $post_counts[$userid]);
}
}
示例10: the_title
<div class="main-box">
<div class="main-box-head">
<h1 class="main-box-title"><?php
the_title();
?>
</h1>
</div>
<div class="main-box-inside">
<?php
//Detect only authors which have at least one post
$ids = get_users(array('fields' => 'ID', 'who' => 'authors'));
$users_posts = count_many_users_posts($ids, 'post');
$users_with_posts = array_filter($users_posts);
?>
<?php
$author_args = array('include' => array_keys($users_with_posts), 'order' => 'DESC', 'orderby' => 'post_count', 'fields' => 'ID');
$authors = get_users($author_args);
foreach ($authors as $author) {
?>
<div class="vce-author-card">
<div class="data-image">
<?php
echo get_avatar($author, 112);
?>
</div>
示例11: p2_user_suggestion
function p2_user_suggestion() {
global $wpdb, $current_user;
if ( ( function_exists( 'is_user_member_of_blog' ) && is_user_member_of_blog( $current_user->id ) ) || ( current_user_can( 'edit_posts' ) ) ) {
$p2_users = array();
if ( function_exists( 'get_users' ) )
$p2_users = get_users();
else
$p2_users = get_users_of_blog();
foreach( $p2_users as $p2_user ) {
$p2_user_ids[$p2_user->ID] = $p2_user->ID;
}
$post_counts = count_many_users_posts( array_keys( $p2_user_ids ) );
$users = array();
foreach( $p2_users as $p2_user ) {
if ( $post_counts[$p2_user->ID] > 0 ) {
$gravatar = get_avatar( $p2_user->user_email, 32 );
$users[] = array( 'name' => $p2_user->display_name, 'username' => $p2_user->user_login, 'gravatar' => $gravatar );
}
}
$users = apply_filters( "p2_user_suggestion", $users );
$users = json_encode( $users );
?>
<script type="text/javascript">
/* <![CDATA[ */
jQuery(document).ready(function() {
var json = <?php echo $users; ?>;
var names = [];
for( var i = 0, ol = json.length; i < ol; i++ ) {
names[i] = [json[i].name, json[i].username, json[i].gravatar];
}
jQuery("#comment").autocomplete(names, {
matchContains: true,
hotkeymode:true,
scroll: false,
formatItem: function(row) { return row[2] + ' ' + row[0] + ' @' + row[1] },
startmsg: '<?php echo esc_js( __( 'After typing @, type a name or username to find a member of this site' ) ); ?>',
noresultsmsg: '<?php echo esc_js( __( 'No matches.' ) ); ?>',
formatResult: function(row) { return '@' + row[1]; }
});
jQuery("#posttext").autocomplete(names, {
matchContains: true,
hotkeymode:true,
scroll: false,
formatItem: function(row) { return row[2] + ' ' + row[0] + ' @' + row[1] },
startmsg: '<?php echo esc_js( __( 'After typing @, type a name or username to find a member of this site' ) ); ?>',
noresultsmsg: '<?php echo esc_js( __( 'No matches.' ) ); ?>',
formatResult: function(row) { return '@' + row[1]; }
});
});
/* ]]> */
</script>
<?php
}
}
示例12: widget
function widget($args, $instance)
{
extract($args);
$title = $instance["title"];
$order_by = $instance["order_by"];
$order = $instance["order"];
$who = $instance["who"];
$include = $instance["include"];
$exclude = $instance["exclude"];
$number_of_users = $instance["number_of_users"];
$full_display = $instance["full_display"];
$show_post_count = $instance["show_post_count"];
$show_comment_count = $instance["show_comment_count"];
$show_if_empty = isset($instance["show_if_empty"]) ? $instance["show_if_empty"] : false;
$user_args = array('order_by' => $order_by, 'order' => $order, 'role' => $who);
if (trim($include) != '') {
$include = preg_replace('/\\s\\s+/', ' ', $include);
$include = explode(',', $include);
if (count($include) > 0) {
$user_args['include'] = $include;
}
}
if (trim($exclude) != '') {
$exclude = preg_replace('/\\s\\s+/', ' ', $exclude);
$exclude = explode(',', $exclude);
if (count($exclude) > 0) {
$user_args['exclude'] = $exclude;
}
}
if ($number_of_users != 'all') {
$user_args['number'] = $number_of_users;
}
$users = get_users($user_args);
if (!$show_if_empty && count($users) == 0) {
return;
}
echo $before_widget;
if ($title != '') {
echo $before_title . $title . $after_title;
}
if (count($users) > 0) {
$user_ids = array();
if ($show_post_count != 'none' || $show_comment_count != 'none') {
foreach ($users as $user) {
$user_ids[] = $user->ID;
}
if ($show_post_count != 'none') {
$this->post_counts = count_many_users_posts($user_ids);
}
if ($show_comment_count != 'none') {
$this->comment_counts = $this->count_many_users_comments($user_ids);
}
}
if ($full_display == 'all') {
$full_display = count($users);
} else {
$full_display = (int) $full_display;
}
$ret = "";
if ($full_display > 0) {
$ret .= "<ul class='full-display-users'>";
$ret .= $this->get_user_list($users, 0, $full_display, 'full', $instance);
$ret .= "</ul>";
}
if (count($users) > $full_display) {
$ret .= "<ul class='gravatar-display-users'>";
$total = count($users);
$ret .= $this->get_user_list($users, $full_display, $total, 'gravatar', $instance);
$ret .= "</ul>";
}
echo $ret;
}
echo $after_widget;
}
示例13: prepare_items
function prepare_items()
{
global $wpdb, $wp_version;
$userdata = array();
$i = 0;
$search = isset($_REQUEST['s']) ? wp_unslash(trim($_REQUEST['s'])) : '';
$users_per_page = $this->get_items_per_page('fields_per_page', 20);
$paged = $this->get_pagenum();
$args = array('number' => $users_per_page, 'offset' => ($paged - 1) * $users_per_page, 'fields' => 'all_with_meta');
if ($wp_version >= '4.4') {
if (isset($_REQUEST['prflxtrflds_role'])) {
$args['role__in'] = (array) $_REQUEST['prflxtrflds_role'];
}
} elseif (!empty($_REQUEST['prflxtrflds_role']) && 'all' != $_GET['prflxtrflds_role']) {
$args['role'] = $_GET['prflxtrflds_role'];
}
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);
$all_users = $wp_user_search->get_results();
/* Users post by id */
$post_counts = count_many_users_posts(array_keys($all_users));
$this->set_pagination_args(array('total_items' => $wp_user_search->get_total(), 'per_page' => $users_per_page));
$table_field_values = $wpdb->base_prefix . 'prflxtrflds_field_values';
$table_user_field_data = $wpdb->base_prefix . 'prflxtrflds_user_field_data';
$table_fields_id = $wpdb->base_prefix . 'prflxtrflds_fields_id';
foreach ($all_users as $user) {
$userdata[$i]['name'] = $user->user_nicename;
$userdata[$i]['role'] = implode(', ', $user->roles);
$userdata[$i]['user_id'] = $user->ID;
$userdata[$i]['disp_name'] = $user->first_name . ' ' . $user->last_name;
$userdata[$i]['email'] = $user->user_email;
$userdata[$i]['posts'] = $post_counts[$user->ID];
/* Get fields for current user */
$filled_fields = $wpdb->get_results("SELECT `" . $table_field_values . "`.`field_id`, `value_name` AS `user_value`\r\n\t\t\t\t\t\tFROM " . $table_user_field_data . ", " . $table_fields_id . ", `" . $table_field_values . "`\r\n\t\t\t\t\t\t\tWHERE `" . $table_user_field_data . "`.`user_value` = `" . $table_field_values . "`.`value_id`\r\n\t\t\t\t\t\t\t\tAND `user_id` = '" . $user->ID . "'\r\n\t\t\t\t\t\t\t\tAND `" . $table_field_values . "`.`field_id`= `" . $table_fields_id . "`.`field_id`\r\n\t\t\t\t\t\t\t\tAND `" . $table_user_field_data . "`.`field_id`= `" . $table_fields_id . "`.`field_id`\r\n\t\t\t\t\t\t\t\tAND `" . $table_fields_id . "`.`field_type_id` IN ( '2', '3', '4' )\r\n\t\t\t\t\t\tUNION\r\n\t\t\t\t\t\tSELECT `" . $table_user_field_data . "`.`field_id`, `user_value`\r\n\t\t\t\t\t\t\tFROM " . $table_user_field_data . ", " . $table_fields_id . " WHERE `user_id` = '" . $user->ID . "' \r\n\t\t\t\t\t\t\t\tAND `" . $table_user_field_data . "`.`field_id`= `" . $table_fields_id . "`.`field_id`\r\n\t\t\t\t\t\t\t\tAND `" . $table_fields_id . "`.`field_type_id` NOT IN ( '2', '3', '4' )\r\n\t\t\t\t\t\t", ARRAY_A);
if (!empty($filled_fields)) {
foreach ($filled_fields as $field) {
if (isset($userdata[$i][$field['field_id']])) {
/* Add value name */
$userdata[$i][$field['field_id']] .= ", " . $field['user_value'];
} else {
/* First write value name */
$userdata[$i][$field['field_id']] = $field['user_value'];
}
}
}
$i++;
}
/* Array search. If search by user not work */
if (!empty($search) && isset($userdata)) {
$not_empty_keys = array();
/* Get all columns */
$hidden_columns = get_user_option('manage' . 'bws-panel_page_profile-extra-fieldsuserdata' . 'columnshidden');
if (empty($hidden_columns)) {
$hidden_columns = array();
}
foreach ($userdata as $key => $oneuserdata) {
/* Data for one user */
foreach ($oneuserdata as $key_col_id => $one_value) {
/* Skip if current column is hidden */
if (in_array($key_col_id, $hidden_columns)) {
continue;
}
/* If value in array, save key */
if (false != stristr($one_value, $search)) {
$not_empty_keys[] = $key;
break;
}
}
}
if (isset($not_empty_keys)) {
$all_keys = array_keys($userdata);
/* Get empty entrys */
$to_delete = array_diff($all_keys, $not_empty_keys);
if (!empty($to_delete)) {
foreach ($to_delete as $key) {
/* Unset empty entrys */
unset($userdata[$key]);
}
}
}
}
/* Order by firstname - lastname */
if (isset($_GET['orderby']) && 'name' == $_GET['orderby']) {
if ('desc' == $_GET['order']) {
function prflxtrflds_cmp($first, $second)
{
/* Permitted names of sort check in switch */
return strcmp($first['disp_name'], $second['disp_name']) * -1;
/* DESC */
}
} else {
/* Sort result array. This use in usort. ASC by default */
function prflxtrflds_cmp($first, $second)
{
//.........这里部分代码省略.........
示例14: get_users
<div id="main" class="site-main">
<div id="primary" class="content-area">
<main id="content" class="site-content" role="main">
<section class="usa-section usa-grid-full bbg-staff__roster">
<header class="bbg-page__header usa-grid">
<h1 class="bbg-page__header-title">STAFF</h1>
<h3 class="bbg-page__header-description">ODDI’s designers, developers and storytellers help drive USIM digital projects.</h3>
</header>
<div class="usa-grid">
<?php
$blogusers = get_users();
$ids = array();
foreach ($blogusers as $user) {
array_push($ids, $user->ID);
}
$postCounts = count_many_users_posts($ids);
// Loop through the users to create the staff profiles
foreach ($blogusers as $user) {
outputUser($user, "staff", $postCounts);
}
?>
</div><!-- .usa-grid -->
</section>
</main>
</div><!-- #primary .content-area -->
<div id="secondary" class="widget-area" role="complementary"></div><!-- #secondary .widget-area -->
</div><!-- #main .site-main -->
<?php
示例15: widget_authors_count_authors
function widget_authors_count_authors($authors)
{
$author_ids = array();
foreach ($authors as $author) {
$author_ids[] = $author->ID;
}
$author_count = count_many_users_posts($author_ids);
return $author_count;
}