Changeset 65918
- Timestamp:
- 12/04/2026 01:07:58 PM (5 hours ago)
- Location:
- trunk
- Files:
-
- 4 edited
-
src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php (modified) (2 diffs)
-
tests/phpunit/tests/rest-api/rest-pages-controller.php (modified) (1 diff)
-
tests/phpunit/tests/rest-api/rest-posts-controller.php (modified) (2 diffs)
-
tests/qunit/fixtures/wp-api-generated.js (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php
r65581 r65918 3017 3017 * @since 5.4.0 The `tax_relation` query parameter was added. 3018 3018 * @since 5.7.0 The `modified_after` and `modified_before` query parameters were added. 3019 * @since 7.3.0 The `excerpt_length` query parameter was added. 3019 3020 * 3020 3021 * @return array Collection parameters. … … 3207 3208 'type' => 'string', 3208 3209 ), 3210 ); 3211 } 3212 3213 $schema = $this->get_item_schema(); 3214 if ( isset( $schema['properties']['excerpt'] ) ) { 3215 $query_params['excerpt_length'] = array( 3216 'description' => __( 'Override the default excerpt length.' ), 3217 'type' => 'integer', 3209 3218 ); 3210 3219 } -
trunk/tests/phpunit/tests/rest-api/rest-pages-controller.php
r64596 r65918 79 79 'before', 80 80 'context', 81 'excerpt_length', 81 82 'exclude', 82 83 'include', -
trunk/tests/phpunit/tests/rest-api/rest-posts-controller.php
r65757 r65918 201 201 'categories_exclude', 202 202 'context', 203 'excerpt_length', 203 204 'exclude', 204 205 'format', … … 2750 2751 ); 2751 2752 $this->assertSame( 0, $filter_count ); 2753 } 2754 2755 /** 2756 * @ticket 66940 2757 * 2758 * @covers WP_REST_Posts_Controller::get_items 2759 */ 2760 public function test_get_items_override_excerpt_length() { 2761 $post_id = self::factory()->post->create( 2762 array( 2763 'post_excerpt' => '', 2764 'post_content' => implode( ' ', array_fill( 0, 60, 'word' ) ), 2765 ) 2766 ); 2767 2768 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); 2769 $request->set_param( 'include', array( $post_id ) ); 2770 $request->set_param( 'excerpt_length', 10 ); 2771 $response = rest_get_server()->dispatch( $request ); 2772 $data = $response->get_data(); 2773 2774 $this->assertSame( 200, $response->get_status(), 'The request should succeed.' ); 2775 $this->assertCount( 1, $data, 'Exactly one post should be returned.' ); 2776 2777 // 10 words plus the ellipsis added via the 'excerpt_more' filter. 2778 $this->assertCount( 2779 11, 2780 explode( ' ', trim( wp_strip_all_tags( $data[0]['excerpt']['rendered'] ) ) ), 2781 'Expected the excerpt to contain 11 words (10 words plus an ellipsis).' 2782 ); 2783 } 2784 2785 /** 2786 * @ticket 66940 2787 * 2788 * @covers WP_REST_Posts_Controller::get_items 2789 */ 2790 public function test_get_items_invalid_excerpt_length() { 2791 $request = new WP_REST_Request( 'GET', '/wp/v2/posts' ); 2792 $request->set_param( 'excerpt_length', 'abc' ); 2793 $response = rest_get_server()->dispatch( $request ); 2794 2795 $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); 2752 2796 } 2753 2797 -
trunk/tests/qunit/fixtures/wp-api-generated.js
r65828 r65918 658 658 }, 659 659 "required": false 660 }, 661 "excerpt_length": { 662 "description": "Override the default excerpt length.", 663 "type": "integer", 664 "required": false 660 665 } 661 666 } … … 1863 1868 "type": "string" 1864 1869 }, 1870 "required": false 1871 }, 1872 "excerpt_length": { 1873 "description": "Override the default excerpt length.", 1874 "type": "integer", 1865 1875 "required": false 1866 1876 } … … 4890 4900 ], 4891 4901 "required": false 4902 }, 4903 "excerpt_length": { 4904 "description": "Override the default excerpt length.", 4905 "type": "integer", 4906 "required": false 4892 4907 } 4893 4908 }
Note:
See TracChangeset
for help on using the changeset viewer.