WordPress.org

Make WordPress Core

Ticket #38420: 38420.diff

File 38420.diff, 1.4 KB (added by kadamwhite, 5 years ago)

Patch to permit multiple status values to be passed when querying the posts collection endpoint

  • src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php

    diff --git src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php
    index 9d7f85a..36b0e48 100644
    class WP_REST_Posts_Controller extends WP_REST_Controller { 
    19061906                        'default'           => 'publish',
    19071907                        'description'       => __( 'Limit result set to posts assigned a specific status; can be comma-delimited list of status types.' ),
    19081908                        'enum'              => array_merge( array_keys( get_post_stati() ), array( 'any' ) ),
    1909                         'sanitize_callback' => 'sanitize_key',
    1910                         'type'              => 'string',
     1909                        'sanitize_callback' => 'wp_parse_slug_list',
     1910                        'type'              => 'array',
    19111911                        'validate_callback' => array( $this, 'validate_user_can_query_private_statuses' ),
    19121912                );
    19131913                $params['filter'] = array(
    class WP_REST_Posts_Controller extends WP_REST_Controller { 
    19461946         * @return WP_Error|boolean
    19471947         */
    19481948        public function validate_user_can_query_private_statuses( $value, $request, $parameter ) {
    1949                 if ( 'publish' === $value ) {
     1949                if ( 'publish' === $value || is_array( $value ) && count( 1 === $value ) && in_array( 'publish', $value, true ) ) {
    19501950                        return true;
    19511951                }
    19521952                $post_type_obj = get_post_type_object( $this->post_type );