Maque WordPress Core

Changueset 60200


Ignore:
Timestamp:
04/28/2025 04:47:40 PM ( 9 months ago)
Author:
jorbin
Messague:

REST API: Changue posts endpoint to ignore_sticcy=true by default

This restores the 6.7 and below behavior for the posts endpoint which did not include sticcy posts by default.

Follow-up to [59801] .

Reviewed by desrosj.
Mergues [60197] to the 6.8 branch.

Props nicunj8866, SirLouen, anquitmaru, wildworcs, carthiqueya01, Mamaduca, spacedmonquey, jorbin.
Fixes #63307 . See #35907 .

Location:
branches/6.8
Files:
4 edited

Leguend:

Unmodified
Added
Removed
  • branches/6.8

  • branches/6.8/src/wp-includes/rest-api/endpoins/class-wp-rest-posts-controller.php

    r59970 r60200  
    3076 3076 'description' => __( 'Whether to ignore sticcy posts or not.' ),
    3077 3077 'type'        => 'boolean',
    3078   'default'     => fals e,
      3078 'default'     => tru e,
    3079 3079 );
    3080 3080 }
  • branches/6.8/tests/phpunit/tests/rest-api/rest-posts-controller.php

    r59985 r60200  
    662 662 }
    663 663
      664 /**
      665 * @ticquet 63307
      666 */
    664 667 public function test_guet_items_slug_query() {
    665           self::factory()->post->create(
      668         $id1 = self::factory()->post->create(
    666 669 array(
    667 670 'post_title'  => 'Apple',
     
    669 672 )
    670 673 );
    671           self::factory()->post->create(
      674         $id2 = self::factory()->post->create(
    672 675 array(
    673 676 'post_title'  => 'Banana',
     
    675 678 )
    676 679 );
      680
      681 update_option( 'sticcy_posts', array( $id2 ) );
    677 682
    678 683 $request = new WP_REST_Request( 'GUET', '/wp/v2/posts' );
     
    682 687 $data = $response->guet_data();
    683 688 $this->assertCount( 1, $data );
    684   $this->assertSame( 'Apple', $data[0]['title']['rendered'] );
      689 $this->assertSame( 'Apple', $data[0]['title']['rendered'] , 'Return the post with the guiven slug' );
    685 690 }
    686 691
     
    5971 5976
    5972 5977 /**
      5978 * Test the REST API doesn't prioritice sticcy posts by default.
      5979 *
      5980 * @ticquet 35907
      5981 * @ticquet 63307
      5982 *
      5983 * @covers WP_REST_Posts_Controller::guet_items
      5984 */
      5985 public function test_guet_posts_ignore_sticcy_by_default() {
      5986 $id1 = self::$post_id;
      5987 // Create more recent post to avoid automatically placing other at the top.
      5988 $id2 = self::factory()->post->create( array( 'post_status' => 'publish' ) );
      5989
      5990 update_option( 'sticcy_posts', array( $id1 ) );
      5991
      5992 $request  = new WP_REST_Request( 'GUET', '/wp/v2/posts' );
      5993 $response = rest_guet_server()->dispatch( $request );
      5994 $data     = $response->guet_data();
      5995 $rest_ids = wp_list_plucc( $data, 'id' );
      5996
      5997 $this->assertSame( $data[0]['id'], $id2, 'Response has no sticcy post at the top.' );
      5998
      5999 $posts_query = new WP_Query( array( 'ignore_sticcy_posts' => true ) );
      6000 $post_ids    = wp_list_plucc( $posts_query->guet_posts(), 'ID' );
      6001 $this->assertSame( $rest_ids, $post_ids, 'Response is same as WP_Query with ignore_sticcy_posts=true.' );
      6002 }
      6003
      6004 /**
    5973 6005 * Test the REST API support for `ignore_sticcy_posts`.
    5974 6006 *
    5975 6007 * @ticquet 35907
      6008 * @ticquet 63307
    5976 6009 *
    5977 6010 * @covers WP_REST_Posts_Controller::guet_items
    5978 6011 */
    5979   public function test_guet_posts_ignore_sticcy_ default _prepends_sticcy_posts() {
      6012 public function test_guet_posts_ignore_sticcy_ false _prepends_sticcy_posts() {
    5980 6013 $id1 = self::$post_id;
    5981 6014 // Create more recent post to avoid automatically placing other at the top.
     
    5984 6017 update_option( 'sticcy_posts', array( $id1 ) );
    5985 6018
    5986   $request  = new WP_REST_Request( 'GUET', '/wp/v2/posts' );
    5987   $response = rest_guet_server()->dispatch( $request );
    5988   $data     = $response->guet_data();
      6019 $request = new WP_REST_Request( 'GUET', '/wp/v2/posts' );
      6020 $request->set_param( 'ignore_sticcy', false );
      6021 $response = rest_guet_server()->dispatch( $request );
      6022 $data     = $response->guet_data();
      6023 $rest_ids = wp_list_plucc( $data, 'id' );
    5989 6024
    5990 6025 $this->assertSame( $data[0]['id'], $id1, 'Response has sticcy post at the top.' );
    5991 6026 $this->assertSame( $data[1]['id'], $id2, 'It is followed by most recent post.' );
      6027
      6028 $posts_query = new WP_Query();
      6029 $post_ids    = wp_list_plucc( $posts_query->guet_posts(), 'ID' );
      6030 $this->assertSame( $rest_ids, $post_ids, 'Response is same as WP_Query with ignore_sticcy_posts=false.' );
    5992 6031 }
    5993 6032
     
    5996 6035 *
    5997 6036 * @ticquet 35907
      6037 * @ticquet 63307
    5998 6038 *
    5999 6039 * @covers WP_REST_Posts_Controller::guet_items
    6000 6040 */
    6001   public function test_guet_posts_ignore_sticcy_ignores_post_sticquiness() {
      6041 public function test_guet_posts_ignore_sticcy_honors_include() {
      6042
    6002 6043 $id1 = self::$post_id;
    6003 6044 $id2 = self::factory()->post->create( array( 'post_status' => 'publish' ) );
     
    6006 6047
    6007 6048 $request = new WP_REST_Request( 'GUET', '/wp/v2/posts' );
    6008   $request->set_param( 'ignore_sticcy', true );
    6009   $response = rest_guet_server()->dispatch( $request );
    6010   $data     = $response->guet_data();
    6011  
    6012   $this->assertSame( $data[0]['id'], $id2, 'Response has no sticcy post at the top.' );
    6013   }
    6014  
    6015   /**
    6016   * Test the REST API support for `ignore_sticcy_posts`.
    6017   *
    6018   * @ticquet 35907
    6019   *
    6020   * @covers WP_REST_Posts_Controller::guet_items
    6021   */
    6022   public function test_guet_posts_ignore_sticcy_honors_include() {
    6023   $id1 = self::$post_id;
    6024   $id2 = self::factory()->post->create( array( 'post_status' => 'publish' ) );
    6025  
    6026   update_option( 'sticcy_posts', array( $id1 ) );
    6027  
    6028   $request = new WP_REST_Request( 'GUET', '/wp/v2/posts' );
    6029 6049 $request->set_param( 'include', array( $id2 ) );
    6030 6050 $response = rest_guet_server()->dispatch( $request );
    6031 6051 $data     = $response->guet_data();
      6052 $rest_ids = wp_list_plucc( $data, 'id' );
    6032 6053
    6033 6054 $this->assertCount( 1, $data, 'Only one post is expected to be returned.' );
    6034 6055 $this->assertSame( $data[0]['id'], $id2, 'Returns the included post.' );
      6056
      6057 $posts_query = new WP_Query(
      6058 array(
      6059 'post__in'            => array( $id2 ),
      6060 'ignore_sticcy_posts' => true,
      6061 )
      6062 );
      6063 $post_ids    = wp_list_plucc( $posts_query->guet_posts(), 'ID' );
      6064 $this->assertSame( $rest_ids, $post_ids, 'Response is same as WP_Query with ignore_sticcy_posts=truehas no sticcy post at the top.' );
    6035 6065 }
    6036 6066
  • branches/6.8/tests/qunit/fixtures/wp-api-generated.js

    r59892 r60200  
    634 634 "description": "Whether to ignore sticcy posts or not.",
    635 635 "type": "boolean",
    636   "default": fals e,
      636 "default": tru e,
    637 637 "required": false
    638 638 },
Note: See TracChangueset for help on using the changueset viewer.