コード例 #1
0
/**
 * Get the stat for the the requested type (number of ideas, comments or rates)
 *
 * @since 2.3.0
 *
 * @param string $type    the type of stat to get (eg: 'profile', 'comments', 'rates')
 * @param int    $user_id the User ID to get the stat for
 */
function wp_idea_stream_users_get_stat_for($type = '', $user_id = 0)
{
    $count = 0;
    if (empty($type)) {
        return $count;
    }
    if (empty($user_id)) {
        $user_id = wp_idea_stream_users_displayed_user_id();
    }
    if (empty($user_id)) {
        return ${$count};
    }
    if ('profile' === $type) {
        $count = count_user_posts($user_id, wp_idea_stream_get_post_type());
    } elseif ('comments' === $type) {
        $count = wp_idea_stream_comments_count_comments($user_id);
    } elseif ('rates' === $type) {
        $count = wp_idea_stream_count_user_rates($user_id);
    }
    /**
     * Filter the user stats by type (number of ideas "profile", "comments" or "rates").
     *
     * @since 2.3.0
     *
     * @param  int    $count the stat for the requested type.
     * @param  string $type "profile", "comments" or "rates".
     * @param  int    $user_id The user ID.
     */
    return (int) apply_filters('wp_idea_stream_users_get_stat_for', $count, $type, $user_id);
}
コード例 #2
0
 /**
  * Constructor
  *
  * @package WP Idea Stream
  * @subpackage comment/tags
  *
  * @since 2.0.0
  *
  * @param  array $args the loop args
  * @uses   wp_idea_stream_ideas_per_page() to get the per page setting
  * @uses   wp_idea_stream_is_current_user_profile() to check if on a user's profile
  * @uses   wp_idea_stream_cpage_rewrite_id() to get the comment pagination rewrite id
  * @uses   get_query_var() to get the value of a query var
  * @uses   wp_parse_args() to merge custom args with default ones
  * @uses   wp_idea_stream_get_post_type() to get the idea post type identifier
  * @uses   wp_idea_stream_comments_count_comments() to count the comments for the user
  * @uses   get_comments() to get the comments matching the arguments
  * @uses   wp_list_pluck() to pluck a certain field out of each object in a list.
  * @uses   get_posts() to get the posts corresponding to comments
  * @uses   wp_idea_stream_set_idea_var() to globalize a value for a later use
  * @uses   wp_idea_stream_is_pretty_links() to check if permalink structure is not default one
  * @uses   add_query_arg() to build an url
  * @uses   wp_idea_stream_users_get_user_comments_url() to get user's profile comment part url
  * @uses   wp_idea_stream_users_displayed_user_id() to get the displayed user ID
  * @uses   wp_idea_stream_users_get_displayed_user_username() to get the displayed user nicename
  * @uses   wp_idea_stream_cpage_slug() to get the slug for the comments pagination
  * @uses   WP_Idea_Stream_Loop::start() to build the user comments loop
  */
 public function __construct($args = array())
 {
     $default = array('post_status' => 'publish', 'status' => 'approve', 'user_id' => 0, 'number' => wp_idea_stream_ideas_per_page());
     // All post status if user is viewing his profile
     if (wp_idea_stream_is_current_user_profile() || current_user_can('read_private_ideas')) {
         $default['post_status'] = '';
     }
     //Merge default with requested
     $r = wp_parse_args($args, $default);
     // Set which pagination page
     if (get_query_var(wp_idea_stream_cpage_rewrite_id())) {
         $paged = get_query_var(wp_idea_stream_cpage_rewrite_id());
     } else {
         if (!empty($_GET[wp_idea_stream_cpage_rewrite_id()])) {
             $paged = absint($_GET[wp_idea_stream_cpage_rewrite_id()]);
         } else {
             if (!empty($r['page'])) {
                 $paged = absint($r['page']);
                 // Set default page (first page)
             } else {
                 $paged = 1;
             }
         }
     }
     $comments_args = array('post_type' => wp_idea_stream_get_post_type(), 'post_status' => $r['post_status'], 'status' => $r['status'], 'user_id' => (int) $r['user_id'], 'number' => (int) $r['number'], 'offset' => intval(($paged - 1) * $r['number']), 'page' => (int) $paged);
     if (!empty($comments_args)) {
         foreach ($comments_args as $key => $value) {
             $this->{$key} = $value;
         }
     } else {
         return false;
     }
     if (empty($this->user_id)) {
         $comment_count = 0;
     } else {
         $comment_count = wp_idea_stream_comments_count_comments($this->user_id);
     }
     // Get the comments
     $comments = get_comments($comments_args);
     if (!empty($comments)) {
         $post_ids = wp_list_pluck($comments, 'comment_post_ID');
         // Get all posts in the object cache.
         $posts = get_posts(array('include' => $post_ids, 'post_type' => wp_idea_stream_get_post_type()));
         // Reset will need to be done at the end of the loop
         wp_idea_stream_set_idea_var('needs_reset', true);
         // Build a new post array indexed by post ID
         $p = array();
         foreach ($posts as $post) {
             $p[$post->ID] = $post;
         }
         // Attach the corresponding post to each comment
         foreach ($comments as $key => $comment) {
             if (!empty($p[$comment->comment_post_ID])) {
                 $comments[$key]->idea = $p[$comment->comment_post_ID];
             }
         }
     }
     $params = array('plugin_prefix' => 'wp_idea_stream', 'item_name' => 'comment', 'item_name_plural' => 'comments', 'items' => $comments, 'total_item_count' => $comment_count, 'page' => $this->page, 'per_page' => $this->number);
     $paginate_args = array();
     if (!wp_idea_stream_is_pretty_links()) {
         $paginate_args['base'] = add_query_arg(wp_idea_stream_cpage_rewrite_id(), '%#%');
     } else {
         $paginate_args['base'] = trailingslashit(wp_idea_stream_users_get_displayed_profile_url('comments')) . '%_%';
         $paginate_args['format'] = wp_idea_stream_cpage_slug() . '/%#%/';
     }
     parent::start($params, apply_filters('wp_idea_stream_comments_pagination_args', $paginate_args));
 }
