<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[32523] trunk: Support multiple post types in `count_user_posts()` and other functions that use `get_posts_by_author_sql()`.</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="https://core.trac.wordpress.org/changeset/32523">32523</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"https://core.trac.wordpress.org/changeset/32523","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>boonebgorges</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2015-05-21 18:42:49 +0000 (Thu, 21 May 2015)</dd>
</dl>
<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>Support multiple post types in `count_user_posts()` and other functions that use `get_posts_by_author_sql()`.
Props nikonratm.
Fixes <a href="https://core.trac.wordpress.org/ticket/32243">#32243</a>.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpincludespostphp">trunk/src/wp-includes/post.php</a></li>
<li><a href="#trunksrcwpincludesuserphp">trunk/src/wp-includes/user.php</a></li>
<li><a href="#trunktestsphpunittestspostgetPostsByAuthorSqlphp">trunk/tests/phpunit/tests/post/getPostsByAuthorSql.php</a></li>
<li><a href="#trunktestsphpunittestsusercountUserPostsphp">trunk/tests/phpunit/tests/user/countUserPosts.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpincludespostphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/post.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/post.php 2015-05-21 18:09:46 UTC (rev 32522)
+++ trunk/src/wp-includes/post.php 2015-05-21 18:42:49 UTC (rev 32523)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -5327,7 +5327,8 @@
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 2.2.0
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param string $post_type Post type. Currently only supports 'post' or 'page'.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param string|array $post_type Array or comma-separated string of post types.
+ * Currently only supports 'post' or 'page'.
</ins><span class="cx" style="display: block; padding: 0 10px"> * @return string SQL code that can be added to a where clause.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> function get_private_posts_cap_sql( $post_type ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -5338,63 +5339,77 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * Retrieve the post SQL based on capability, author, and type.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 3.0.0
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @since 4.3.0 Introduced the ability to pass multiple post types to `$post_type`.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @see get_private_posts_cap_sql()
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param string $post_type Post type.
- * @param bool $full Optional. Returns a full WHERE statement instead of just
- * an 'andalso' term. Default true.
- * @param int $post_author Optional. Query posts having a single author ID. Default null.
- * @param bool $public_only Optional. Only return public posts. Skips cap checks for
- * $current_user. Default false.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param array|string $post_type Array or comma-separated list of post type(s).
+ * @param bool $full Optional. Returns a full WHERE statement instead of just
+ * an 'andalso' term. Default true.
+ * @param int $post_author Optional. Query posts having a single author ID. Default null.
+ * @param bool $public_only Optional. Only return public posts. Skips cap checks for
+ * $current_user. Default false.
</ins><span class="cx" style="display: block; padding: 0 10px"> * @return string SQL WHERE code that can be added to a query.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> function get_posts_by_author_sql( $post_type, $full = true, $post_author = null, $public_only = false ) {
</span><span class="cx" style="display: block; padding: 0 10px"> global $wpdb;
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- // Private posts.
- $post_type_obj = get_post_type_object( $post_type );
- if ( ! $post_type_obj )
- return $full ? 'WHERE 1 = 0' : ' 1 = 0 ';
-
- /**
- * Filter the capability to read private posts for a custom post type
- * when generating SQL for getting posts by author.
- *
- * @since 2.2.0
- * @deprecated 3.2.0 The hook transitioned from "somewhat useless" to "totally useless".
- *
- * @param string $cap Capability.
- */
- if ( ! $cap = apply_filters( 'pub_priv_sql_capability', '' ) ) {
- $cap = $post_type_obj->cap->read_private_posts;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( is_array( $post_type ) ) {
+ $post_types = $post_type;
+ } else {
+ $post_types = preg_split( '/[\s,]+/', $post_type );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $sql = $wpdb->prepare( 'post_type = %s', $post_type );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $post_type_clauses = array();
+ foreach ( $post_types as $post_type ) {
+ $post_type_obj = get_post_type_object( $post_type );
+ if ( ! $post_type_obj ) {
+ continue;
+ }
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( null !== $post_author ) {
- $sql .= $wpdb->prepare( ' AND post_author = %d', $post_author );
- }
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ /**
+ * Filter the capability to read private posts for a custom post type
+ * when generating SQL for getting posts by author.
+ *
+ * @since 2.2.0
+ * @deprecated 3.2.0 The hook transitioned from "somewhat useless" to "totally useless".
+ *
+ * @param string $cap Capability.
+ */
+ if ( ! $cap = apply_filters( 'pub_priv_sql_capability', '' ) ) {
+ $cap = current_user_can( $post_type_obj->cap->read_private_posts );
+ }
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- // Only need to check the cap if $public_only is false.
- $post_status_sql = "post_status = 'publish'";
- if ( false === $public_only ) {
- if ( current_user_can( $cap ) ) {
- // Does the user have the capability to view private posts? Guess so.
- $post_status_sql .= " OR post_status = 'private'";
- } elseif ( is_user_logged_in() ) {
- // Users can view their own private posts.
- $id = get_current_user_id();
- if ( null === $post_author || ! $full ) {
- $post_status_sql .= " OR post_status = 'private' AND post_author = $id";
- } elseif ( $id == (int) $post_author ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // Only need to check the cap if $public_only is false.
+ $post_status_sql = "post_status = 'publish'";
+ if ( false === $public_only ) {
+ if ( $cap ) {
+ // Does the user have the capability to view private posts? Guess so.
</ins><span class="cx" style="display: block; padding: 0 10px"> $post_status_sql .= " OR post_status = 'private'";
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ } elseif ( is_user_logged_in() ) {
+ // Users can view their own private posts.
+ $id = get_current_user_id();
+ if ( null === $post_author || ! $full ) {
+ $post_status_sql .= " OR post_status = 'private' AND post_author = $id";
+ } elseif ( $id == (int) $post_author ) {
+ $post_status_sql .= " OR post_status = 'private'";
+ } // else none
</ins><span class="cx" style="display: block; padding: 0 10px"> } // else none
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- } // else none
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ }
+
+ $post_type_clauses[] = "( post_type = '" . $post_type . "' AND ( $post_status_sql ) )";
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $sql .= " AND ($post_status_sql)";
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( empty( $post_type_clauses ) ) {
+ return $full ? 'WHERE 1 = 0' : '1 = 0';
+ }
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $sql = '( '. implode( ' OR ', $post_type_clauses ) . ' )';
+
+ if ( null !== $post_author ) {
+ $sql .= $wpdb->prepare( ' AND post_author = %d', $post_author );
+ }
+
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( $full ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $sql = 'WHERE ' . $sql;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span></span></pre></div>
<a id="trunksrcwpincludesuserphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/user.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/user.php 2015-05-21 18:09:46 UTC (rev 32522)
+++ trunk/src/wp-includes/user.php 2015-05-21 18:42:49 UTC (rev 32523)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -251,17 +251,19 @@
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 3.0.0
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 4.1.0 Added `$post_type` argument.
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @since 4.3.0 Added `$public_only` argument.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @global wpdb $wpdb WordPress database object for queries.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param int $userid User ID.
- * @param string $post_type Optional. Post type to count the number of posts for. Default 'post'.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param int $userid User ID.
+ * @param array|string $post_type Optional. Post type(s) to count the number of posts for. Default 'post'.
+ * @param bool $public_only Optional. Only return counts for public posts. Defaults to false.
</ins><span class="cx" style="display: block; padding: 0 10px"> * @return int Number of posts the user has written in this post type.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-function count_user_posts( $userid, $post_type = 'post' ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+function count_user_posts( $userid, $post_type = 'post', $public_only = false ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> global $wpdb;
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $where = get_posts_by_author_sql( $post_type, true, $userid );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $where = get_posts_by_author_sql( $post_type, true, $userid, $public_only );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $count = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->posts $where" );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -270,10 +272,12 @@
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 2.7.0
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 4.1.0 Added `$post_type` argument.
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @since 4.3.0 Added `$public_only` argument.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param int $count The user's post count.
- * @param int $userid User ID.
- * @param string $post_type Post type to count the number of posts for.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param int $count The user's post count.
+ * @param int $userid User ID.
+ * @param string|array $post_types Post types to count the number of posts for.
+ * @param bool $public_only Whether to limit counted posts to public posts.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> return apply_filters( 'get_usernumposts', $count, $userid, $post_type );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -283,9 +287,9 @@
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 3.0.0
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param array $users Array of user IDs.
- * @param string $post_type Optional. Post type to check. Defaults to post.
- * @param bool $public_only Optional. Only return counts for public posts. Defaults to false.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param array $users Array of user IDs.
+ * @param string|array $post_type Optional. Array or comma-separated list of post types to check. Defaults to 'post'.
+ * @param bool $public_only Optional. Only return counts for public posts. Defaults to false.
</ins><span class="cx" style="display: block; padding: 0 10px"> * @return array Amount of posts each user has written.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> function count_many_users_posts( $users, $post_type = 'post', $public_only = false ) {
</span></span></pre></div>
<a id="trunktestsphpunittestspostgetPostsByAuthorSqlphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/post/getPostsByAuthorSql.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/post/getPostsByAuthorSql.php 2015-05-21 18:09:46 UTC (rev 32522)
+++ trunk/tests/phpunit/tests/post/getPostsByAuthorSql.php 2015-05-21 18:42:49 UTC (rev 32523)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -20,6 +20,18 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertContains( '1 = 0', $maybe_string );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ public function test_multiple_post_types(){
+ register_post_type( 'foo' );
+ register_post_type( 'bar' );
+
+ $maybe_string = get_posts_by_author_sql( 'foo,bar' );
+ $this->assertContains( "post_type = 'foo'", $maybe_string );
+ $this->assertContains( "post_type = 'bar'", $maybe_string );
+
+ _unregister_post_type( 'foo' );
+ _unregister_post_type( 'bar' );
+ }
+
</ins><span class="cx" style="display: block; padding: 0 10px"> public function test_full_true(){
</span><span class="cx" style="display: block; padding: 0 10px"> $maybe_string = get_posts_by_author_sql( 'post', true );
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertRegExp( '/^WHERE /', $maybe_string );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -112,4 +124,25 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> wp_set_current_user( $current_user );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+ public function test_user_has_access_only_to_private_posts_for_certain_post_types(){
+ register_post_type( 'foo', array( 'capabilities' => array( 'read_private_posts' => 'read_private_foo' ) ) );
+ register_post_type( 'bar', array( 'capabilities' => array( 'read_private_posts' => 'read_private_bar' ) ) );
+ register_post_type( 'baz', array( 'capabilities' => array( 'read_private_posts' => 'read_private_baz' ) ) );
+ $current_user = get_current_user_id();
+ $u = $this->factory->user->create( array( 'role' => 'editor' ) );
+ $editor_role = get_role('editor');
+ $editor_role->add_cap( 'read_private_baz' );
+ wp_set_current_user( $u );
+
+ $maybe_string = get_posts_by_author_sql( 'foo,bar,baz' );
+ $this->assertNotContains( "post_type = 'foo' AND ( post_status = 'publish' OR post_status = 'private' )", $maybe_string );
+ $this->assertNotContains( "post_type = 'bar' AND ( post_status = 'publish' OR post_status = 'private' )", $maybe_string );
+ $this->assertContains( "post_type = 'baz' AND ( post_status = 'publish' OR post_status = 'private' )", $maybe_string );
+
+ _unregister_post_type( 'foo' );
+ _unregister_post_type( 'bar' );
+ _unregister_post_type( 'baz' );
+ wp_set_current_user( $current_user );
+ }
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span></span></pre></div>
<a id="trunktestsphpunittestsusercountUserPostsphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/user/countUserPosts.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/user/countUserPosts.php 2015-05-21 18:09:46 UTC (rev 32522)
+++ trunk/tests/phpunit/tests/user/countUserPosts.php 2015-05-21 18:42:49 UTC (rev 32523)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -78,4 +78,18 @@
</span><span class="cx" style="display: block; padding: 0 10px"> public function test_count_user_posts_post_type_cpt() {
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertEquals( 3, count_user_posts( self::$user_id, 'wptests_pt' ) );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+ /**
+ * @ticket 32243
+ */
+ public function test_count_user_posts_with_multiple_post_types() {
+ $this->assertEquals( 7, count_user_posts( self::$user_id, array( 'wptests_pt', 'post' ) ) );
+ }
+
+ /**
+ * @ticket 32243
+ */
+ public function test_count_user_posts_should_ignore_non_existent_post_types() {
+ $this->assertEquals( 4, count_user_posts( self::$user_id, array( 'foo', 'post' ) ) );
+ }
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span></span></pre>
</div>
</div>
</body>
</html>