Changeset 59801
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php
r59630 r59801 248 248 'exclude' => 'post__not_in', 249 249 'include' => 'post__in', 250 'ignore_sticky' => 'ignore_sticky_posts', 250 251 'menu_order' => 'menu_order', 251 252 'offset' => 'offset', … … 336 337 $args['post__not_in'] = array_merge( $args['post__not_in'], $sticky_posts ); 337 338 } 339 } 340 341 /* 342 * Honor the original REST API `post__in` behavior. Don't prepend sticky posts 343 * when `post__in` has been specified. 344 */ 345 if ( ! empty( $args['post__in'] ) ) { 346 unset( $args['ignore_sticky_posts'] ); 338 347 } 339 348 … … 3046 3055 'type' => 'boolean', 3047 3056 ); 3057 3058 $query_params['ignore_sticky'] = array( 3059 'description' => __( 'Whether to ignore sticky posts or not.' ), 3060 'type' => 'boolean', 3061 'default' => false, 3062 ); 3048 3063 } 3049 3064 -
trunk/tests/phpunit/tests/rest-api/rest-posts-controller.php
r59766 r59801 198 198 'exclude', 199 199 'format', 200 'ignore_sticky', 200 201 'include', 201 202 'modified_after', … … 5717 5718 5718 5719 /** 5720 * Test the REST API support for `ignore_sticky_posts`. 5721 * 5722 * @ticket 35907 5723 * 5724 * @covers WP_REST_Posts_Controller::get_items 5725 */ 5726 public function test_get_posts_ignore_sticky_default_prepends_sticky_posts() { 5727 $id1 = self::$post_id; 5728 // Create more recent post to avoid automatically placing other at the top. 5729 $id2 = self::factory()->post->create( array( 'post_status' => 'publish' ) ); 5730 5731 update_option( 'sticky_posts', array( $id1 ) ); 5732 5733 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); 5734 $response = rest_get_server()->dispatch( $request ); 5735 $data = $response->get_data(); 5736 5737 $this->assertSame( $data[0]['id'], $id1, 'Response has sticky post at the top.' ); 5738 $this->assertSame( $data[1]['id'], $id2, 'It is followed by most recent post.' ); 5739 } 5740 5741 /** 5742 * Test the REST API support for `ignore_sticky_posts`. 5743 * 5744 * @ticket 35907 5745 * 5746 * @covers WP_REST_Posts_Controller::get_items 5747 */ 5748 public function test_get_posts_ignore_sticky_ignores_post_stickiness() { 5749 $id1 = self::$post_id; 5750 $id2 = self::factory()->post->create( array( 'post_status' => 'publish' ) ); 5751 5752 update_option( 'sticky_posts', array( $id1 ) ); 5753 5754 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); 5755 $request->set_param( 'ignore_sticky', true ); 5756 $response = rest_get_server()->dispatch( $request ); 5757 $data = $response->get_data(); 5758 5759 $this->assertSame( $data[0]['id'], $id2, 'Response has no sticky post at the top.' ); 5760 } 5761 5762 /** 5763 * Test the REST API support for `ignore_sticky_posts`. 5764 * 5765 * @ticket 35907 5766 * 5767 * @covers WP_REST_Posts_Controller::get_items 5768 */ 5769 public function test_get_posts_ignore_sticky_honors_include() { 5770 $id1 = self::$post_id; 5771 $id2 = self::factory()->post->create( array( 'post_status' => 'publish' ) ); 5772 5773 update_option( 'sticky_posts', array( $id1 ) ); 5774 5775 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); 5776 $request->set_param( 'include', array( $id2 ) ); 5777 $response = rest_get_server()->dispatch( $request ); 5778 $data = $response->get_data(); 5779 5780 $this->assertCount( 1, $data, 'Only one post is expected to be returned.' ); 5781 $this->assertSame( $data[0]['id'], $id2, 'Returns the included post.' ); 5782 } 5783 5784 /** 5719 5785 * Internal function used to disable an insert query which 5720 5786 * will trigger a wpdb error for testing purposes. -
trunk/tests/qunit/fixtures/wp-api-generated.js
r59532 r59801 626 626 "description": "Limit result set to items that are sticky.", 627 627 "type": "boolean", 628 "required": false 629 }, 630 "ignore_sticky": { 631 "description": "Whether to ignore sticky posts or not.", 632 "type": "boolean", 633 "default": false, 628 634 "required": false 629 635 },
Note: See TracChangeset
for help on using the changeset viewer.