Make WordPress Core

Ticket #39947: 39947.diff

File 39947.diff, 2.2 KB (added by ryelle, 8 years ago)
  • src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php

     
    220220
    221221                if ( isset( $registered['sticky'], $request['sticky'] ) ) {
    222222                        $sticky_posts = get_option( 'sticky_posts', array() );
    223                         if ( $sticky_posts && $request['sticky'] ) {
     223                        if ( ! is_array( $sticky_posts ) ) {
     224                                $sticky_posts = array();
     225                        }
     226                        if ( $request['sticky'] ) {
    224227                                /*
    225228                                 * As post__in will be used to only get sticky posts,
    226229                                 * we have to support the case where post__in was already
     
    234237                                 * so we have to fake it a bit.
    235238                                 */
    236239                                if ( ! $args['post__in'] ) {
    237                                         $args['post__in'] = array( -1 );
     240                                        $args['post__in'] = array( 0 );
    238241                                }
    239242                        } elseif ( $sticky_posts ) {
    240243                                /*
  • tests/phpunit/tests/rest-api/rest-posts-controller.php

     
    740740                $this->assertEquals( $id1, $post['id'] );
    741741        }
    742742
     743        public function test_get_items_sticky_query_with_no_sticky_posts() {
     744                $id1 = self::$post_id;
     745
     746                update_option( 'sticky_posts', array() );
     747
     748                $request = new WP_REST_Request( 'GET', '/wp/v2/posts' );
     749                $request->set_param( 'sticky', true );
     750
     751                $response = $this->server->dispatch( $request );
     752                $this->assertCount( 0, $response->get_data() );
     753        }
     754
     755        public function test_get_items_sticky_with_post__in_query_no_sticky_posts() {
     756                $id1 = self::$post_id;
     757
     758                update_option( 'sticky_posts', array() );
     759
     760                $request = new WP_REST_Request( 'GET', '/wp/v2/posts' );
     761                $request->set_param( 'sticky', true );
     762                $request->set_param( 'include', array( $id1 ) );
     763
     764                $response = $this->server->dispatch( $request );
     765                $this->assertCount( 0, $response->get_data() );
     766        }
     767
    743768        public function test_get_items_not_sticky_query() {
    744769                $id1 = self::$post_id;
    745770                $id2 = $this->factory->post->create( array( 'post_status' => 'publish' ) );