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(); }
/** * 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; }
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')); }
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']; } }
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; }
/** * 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); }
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']; }
/** * 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; }
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"; } }
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); } }
/** * 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 } }
/** @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 }
/** * 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)); }
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); } }
/** * 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]; }
/** * convert userdata to an object * @param object $user * @return user object after convert * - wp_error object if user invalid * @author Dakachi * @since 1.0 */ public function convert($user) { if (!$user->ID) { return new WP_Error('ae_invalid_user_data', __("Input invalid", ET_DOMAIN)); } $result = isset($user->data) ? $user->data : $user; foreach ($this->meta_data as $key) { $result->{$key} = get_user_meta($result->ID, $key, true); } $result->avatar = get_avatar($user->ID); $result->join_date = sprintf(__("Join on %s", ET_DOMAIN), (string) date(get_option('date_format'), strtotime($user->user_registered))); /** * get user role */ if (current_user_can('edit_users')) { $user_role = $user->roles; $result->role = array_pop($user_role); } /** * get all user meta data */ $author_metas = array('display_name', 'first_name', 'last_name', 'description', 'user_url'); foreach ($author_metas as $key => $author_meta) { $result->{$author_meta} = get_the_author_meta($author_meta, $result->ID); } /** * return post count */ $result->post_count = count_user_posts($result->ID); /** * return comment count */ $result->comment_count = ae_comment_count($result->user_email); $result->id = $result->ID; unset($result->user_pass); return apply_filters('ae_convert_user', $result); }
function edit_user_name_field($user) { $user_role = get_the_author_meta('roles', $user->ID); $user_role = $user_role[0]; if (current_user_can('edit_user', $user->ID) && !IS_PROFILE_PAGE && count_user_posts($user->ID) < 1) { $current_login = get_the_author_meta('user_login', $user->ID); $current_url = get_the_author_meta('user_nicename', $user->ID); ?> <h3><?php _e("Edit User Login", "blank"); ?> </h3> <label for="username_edit"><?php _e("User Name"); ?> </label> <input type="text" name="username_edit" id="username_edit" value="<?php echo esc_attr($current_login); ?> " placeholder="<?php echo esc_attr($current_login); ?> " class="regular-text" /><br /> <input type="hidden" name="user_nicename_edit" id="user_nicename_edit" value="<?php echo esc_attr($current_url); ?> "> <span class="description"><?php _e("This will also change the users permalink. Be careful with this. With great power comes great responsibility."); ?> </span> <?php } else { return false; } }
/** * Retrieve the number of posts by the author of the current post. * * @since 1.5 * @uses $post The current post in the Loop's DB object. * @uses count_user_posts() * @return int The number of posts by the author. */ function get_the_author_posts() { global $post; return count_user_posts($post->post_author); }
/** * Delete users by user meta. * * @since 5.5 * @param array $delete_options Delete Options * @return int Number of users deleted */ public function delete($delete_options) { if (!function_exists('wp_delete_user')) { require_once ABSPATH . 'wp-admin/includes/user.php'; } $count = 0; $options = array('meta_key' => $delete_options['meta_key'], 'meta_value' => $delete_options['meta_value'], 'meta_compare' => $delete_options['meta_compare']); if ($delete_options['limit_to'] > 0) { $options['number'] = $delete_options['limit_to']; } $users = get_users($options); foreach ($users as $user) { if ($delete_options['no_posts'] && count_user_posts($user->ID) > 0) { continue; } if ($delete_options['login_restrict']) { $login_days = $delete_options['login_days']; $last_login = bd_get_last_login($user->ID); if (null != $last_login) { if (strtotime($last_login) > strtotime('-' . $login_days . 'days')) { continue; } } else { continue; } } wp_delete_user($user->ID); $count++; } return $count; }
function ipin_top_user_by_pins($user_id) { $user_id = (int) $user_id; $blog_cat_id = of_get_option('blog_cat_id'); if ($blog_cat_id) { global $wpdb; $blog_post_count = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM {$wpdb->posts}\n\t\t\t\tLEFT JOIN {$wpdb->term_relationships} ON({$wpdb->posts}.ID = {$wpdb->term_relationships}.object_id)\n\t\t\t\tLEFT JOIN {$wpdb->term_taxonomy} ON({$wpdb->term_relationships}.term_taxonomy_id = {$wpdb->term_taxonomy}.term_taxonomy_id)\n\t\t\t\tWHERE {$wpdb->term_taxonomy}.term_id = %d\n\t\t\t\tAND {$wpdb->term_taxonomy}.taxonomy = 'category'\n\t\t\t\tAND {$wpdb->posts}.post_status = 'publish'\n\t\t\t\tAND post_author = %d\n\t\t\t\t", $blog_cat_id, $user_id)); } $pins_count = count_user_posts($user_id) - $blog_post_count; $args = array('order' => 'desc', 'orderby' => 'post_count', 'number' => '20'); $top_user_postcount_query = new WP_User_Query($args); $top_user_postcount_array = array(); foreach ($top_user_postcount_query->results as $top_user_postcount) { array_push($top_user_postcount_array, $top_user_postcount->ID); } $most_pins_pos = array_search($user_id, $top_user_postcount_array); if ($most_pins_pos !== false && $pins_count > 0) { return $most_pins_pos + 1; } else { return false; } }
/** * Flushes post cache * * @param integer $post_id * @return boolean */ function flush_post($post_id = null) { if (!$post_id) { $post_id = $this->_detect_post_id(); } if ($post_id) { $uris = array(); $domain_url = w3_get_domain_url(); $feeds = $this->_config->get_array('pgcache.purge.feed.types'); if ($this->_config->get_boolean('pgcache.purge.terms') || $this->_config->get_boolean('pgcache.purge.feed.terms')) { $taxonomies = get_post_taxonomies($post_id); $terms = nxt_get_post_terms($post_id, $taxonomies); } switch (true) { case $this->_config->get_boolean('pgcache.purge.author'): case $this->_config->get_boolean('pgcache.purge.archive.daily'): case $this->_config->get_boolean('pgcache.purge.archive.monthly'): case $this->_config->get_boolean('pgcache.purge.archive.yearly'): case $this->_config->get_boolean('pgcache.purge.feed.author'): $post = get_post($post_id); } /** * Home URL */ if ($this->_config->get_boolean('pgcache.purge.home')) { $home_path = w3_get_home_path(); $site_path = w3_get_site_path(); $uris[] = $home_path; if ($site_path != $home_path) { $uris[] = $site_path; } } /** * Post URL */ if ($this->_config->get_boolean('pgcache.purge.post')) { $post_link = post_permalink($post_id); $post_uri = str_replace($domain_url, '', $post_link); $uris[] = $post_uri; } /** * Post comments URLs */ if ($this->_config->get_boolean('pgcache.purge.comments') && function_exists('get_comments_pagenum_link')) { $comments_number = get_comments_number($post_id); $comments_per_page = get_option('comments_per_page'); $comments_pages_number = @ceil($comments_number / $comments_per_page); for ($pagenum = 1; $pagenum <= $comments_pages_number; $pagenum++) { $comments_pagenum_link = $this->_get_comments_pagenum_link($post_id, $pagenum); $comments_pagenum_uri = str_replace($domain_url, '', $comments_pagenum_link); $uris[] = $comments_pagenum_uri; } } /** * Post author URLs */ if ($this->_config->get_boolean('pgcache.purge.author') && $post) { $posts_number = count_user_posts($post->post_author); $posts_per_page = get_option('posts_per_page'); $posts_pages_number = @ceil($posts_number / $posts_per_page); $author_link = get_author_link(false, $post->post_author); $author_uri = str_replace($domain_url, '', $author_link); for ($pagenum = 1; $pagenum <= $posts_pages_number; $pagenum++) { $author_pagenum_link = $this->_get_pagenum_link($author_uri, $pagenum); $author_pagenum_uri = str_replace($domain_url, '', $author_pagenum_link); $uris[] = $author_pagenum_uri; } } /** * Post terms URLs */ if ($this->_config->get_boolean('pgcache.purge.terms')) { $posts_per_page = get_option('posts_per_page'); foreach ($terms as $term) { $term_link = get_term_link($term, $term->taxonomy); $term_uri = str_replace($domain_url, '', $term_link); $posts_pages_number = @ceil($term->count / $posts_per_page); for ($pagenum = 1; $pagenum <= $posts_pages_number; $pagenum++) { $term_pagenum_link = $this->_get_pagenum_link($term_uri, $pagenum); $term_pagenum_uri = str_replace($domain_url, '', $term_pagenum_link); $uris[] = $term_pagenum_uri; } } } /** * Daily archive URLs */ if ($this->_config->get_boolean('pgcache.purge.archive.daily') && $post) { $post_date = strtotime($post->post_date); $post_year = gmdate('Y', $post_date); $post_month = gmdate('m', $post_date); $post_day = gmdate('d', $post_date); $posts_per_page = get_option('posts_per_page'); $posts_number = $this->_get_archive_posts_count($post_year, $post_month, $post_day); $posts_pages_number = @ceil($posts_number / $posts_per_page); $day_link = get_day_link($post_year, $post_month, $post_day); $day_uri = str_replace($domain_url, '', $day_link); for ($pagenum = 1; $pagenum <= $posts_pages_number; $pagenum++) { $day_pagenum_link = $this->_get_pagenum_link($day_uri, $pagenum); $day_pagenum_uri = str_replace($domain_url, '', $day_pagenum_link); $uris[] = $day_pagenum_uri; } } /** * Monthly archive URLs */ if ($this->_config->get_boolean('pgcache.purge.archive.monthly') && $post) { $post_date = strtotime($post->post_date); $post_year = gmdate('Y', $post_date); $post_month = gmdate('m', $post_date); $posts_per_page = get_option('posts_per_page'); $posts_number = $this->_get_archive_posts_count($post_year, $post_month); $posts_pages_number = @ceil($posts_number / $posts_per_page); $month_link = get_month_link($post_year, $post_month); $month_uri = str_replace($domain_url, '', $month_link); for ($pagenum = 1; $pagenum <= $posts_pages_number; $pagenum++) { $month_pagenum_link = $this->_get_pagenum_link($month_uri, $pagenum); $month_pagenum_uri = str_replace($domain_url, '', $month_pagenum_link); $uris[] = $month_pagenum_uri; } } /** * Yearly archive URLs */ if ($this->_config->get_boolean('pgcache.purge.archive.yearly') && $post) { $post_date = strtotime($post->post_date); $post_year = gmdate('Y', $post_date); $posts_per_page = get_option('posts_per_page'); $posts_number = $this->_get_archive_posts_count($post_year); $posts_pages_number = @ceil($posts_number / $posts_per_page); $year_link = get_year_link($post_year); $year_uri = str_replace($domain_url, '', $year_link); for ($pagenum = 1; $pagenum <= $posts_pages_number; $pagenum++) { $year_pagenum_link = $this->_get_pagenum_link($year_uri, $pagenum); $year_pagenum_uri = str_replace($domain_url, '', $year_pagenum_link); $uris[] = $year_pagenum_uri; } } /** * Feed URLs */ if ($this->_config->get_boolean('pgcache.purge.feed.blog')) { foreach ($feeds as $feed) { $feed_link = get_feed_link($feed); $feed_uri = str_replace($domain_url, '', $feed_link); $uris[] = $feed_uri; } } if ($this->_config->get_boolean('pgcache.purge.feed.comments')) { foreach ($feeds as $feed) { $post_comments_feed_link = get_post_comments_feed_link($post_id, $feed); $post_comments_feed_uri = str_replace($domain_url, '', $post_comments_feed_link); $uris[] = $post_comments_feed_uri; } } if ($this->_config->get_boolean('pgcache.purge.feed.author') && $post) { foreach ($feeds as $feed) { $author_feed_link = get_author_feed_link($post->post_author, $feed); $author_feed_uri = str_replace($domain_url, '', $author_feed_link); $uris[] = $author_feed_uri; } } if ($this->_config->get_boolean('pgcache.purge.feed.terms')) { foreach ($terms as $term) { foreach ($feeds as $feed) { $term_feed_link = get_term_feed_link($term->term_id, $term->taxonomy, $feed); $term_feed_uri = str_replace($domain_url, '', $term_feed_link); $uris[] = $term_feed_uri; } } } /** * Flush cache */ if (count($uris)) { $cache =& $this->_get_cache(); $mobile_groups = $this->_get_mobile_groups(); $referrer_groups = $this->_get_referrer_groups(); $encryptions = $this->_get_encryptions(); $compressions = $this->_get_compressions(); foreach ($uris as $uri) { foreach ($mobile_groups as $mobile_group) { foreach ($referrer_groups as $referrer_group) { foreach ($encryptions as $encryption) { foreach ($compressions as $compression) { $page_key = $this->_get_page_key($uri, $mobile_group, $referrer_group, $encryption, $compression); $cache->delete($page_key); } } } } } /** * Purge varnish servers */ if ($this->_config->get_boolean('varnish.enabled')) { $varnish =& w3_instance('W3_Varnish'); foreach ($uris as $uri) { $varnish->purge($uri); } } } return true; } return false; }
public static function user_shortcode($atts) { if (self::$state['is_users_loop']) { $u = self::$state['current_user_object']; } else { //global $current_user; //get_currentuserinfo(); $current_user = wp_get_current_user(); self::$state['current_user_object'] = $current_user; $u = $current_user; } extract(shortcode_atts(array('field' => '', 'meta' => '', 'image' => '', 'size' => '', 'text' => '', 'out' => ''), $atts)); if (empty($u)) { return; } // no current user // Get field specified if (!empty($meta)) { $field = $meta; } if (!empty($image)) { if (!empty($field)) { $image_field = $field; } else { $image_field = 'image'; } $field = $image; } if (empty($field)) { // or just get the first parameter $field = isset($atts[0]) ? $atts[0] : null; } switch ($field) { case '': case 'fullname': return $u->display_name; break; case 'name': return $u->user_login; break; case 'slug': case 'nicename': return $u->user_nicename; break; case 'id': return $u->ID; break; case 'email': return $u->user_email; break; case 'url': return $u->user_url; break; case 'archive-url': return get_author_posts_url($u->ID); break; case 'archive-link': $url = get_author_posts_url($u->ID); $text = !empty($text) ? $text : $u->display_name; return '<a href="' . $url . '">' . $text . '</a>'; break; case 'avatar': return get_avatar($u->ID, !empty($size) ? $size : 96); break; case 'fullname': return $u->display_name; break; case 'post-count': return strval(count_user_posts($u->ID)); break; case 'role': if ($out == 'slug') { return rtrim(implode(',', $u->roles), ','); } else { return rtrim(implode(',', array_map('ucwords', $u->roles)), ','); } break; case 'edit-url': return admin_url('user-edit.php?user_id=' . $u->ID); break; case 'edit-link': if (empty($text)) { $text = 'Edit Profile'; } $url = admin_url('user-edit.php?user_id=' . $u->ID); return '<a href="' . $url . '">' . $text . '</a>'; case 'agent': return $_SERVER["HTTP_USER_AGENT"]; break; case 'device': if (class_exists('CCS_Mobile_Detect')) { return CCS_Mobile_Detect::$device; } else { return null; } break; case 'device-type': if (class_exists('CCS_Mobile_Detect')) { return CCS_Mobile_Detect::$device_type; } else { return null; } break; case 'browser': if (class_exists('CCS_Mobile_Detect')) { return CCS_Mobile_Detect::$browser; } else { return null; } break; default: // Custom user field $result = get_user_meta($u->ID, $field, true); break; } // Post-process // Attachment if (!empty($image)) { $params = ''; if (!empty($size)) { $params .= ' size="' . $size . '"'; } $result = do_ccs_shortcode('[attached id=' . $result . ']' . '[field ' . $image_field . $params . ']' . '[/attached]'); } // Array return $result; }
/** * Retrieve the number of posts by the author of the current post. * * @since 1.5.0 * * @return int The number of posts by the author. */ function get_the_author_posts() { $post = get_post(); if (!$post) { return 0; } return count_user_posts($post->post_author, $post->post_type); }
?> </a></h4> <h5> <a href="<?php echo get_author_posts_url($user->ID); ?> "> <?php echo count_user_posts($user->ID); ?> <?php if (count_user_posts($user->ID) == 1) { echo ' post'; } else { echo ' posts'; } ?> </a> </h5> <p class="author-description"><?php echo get_user_meta($user->ID, 'description', true); ?> </p>
/** * Retrieve the number of posts by the author of the current post. * * @since 1.5.0 * * @uses $post The current post in the Loop's DB object. * @uses count_user_posts() * @return int The number of posts by the author. */ function get_the_author_posts() { return count_user_posts(get_post()->post_author); }
/** * Get contribution * * @since 1.0.0 * * @param int $user_id [required] * @return mixed */ public function get_contribution($user_id = null) { if (empty($user_id) || intval($user_id) < 1 || count_user_posts($user_id, $this->domain_name, false) === 0) { return false; } $_posts = get_posts(array('numberposts' => -1, 'post_type' => $this->domain_name, 'author' => $user_id)); if (!empty($_posts)) { $contribution = 0; foreach ($_posts as $_post) { $contribution += intval(get_post_meta($_post->ID, 'wpqt_stocks', true)); } } update_user_meta($user_id, 'contribution', $contribution); return $contribution; }
<?php get_header(); ?> <section id="content" class="list"> <?php $list = get_users('exclude=1&orderby=post_count,display_name&posts_per_page=7'); foreach ($list as $author) { $total = count_user_posts($author->id); ?> <section class="author bg-gradiente"> <a href="<?php echo get_author_posts_url($author->id); ?> " rel="bookmark"><?php echo get_avatar($author->id, 120, 'http://workspace.blog.br/wp-content/themes/workspace/images/sem-foto.png'); ?> </a> <h2><a href="<?php echo get_author_posts_url($author->id); ?> " rel="bookmark"><?php echo $author->display_name; ?> </a></h2> <?php workspace_author_links($author->id); ?> <p><?php echo get_the_author_meta('description', $author->id); ?>
echo get_avatar($author->ID, 150); ?> </a> <h2 style="color:<?php echo esc_attr($user_color); ?> "><?php echo esc_html($author->display_name); ?> </h2> <p class="description"><?php echo esc_html($author->description); ?> </p> <?php $count = count_user_posts($author->ID); ?> <a href="<?php echo esc_url(get_author_posts_url($author->ID)); ?> " class="button post-count" title="<?php esc_attr_e(sprintf(__('Posts By: %s', 'extra'), $author->user_nicename)); ?> " rel="author"><?php esc_html_e(sprintf(_n('%d Post', '%d Posts', $count), $count)); ?> </a> </div> <!-- /.author-content --> <?php $social_links = '';
/** * Number of posts user has written. * * @since 0.71 * @deprecated 3.0.0 * @deprecated Use count_user_posts() * @see count_user_posts() */ function get_usernumposts($userid) { _deprecated_function(__FUNCTION__, '3.0', 'count_user_posts()'); return count_user_posts($userid); }
<div class="blog-post-content left"> <div class="blog-post-data-comment left"> <?php ?> <div class="home-authors-img left no-margin" style="display: inline-block"><a href="<?php echo get_author_posts_url($curauth->ID); ?> "><?php echo get_avatar($curauth->ID, $size = '79', $default = '<path_to_url>'); ?> </a></div><!--/home-authors-img--> <div class="user-info"> <div class="blog-post-user left"><?php echo count_user_posts($curauth->ID); ?> <?php _e('Posts', tk_theme_name); ?> </div><!--/blog-post-user--> <p><?php echo $author_bio; ?> </p><!--/blog-post-user--> </div> </div><!--/blog-post-data-comment--> <div class="title-border left"><span></span></div><!--title-border-->