Make WordPress Core

Changeset 32524


Ignore:
Timestamp:
05/21/2015 07:48:19 PM (9 years ago)
Author:
boonebgorges
Message:

Streamline support for multiple post types in get_posts_by_author_sql().

  • Don't accept a comma-separated list, only a single post type or an array of post types. This is easier to document.
  • Add changelog entries to all calling functions.

Props DrewAPicture.
Fixes #32243.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/post.php

    r32523 r32524  
    53275327 *
    53285328 * @since 2.2.0
    5329  *
    5330  * @param string|array $post_type Array or comma-separated string of post types.
    5331  *                               Currently only supports 'post' or 'page'.
     5329 * @since 4.3.0 Added the ability to pass an array to `$post_type`.
     5330 *
     5331 * @param string|array $post_type Single post type or an array of post types. Currently only supports 'post' or 'page'.
    53325332 * @return string SQL code that can be added to a where clause.
    53335333 */
     
    53405340 *
    53415341 * @since 3.0.0
    5342  * @since 4.3.0 Introduced the ability to pass multiple post types to `$post_type`.
     5342 * @since 4.3.0 Introduced the ability to pass an array of post types to `$post_type`.
    53435343 *
    53445344 * @see get_private_posts_cap_sql()
    53455345 *
    5346  * @param array|string   $post_type   Array or comma-separated list of post type(s).
     5346 * @param array|string   $post_type   Single post type or an array of post types.
    53475347 * @param bool           $full        Optional. Returns a full WHERE statement instead of just
    53485348 *                                    an 'andalso' term. Default true.
     
    53585358        $post_types = $post_type;
    53595359    } else {
    5360         $post_types = preg_split( '/[\s,]+/', $post_type );
     5360        $post_types = array( $post_type );
    53615361    }
    53625362
  • trunk/src/wp-includes/user.php

    r32523 r32524  
    252252 * @since 3.0.0
    253253 * @since 4.1.0 Added `$post_type` argument.
    254  * @since 4.3.0 Added `$public_only` argument.
     254 * @since 4.3.0 Added `$public_only` argument. Added the ability to pass an array of post types to `$post_type`.
    255255 *
    256256 * @global wpdb $wpdb WordPress database object for queries.
     
    289289 *
    290290 * @param array        $users       Array of user IDs.
    291  * @param string|array $post_type   Optional. Array or comma-separated list of post types to check. Defaults to 'post'.
     291 * @param string|array $post_type   Optional. Single post type or array of post types to check. Defaults to 'post'.
    292292 * @param bool         $public_only Optional. Only return counts for public posts.  Defaults to false.
    293293 * @return array Amount of posts each user has written.
  • trunk/tests/phpunit/tests/post/getPostsByAuthorSql.php

    r32523 r32524  
    2525        register_post_type( 'bar' );
    2626
    27         $maybe_string = get_posts_by_author_sql( 'foo,bar' );
     27        $maybe_string = get_posts_by_author_sql( array( 'foo', 'bar' ) );
    2828        $this->assertContains( "post_type = 'foo'", $maybe_string );
    2929        $this->assertContains( "post_type = 'bar'", $maybe_string );
     
    136136        wp_set_current_user( $u );
    137137
    138         $maybe_string = get_posts_by_author_sql( 'foo,bar,baz' );
     138        $maybe_string = get_posts_by_author_sql( array( 'foo', 'bar', 'baz' ) );
    139139        $this->assertNotContains( "post_type = 'foo' AND ( post_status = 'publish' OR post_status = 'private' )", $maybe_string );
    140140        $this->assertNotContains( "post_type = 'bar' AND ( post_status = 'publish' OR post_status = 'private' )", $maybe_string );
Note: See TracChangeset for help on using the changeset viewer.