[wp-trac] [WordPress Trac] #47640: WP_Posts_List_Table::get_views() doesn't allow the "Mine" counts to be filtered

WordPress Trac noreply at wordpress.org
Tue Jul 2 16:37:23 UTC 2019


#47640: WP_Posts_List_Table::get_views() doesn't allow the "Mine" counts to be
filtered
-------------------------------+-----------------------------
 Reporter:  pbiron             |      Owner:  (none)
     Type:  defect (bug)       |     Status:  new
 Priority:  normal             |  Milestone:  Awaiting Review
Component:  Posts, Post Types  |    Version:
 Severity:  normal             |   Keywords:  has-screenshots
  Focuses:  administration     |
-------------------------------+-----------------------------
 [https://developer.wordpress.org/reference/classes/wp_posts_list_table/get_views/
 WP_Posts_List_Table::get_views()] calls
 [https://developer.wordpress.org/reference/functions/wp_count_posts/
 wp_count_posts()] to get the counts for the various post statuses.

 It then computes the count for posts owned by the current user for use in
 the "Mine" view.  That computation uses `$this->user_posts_count` which is
 computed in
 [https://developer.wordpress.org/reference/classes/wp_posts_list_table/__construct/
 WP_Posts_List_Table::__construct()] with custom SQL.

 The problem is that if you hook into the
 [https://developer.wordpress.org/reference/hooks/wp_count_posts/
 wp_count_posts] filter and alter the counts for each post status you can
 end up with a situation where the "Mine" count is very different than the
 sum of the post status counts.

 For example, I've got a CPT where some (but not all) of the posts of that
 type are just "placeholders" for posts of another CPT.  I hide those
 "placeholder" posts from the list table by hooking into
 [https://developer.wordpress.org/reference/hooks/request/ request] and
 altering the request that the list table uses.  I then hook into
 `wp_count_posts` to adjust the counts by post status accordingly (e.g.,
 don't count the "hidden" posts).  This results in a situation that could
 be **very** confusing for users (see screenshot).

 Thus, I suggest that a filter be added to filter the value of
 `$this->user_posts_count`.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/47640>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list