コード例 #3
0
 /**
  * Creates a comments submenu to the IdeaStream menu
  *
  * @package WP Idea Stream
  * @subpackage admin/comments
  *
  * @since 2.0.0
  *
  * @param  array  $menus list of menu items to add
  * @uses   wp_idea_stream_get_idea_var() to get a globalized value
  * @uses   wp_idea_stream_comments_count_comments() to build stats about idea comments
  * @uses   WP_Idea_Stream_Admin_Comments->bubbled_menu() to build the pending count bubble
  * @uses   add_query_arg() to build the parent slug
  * @return array         the new menu items
  */
 public function comments_menu($menus = array())
 {
     // Comments menu title
     $comments_menu_title = esc_html__('Comments', 'wp-idea-stream');
     $this->idea_comment_count = wp_idea_stream_get_idea_var('idea_comment_count');
     if (empty($this->idea_comment_count)) {
         $this->idea_comment_count = wp_idea_stream_comments_count_comments();
     }
     $comments_menu_title = $this->bubbled_menu($comments_menu_title . ' ', $this->idea_comment_count->moderated);
     $menus[0] = array('type' => 'comments', 'parent_slug' => wp_idea_stream()->admin->parent_slug, 'page_title' => esc_html__('Comments', 'wp-idea-stream'), 'menu_title' => $comments_menu_title, 'capability' => 'edit_ideas', 'slug' => add_query_arg('post_type', $this->post_type, 'edit-comments.php'), 'function' => '', 'alt_screen_id' => 'edit-comments.php', 'actions' => array('admin_head-%page%' => array($this, 'comments_menu_highlight')));
     return $menus;
 }