Ticket #39947: 39947.diff
File 39947.diff, 2.2 KB (added by , 8 years ago) |
---|
-
src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php
220 220 221 221 if ( isset( $registered['sticky'], $request['sticky'] ) ) { 222 222 $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'] ) { 224 227 /* 225 228 * As post__in will be used to only get sticky posts, 226 229 * we have to support the case where post__in was already … … 234 237 * so we have to fake it a bit. 235 238 */ 236 239 if ( ! $args['post__in'] ) { 237 $args['post__in'] = array( -1);240 $args['post__in'] = array( 0 ); 238 241 } 239 242 } elseif ( $sticky_posts ) { 240 243 /* -
tests/phpunit/tests/rest-api/rest-posts-controller.php
740 740 $this->assertEquals( $id1, $post['id'] ); 741 741 } 742 742 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 743 768 public function test_get_items_not_sticky_query() { 744 769 $id1 = self::$post_id; 745 770 $id2 = $this->factory->post->create( array( 'post_status' => 'publish' ) );