本文整理汇总了PHP中count_user_posts函数的典型用法代码示例。如果您正苦于以下问题:PHP count_user_posts函数的具体用法?PHP count_user_posts怎么用?PHP count_user_posts使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了count_user_posts函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: widget
function widget($args, $instance)
{
extract(array_merge(array('title' => ''), $instance));
$authors = get_users(array('orderby' => 'post_count', 'order' => 'DESC'));
if (isset($before_widget)) {
echo $before_widget;
}
echo '<aside id="tt_authors_widget" class="widget tt-authors-widget tt-widget">';
if ($title != '') {
echo $args['before_title'] . $title . $args['after_title'];
}
echo '<ul>';
foreach ($authors as $author) {
echo '<li>';
echo '<span class="widget-thumb">';
echo get_avatar($author->ID, 55);
echo '</span>';
echo '<a href="' . get_author_posts_url($author->ID, $author->user_nicename) . '" class="widget-item-title" title="">' . $author->display_name . '</a>';
echo '<ul>
<li class="comments-number"><a href="' . get_author_posts_url($author->ID, $author->user_nicename) . '" title="">' . count_user_posts($author->ID) . ' ' . (count_user_posts($author->ID) > 1 ? __('posts', 'themeton') : __('post', 'themeton')) . '</a></li>
</ul>';
echo '</li>';
}
echo '</ul>';
echo '</aside>';
if (isset($after_widget)) {
echo $after_widget;
}
wp_reset_query();
}
示例2: comment_author_profile_link
/**
* Set the content width based on the theme's design and stylesheet.
*
* Used to set the width of images and content. Should be equal to the width the theme
* is designed for, generally via the style.css stylesheet.
*/
function comment_author_profile_link()
{
/* Get the comment author information */
global $comment;
$comment_ID = $comment->user_id;
$author = get_comment_author($comment_ID);
$url = get_comment_author_url($comment_ID);
/* Check if commenter is registered or not */
/* Registered Commenter */
$registeredID = get_userdata($comment_ID);
$authorName = $registeredID->display_name;
$authorLevel = $registeredID->user_level;
$authorURL = $registeredID->user_url;
$authorID = $registeredID->ID;
/* Check if they have edit posts capabilities & is author or higher */
if ($authorLevel > 1 && user_can($authorID, 'edit_posts') == true && count_user_posts($authorID) > 0) {
/* Author+ with Posts */
$return = '<a href="' . home_url() . '/?author=' . $authorID . '">' . $authorName . '</a>';
} else {
/* Below Author */
if (empty($authorURL) || 'http://' == $authorURL) {
$return = $authorName;
} else {
$return = "<a href='{$authorURL}' rel='external nofollow' class='url' target='_blank'>{$authorName}</a>";
}
}
return $return;
}
示例3: content_setup_nav
public function content_setup_nav()
{
global $bp;
if (!ap_opt('disable_reputation')) {
bp_core_new_nav_item(array('name' => __('Reputation', 'anspress-question-answer'), 'slug' => 'reputation', 'screen_function' => array($this, 'reputation_screen_link'), 'position' => 30, 'default_subnav_slug' => 'my-posts-subnav'));
}
bp_core_new_nav_item(array('name' => sprintf(__('Questions %s', 'anspress-question-answer'), '<span class="count">' . count_user_posts(bp_displayed_user_id(), 'question') . '</span>'), 'slug' => 'questions', 'screen_function' => array($this, 'questions_screen_link'), 'position' => 40, 'default_subnav_slug' => 'my-posts-subnav'));
bp_core_new_nav_item(array('name' => sprintf(__('Answers %s', 'anspress-question-answer'), '<span class="count">' . count_user_posts(bp_displayed_user_id(), 'answer') . '</span>'), 'slug' => 'answers', 'screen_function' => array($this, 'answers_screen_link'), 'position' => 40, 'default_subnav_slug' => 'my-posts-subnav'));
}
示例4: widget
public function widget($args, $instance)
{
if (is_single()) {
global $authordata, $post;
echo $args['before_widget'];
if (!empty($instance['title'])) {
echo $args['before_title'] . apply_filters('widget_title', $instance['title']) . $args['after_title'];
}
$latest_args = array('author' => $authordata->ID, 'post__not_in' => array($post->ID), 'numberposts' => $instance['posts_no'], 'post_status' => 'publish');
if ($instance['random']) {
$latest_args['orderby'] = 'rand';
}
$latest_posts = wp_get_recent_posts($latest_args);
if ($latest_posts) {
echo '<ul>';
foreach ($latest_posts as $latest) {
$post_categories = get_the_category($latest['ID']);
$post_categories_output = array();
foreach ($post_categories as $category) {
$category_output = '<a href="' . esc_url(get_category_link($category->cat_ID)) . '">' . esc_html($category->name) . '</a>';
array_push($post_categories_output, $category_output);
}
if (count($post_categories_output) > 0) {
$post_categories_output = ' ' . __('in', 'qtools') . ' ' . implode(', ', $post_categories_output) . ' ';
} else {
$post_categories_output = '';
}
echo '<li>';
if ($instance['thumbs'] && current_theme_supports('post-thumbnails')) {
echo '<div class="qtools-widget-post-thumb">';
if (has_post_thumbnail($latest['ID'])) {
echo '<a href="' . esc_url(get_permalink($latest['ID'])) . '">' . get_the_post_thumbnail($latest['ID'], 'thumbnail') . '</a>';
} else {
echo '<a href="' . esc_url(get_permalink($latest['ID'])) . '" title="' . apply_filters('the_title_attribute', $latest['post_title']) . '"><img src="' . plugin_dir_url(dirname(__FILE__)) . 'img/no-thumb.png" alt="' . apply_filters('the_title_attribute', $latest['post_title']) . '"></a>';
}
echo '</div>';
}
echo '<div class="qtools-widget-post-info">';
echo '<h4 class="qtools-widget-post-title"><a href="' . esc_url(get_permalink($latest['ID'])) . '">' . apply_filters('the_title', $latest['post_title']) . '</h4></a>';
if ($instance['meta']) {
echo '<div class="qtools-widget-post-meta"><a href="' . esc_url(get_author_posts_url($latest['post_author'])) . '">' . esc_html(get_the_author_meta('display_name', $latest['post_author'])) . '</a> ' . $post_categories_output . '</div>';
}
echo '</div>';
echo '</li>';
}
echo '</ul>';
if ($instance['posts_no'] < count_user_posts($authordata->ID)) {
echo '<a href="' . esc_html(get_author_posts_url($authordata->ID)) . '" class="small-title link">' . esc_html__('More posts', 'qtools') . '</a>';
}
} else {
esc_html_e('No posts found!', 'qtools');
}
echo $args['after_widget'];
}
}
示例5: widget
public function widget($args, $instance)
{
extract($args);
$title = apply_filters('widget_title', $instance['title']);
$authors_number = $instance['authors_number'];
echo $before_widget;
echo $before_title . $title . $after_title;
?>
<ul class="list-inline">
<?php
$users = array_merge(get_users('role=author'), get_users('role=administrator'));
foreach ($users as $q) {
?>
<li>
<?php
if (count_user_posts($q->ID) > 0) {
?>
<a href="<?php
echo get_author_posts_url($q->ID);
?>
" title="<?php
echo get_the_author_meta('display_name', $q->ID);
?>
page">
<?php
echo get_avatar($q->ID, 50);
?>
</a>
<?php
} else {
?>
<?php
echo get_avatar($q->ID, 50);
?>
<?php
}
?>
</li>
<?php
}
?>
</ul>
<?php
echo $after_widget;
}
示例6: widget
/**
* widget
*
* @param array $args
* @param array $instance
*/
public function widget($args, $instance)
{
$authors = get_users(array('orderby' => 'post_count', 'order' => 'DESC', 'who' => 'authors'));
foreach ($authors as $i => &$author) {
if (count_user_posts($author->ID)) {
$author = new \TimberUser($author);
} else {
unset($authors[$i]);
}
}
$instance['authors'] = $authors;
parent::widget($args, $instance);
}
示例7: widget
public function widget($args, $instance)
{
$title = apply_filters('widget_title', $instance['title']);
echo $args['before_widget'];
if (!empty($title)) {
echo $args['before_title'] . $title . $args['after_title'];
}
if (empty($instance['roles'])) {
$users = get_users(array('blog_id' => get_current_blog_id(), 'role' => 'author'));
} else {
$users = array();
foreach ($instance['roles'] as $key => $val) {
if ($val == 'on') {
$result = get_users(array('blog_id' => get_current_blog_id(), 'role' => $key));
$users = array_merge($users, $result);
}
}
}
$users = apply_filters('largo_staff_widget_users', $users);
$markup = '<ul class="staff-roster">';
foreach ($users as $user) {
$hide = get_user_meta($user->ID, 'hide', true);
if ($hide == 'on') {
continue;
}
$avatar = get_avatar($user->ID, '65');
$author_url = get_author_posts_url($user->ID);
$job_title = get_user_meta($user->ID, 'job_title', true);
$user_posts_link = '';
if (count_user_posts($user->ID) > 0) {
$user_posts_link = "<a href=\"{$author_url}\">{$user->first_name}'s posts</a>";
}
$markup .= "<li>";
$markup .= "<div>";
if (count_user_posts($user->ID) > 0) {
$markup .= "<a href='{$author_url}'>";
}
$markup .= "\t\t{$avatar}";
$markup .= "\t\t<span class='staff-name'>{$user->display_name}</span>";
if (count_user_posts($user->ID) > 0) {
$markup .= "</a>";
}
$markup .= "\t<p>{$job_title}<p>";
$markup .= "\t{$user_posts_link}";
$markup .= "</div>";
$markup .= "</li>";
}
$markup .= '</ul>';
echo $markup;
echo $args['after_widget'];
}
示例8: ed_charitable_allow_one_campaign_per_user
/**
* Prevent users from creating a new campaign.
*
* @param array $args
* @return array
*/
function ed_charitable_allow_one_campaign_per_user($args)
{
/* Don't stop people editing existing campaigns. */
if (get_query_var('campaign_id', false)) {
return;
}
$user_id = get_current_user_id();
if (!$user_id) {
return;
}
$count = count_user_posts($user_id, 'campaign');
if ($count > 0) {
$args['hidden'] = true;
}
return $args;
}
示例9: v2_coauthors_box
function v2_coauthors_box($author_ID = '')
{
$options = mh_theme_options();
if ($options['authorbox_layout'] != 'disable' && !is_attachment() || is_page_template('page-authors.php')) {
$name = get_the_author_meta('display_name', $author_ID);
$website = get_the_author_meta('user_url', $author_ID);
$facebook = get_the_author_meta('facebook', $author_ID);
$twitter = get_the_author_meta('twitter', $author_ID);
$googleplus = get_the_author_meta('googleplus', $author_ID);
$youtube = get_the_author_meta('youtube', $author_ID);
echo '<section class="author-box">' . "\n";
echo '<div class="author-box-wrap clearfix">' . "\n";
echo '<div class="author-box-avatar">' . get_avatar($author_ID, 113) . '</div>' . "\n";
echo '<h5 class="author-box-name">' . sprintf(__('About %s', 'mh'), esc_attr($name)) . '<span class="author-box-postcount"> (<a href="' . esc_url(get_author_posts_url($author_ID)) . '" title="' . sprintf(__('More articles written by %s', 'mh'), esc_attr($name)) . '">' . sprintf(__('%s Articles', 'mh'), count_user_posts($author_ID)) . '</a>)</span></h5>' . "\n";
if (get_the_author_meta('description', $author_ID)) {
echo '<div class="author-box-desc">' . wp_kses_post(get_the_author_meta('description', $author_ID)) . '</div>' . "\n";
} else {
echo '<div class="author-box-desc">' . __('The author has not yet added any personal or biographical info to his author profile.', 'mh') . '</div>' . "\n";
}
echo '</div>' . "\n";
if ($options['author_contact'] == 'enable') {
if ($website || $facebook || $twitter || $googleplus || $youtube) {
echo '<div class="author-box-contact">';
echo '<span class="author-box-contact-start">' . __('Contact:', 'mh') . ' </span>';
if ($website) {
echo '<a class="author-box-website" href="' . esc_url($website) . '" title="' . sprintf(__('Visit the website of %s', 'mh'), esc_attr($name)) . '" target="_blank">' . __('Website', 'mh') . '</a>';
}
if ($facebook) {
echo '<a class="author-box-facebook" href="' . esc_url($facebook) . '" title="' . sprintf(__('Follow %s on Facebook', 'mh'), esc_attr($name)) . '" target="_blank">' . __('Facebook', 'mh') . '</a>';
}
if ($twitter) {
echo '<a class="author-box-twitter" href="' . esc_url($twitter) . '" title="' . sprintf(__('Follow %s on Twitter', 'mh'), esc_attr($name)) . '" target="_blank">' . __('Twitter', 'mh') . '</a>';
}
if ($googleplus) {
echo '<a class="author-box-googleplus" href="' . esc_url($googleplus) . '" title="' . sprintf(__('Follow %s on Google+', 'mh'), esc_attr($name)) . '" target="_blank">' . __('Google+', 'mh') . '</a>';
}
if ($youtube) {
echo '<a class="author-box-youtube" href="' . esc_url($youtube) . '" title="' . sprintf(__('Follow %s on YouTube', 'mh'), esc_attr($name)) . '" target="_blank">' . __('YouTube', 'mh') . '</a>';
}
echo '</div>' . "\n";
}
}
echo '</section>' . "\n";
}
}
示例10: test_get_items_unauthenticated_only_shows_public_users
public function test_get_items_unauthenticated_only_shows_public_users()
{
$request = new WP_REST_Request('GET', '/wp/v2/users');
$response = $this->server->dispatch($request);
$this->assertEquals(array(), $response->get_data());
$this->factory->post->create(array('post_author' => $this->editor));
$this->factory->post->create(array('post_author' => $this->user, 'post_status' => 'draft'));
$request = new WP_REST_Request('GET', '/wp/v2/users');
$response = $this->server->dispatch($request);
$users = $response->get_data();
foreach ($users as $user) {
$this->assertTrue(count_user_posts($user['id']) > 0);
// Ensure we don't expose non-public data
$this->assertArrayNotHasKey('capabilities', $user);
$this->assertArrayNotHasKey('email', $user);
$this->assertArrayNotHasKey('roles', $user);
}
}
示例11: zatolab_list_authors
/**
* Print a list of all site contributors who published at least one post.
*
* @since Dichan 1.0
*
* @return void
*/
function zatolab_list_authors()
{
$contributor_ids = get_users(array('fields' => 'ID', 'orderby' => 'post_count', 'order' => 'DESC', 'who' => 'authors'));
foreach ($contributor_ids as $contributor_id) {
$post_count = count_user_posts($contributor_id);
// Move on if user has not published a post (yet).
if (!$post_count) {
continue;
}
?>
<div class="contributor">
<div class="contributor-info">
<div class="contributor-avatar"><?php
echo get_avatar($contributor_id, 132);
?>
</div>
<div class="contributor-summary">
<h2 class="contributor-name"><?php
echo get_the_author_meta('display_name', $contributor_id);
?>
</h2>
<p class="contributor-bio">
<?php
echo get_the_author_meta('description', $contributor_id);
?>
</p>
<a class="contributor-posts-link" href="<?php
echo esc_url(get_author_posts_url($contributor_id));
?>
">
<?php
printf(_n('%d Article', '%d Articles', $post_count, 'zatolab'), $post_count);
?>
</a>
</div><!-- .contributor-summary -->
</div><!-- .contributor-info -->
</div><!-- .contributor -->
<?php
}
}
示例12: widget
/** @see WP_Widget::widget */
function widget($args, $instance)
{
extract($args);
global $wpdb;
$title = apply_filters('widget_title', $instance['title']);
$count = $instance['count'];
if (!$size) {
$size = 40;
}
?>
<?php
echo $before_widget;
?>
<?php
if ($title) {
echo $before_title . $title . $after_title;
}
?>
<ul class="classy-widget-authors">
<?php
$authors = $wpdb->get_results("SELECT ID FROM {$wpdb->users} ORDER BY ID");
foreach ($authors as $author) {
$author_info = get_userdata($author->ID);
echo '<li class="clearfix">';
echo '<div style="float: left; margin-left: 5px;">';
echo get_avatar($author->ID, 40);
echo '</div>';
echo '<a href="' . get_author_posts_url($author->ID) . '" title="View author archive">';
echo $author_info->display_name;
if ($count) {
echo '(' . count_user_posts($author->ID) . ')';
}
echo '</a>';
echo '</li>';
}
?>
</ul>
<?php
echo $after_widget;
?>
<?php
}
示例13: test_post_publish_count_for_coauthor
/**
* Post published count should default to 'post', but be filterable
*
* @see https://github.com/Automattic/Co-Authors-Plus/issues/170
*/
public function test_post_publish_count_for_coauthor()
{
global $coauthors_plus;
$editor1 = get_user_by('id', $this->editor1);
/**
* Two published posts
*/
$coauthors_plus->add_coauthors($this->author1_post1, array($editor1->user_login));
$coauthors_plus->add_coauthors($this->author1_post2, array($editor1->user_login));
$this->assertEquals(2, count_user_posts($editor1->ID));
/**
* One published page too, but no filter
*/
$coauthors_plus->add_coauthors($this->author1_page1, array($editor1->user_login));
$this->assertEquals(2, count_user_posts($editor1->ID));
// Publish count to include posts and pages
$filter = function () {
return array('post', 'page');
};
add_filter('coauthors_count_published_post_types', $filter);
/**
* Two published posts and pages
*/
$coauthors_plus->add_coauthors($this->author1_page2, array($editor1->user_login));
$this->assertEquals(4, count_user_posts($editor1->ID));
// Publish count is just pages
remove_filter('coauthors_count_published_post_types', $filter);
$filter = function () {
return array('page');
};
add_filter('coauthors_count_published_post_types', $filter);
/**
* Just one published page now for the editor
*/
$author1 = get_user_by('id', $this->author1);
$coauthors_plus->add_coauthors($this->author1_page2, array($author1->user_login));
$this->assertEquals(1, count_user_posts($editor1->ID));
}
示例14: get_count
public static function get_count($key, $user_id)
{
$cache_id = 'user-count-' . $user_id;
$caches = (array) wp_cache_get($cache_id);
switch ($key) {
case 'works':
if (!isset($caches['works'])) {
$caches['works'] = (int) count_user_posts($user_id);
wp_cache_set($cache_id, $caches, null, self::$cache_expire);
}
return $caches['works'];
case 'comments':
if (!isset($caches['comments'])) {
$caches['comments'] = (int) theme_features::get_user_comments_count($user_id);
wp_cache_set($cache_id, $caches, null, self::$cache_expire);
}
return $caches['comments'];
case 'followers_count':
return (int) get_user_meta($user_id, self::$user_meta_key['followers_count'], true);
case 'following_count':
return (int) get_user_meta($user_id, self::$user_meta_key['following_count'], true);
}
}
示例15: is_user_required_for_blog
/**
* Does the given user need to be migrated?
*
* @param int $user_id
* @param int $blog_id Optional.
*
* @return bool
*/
private function is_user_required_for_blog($user_id, $blog_id = 0)
{
static $users = array();
if (empty($user_id)) {
$user_id = 0;
}
if (empty($blog_id)) {
$blog_id = 0;
}
if (isset($users[$blog_id][$user_id])) {
return $users[$blog_id][$user_id];
}
if (!is_multisite()) {
$users[$blog_id][$user_id] = true;
return $users[$blog_id][$user_id];
}
$subsites = $this->subsites_list();
if (empty($subsites) || !array_key_exists($blog_id, $subsites)) {
$users[$blog_id][$user_id] = false;
return $users[$blog_id][$user_id];
}
if (is_user_member_of_blog($user_id, $blog_id)) {
$users[$blog_id][$user_id] = true;
return $users[$blog_id][$user_id];
}
// If the user has any posts that are going to be migrated, we need the user regardless of whether they still have access.
switch_to_blog($blog_id);
$user_posts = count_user_posts($user_id);
restore_current_blog();
if (0 < $user_posts) {
$users[$blog_id][$user_id] = true;
return $users[$blog_id][$user_id];
}
// If here, user not required.
$users[$blog_id][$user_id] = false;
return $users[$blog_id][$user_id];
}