[wp-trac] [WordPress Trac] #32243: count_user_posts Should Accept Multiple Post Types
WordPress Trac
noreply at wordpress.org
Mon May 4 00:32:39 UTC 2015
#32243: count_user_posts Should Accept Multiple Post Types
-------------------------+------------------------------
Reporter: nikonratm | Owner:
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Users | Version: trunk
Severity: normal | Resolution:
Keywords: needs-patch | Focuses: template
-------------------------+------------------------------
Changes (by boonebgorges):
* keywords: has-patch needs-testing => needs-patch
Comment:
Thanks for the patch, nikonratm!
Your `$cap_final` logic doesn't look like it will work properly. Say I'm
querying for three post types: `array( 'foo', 'bar', 'baz' )`. And let's
say that I have the `read_private_posts` cap for 'baz' but not for 'foo'
and 'bar'. In this situation, it looks like the last post type cap will
overwrite the previous two, and private posts for all three post types
will be returned. If we're going to add this improvement, the SQL will
need to look like this:
`... WHERE (
( post_type = 'foo' AND post_status = 'publish' )
OR
( post_type = 'bar' AND post_status = 'publish' )
OR
( post_type = 'baz' AND ( post_status = 'publish' OR post_status =
'private' ) )
)`
(You'll have to make sure the "users can view their own private posts"
stuff works too.)
It'll help enormously to write some unit tests describing scenarios like
the above. See
https://core.trac.wordpress.org/browser/trunk/tests/phpunit/tests/post/getPostsByAuthorSql.php
for some examples. (You could also write indirect tests for
`count_user_posts()`.)
Small additional point: Make sure you don't break backward compatibility
for singular `$post_type`. If a string has been passed, cast it to `array(
$post_type )`.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/32243#comment:3>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list