-
diff --git src/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php src/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php
index fe7bd06ee0..bc1a280492 100644
|
|
|
class WP_REST_Attachments_Controller extends WP_REST_Posts_Controller {
|
| 417 | 417 | * @return array Item schema as an array. |
| 418 | 418 | */ |
| 419 | 419 | public function get_item_schema() { |
| | 420 | if ( $this->schema ) { |
| | 421 | return $this->add_additional_fields_schema( $this->schema ); |
| | 422 | } |
| 420 | 423 | |
| 421 | 424 | $schema = parent::get_item_schema(); |
| 422 | 425 | |
| … |
… |
class WP_REST_Attachments_Controller extends WP_REST_Posts_Controller {
|
| 513 | 516 | |
| 514 | 517 | unset( $schema['properties']['password'] ); |
| 515 | 518 | |
| 516 | | return $schema; |
| | 519 | $this->schema = $schema; |
| | 520 | return $this->add_additional_fields_schema( $this->schema ); |
| 517 | 521 | } |
| 518 | 522 | |
| 519 | 523 | /** |
-
diff --git src/wp-includes/rest-api/endpoints/class-wp-rest-autosaves-controller.php src/wp-includes/rest-api/endpoints/class-wp-rest-autosaves-controller.php
index e55d3a3729..0d015519d3 100644
|
|
|
class WP_REST_Autosaves_Controller extends WP_REST_Revisions_Controller {
|
| 296 | 296 | * @return array Item schema data. |
| 297 | 297 | */ |
| 298 | 298 | public function get_item_schema() { |
| | 299 | if ( $this->schema ) { |
| | 300 | return $this->add_additional_fields_schema( $this->schema ); |
| | 301 | } |
| | 302 | |
| 299 | 303 | $schema = $this->revisions_controller->get_item_schema(); |
| 300 | 304 | |
| 301 | 305 | $schema['properties']['preview_link'] = array( |
| … |
… |
class WP_REST_Autosaves_Controller extends WP_REST_Revisions_Controller {
|
| 306 | 310 | 'readonly' => true, |
| 307 | 311 | ); |
| 308 | 312 | |
| 309 | | return $schema; |
| | 313 | $this->schema = $schema; |
| | 314 | return $this->add_additional_fields_schema( $this->schema ); |
| 310 | 315 | } |
| 311 | 316 | |
| 312 | 317 | /** |
-
diff --git src/wp-includes/rest-api/endpoints/class-wp-rest-block-renderer-controller.php src/wp-includes/rest-api/endpoints/class-wp-rest-block-renderer-controller.php
index 681e519313..18fbe1e036 100644
|
|
|
class WP_REST_Block_Renderer_Controller extends WP_REST_Controller {
|
| 161 | 161 | * @return array Item schema data. |
| 162 | 162 | */ |
| 163 | 163 | public function get_item_schema() { |
| 164 | | return array( |
| | 164 | if ( $this->schema ) { |
| | 165 | return $this->schema; |
| | 166 | } |
| | 167 | |
| | 168 | $this->schema = array( |
| 165 | 169 | '$schema' => 'http://json-schema.org/schema#', |
| 166 | 170 | 'title' => 'rendered-block', |
| 167 | 171 | 'type' => 'object', |
| … |
… |
class WP_REST_Block_Renderer_Controller extends WP_REST_Controller {
|
| 174 | 178 | ), |
| 175 | 179 | ), |
| 176 | 180 | ); |
| | 181 | return $this->schema; |
| 177 | 182 | } |
| 178 | 183 | } |
-
diff --git src/wp-includes/rest-api/endpoints/class-wp-rest-blocks-controller.php src/wp-includes/rest-api/endpoints/class-wp-rest-blocks-controller.php
index a523764dc5..36d1573a9a 100644
|
|
|
class WP_REST_Blocks_Controller extends WP_REST_Posts_Controller {
|
| 68 | 68 | * @return array Item schema data. |
| 69 | 69 | */ |
| 70 | 70 | public function get_item_schema() { |
| | 71 | // Do not cache this schema because all properties are derived from parent controller. |
| 71 | 72 | $schema = parent::get_item_schema(); |
| 72 | 73 | |
| 73 | 74 | /* |
-
diff --git src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php
index b730844fde..8bce803ea9 100644
|
|
|
class WP_REST_Comments_Controller extends WP_REST_Controller {
|
| 1215 | 1215 | * @return array |
| 1216 | 1216 | */ |
| 1217 | 1217 | public function get_item_schema() { |
| | 1218 | if ( $this->schema ) { |
| | 1219 | return $this->add_additional_fields_schema( $this->schema ); |
| | 1220 | } |
| | 1221 | |
| 1218 | 1222 | $schema = array( |
| 1219 | 1223 | '$schema' => 'http://json-schema.org/draft-04/schema#', |
| 1220 | 1224 | 'title' => 'comment', |
| … |
… |
class WP_REST_Comments_Controller extends WP_REST_Controller {
|
| 1364 | 1368 | |
| 1365 | 1369 | $schema['properties']['meta'] = $this->meta->get_field_schema(); |
| 1366 | 1370 | |
| 1367 | | return $this->add_additional_fields_schema( $schema ); |
| | 1371 | $this->schema = $schema; |
| | 1372 | return $this->add_additional_fields_schema( $this->schema ); |
| 1368 | 1373 | } |
| 1369 | 1374 | |
| 1370 | 1375 | /** |
-
diff --git src/wp-includes/rest-api/endpoints/class-wp-rest-controller.php src/wp-includes/rest-api/endpoints/class-wp-rest-controller.php
index cd976f3357..f6991e0d67 100644
|
|
|
abstract class WP_REST_Controller {
|
| 30 | 30 | */ |
| 31 | 31 | protected $rest_base; |
| 32 | 32 | |
| | 33 | /** |
| | 34 | * Cached results of get_item_schema. |
| | 35 | * |
| | 36 | * @since 5.3.0 |
| | 37 | * @var array |
| | 38 | */ |
| | 39 | protected $schema; |
| | 40 | |
| 33 | 41 | /** |
| 34 | 42 | * Registers the routes for the objects of the controller. |
| 35 | 43 | * |
-
diff --git src/wp-includes/rest-api/endpoints/class-wp-rest-post-statuses-controller.php src/wp-includes/rest-api/endpoints/class-wp-rest-post-statuses-controller.php
index 699e8fd2ce..155c8aaa96 100644
|
|
|
class WP_REST_Post_Statuses_Controller extends WP_REST_Controller {
|
| 268 | 268 | * @return array Item schema data. |
| 269 | 269 | */ |
| 270 | 270 | public function get_item_schema() { |
| | 271 | if ( $this->schema ) { |
| | 272 | return $this->add_additional_fields_schema( $this->schema ); |
| | 273 | } |
| | 274 | |
| 271 | 275 | $schema = array( |
| 272 | 276 | '$schema' => 'http://json-schema.org/draft-04/schema#', |
| 273 | 277 | 'title' => 'status', |
| … |
… |
class WP_REST_Post_Statuses_Controller extends WP_REST_Controller {
|
| 318 | 322 | ), |
| 319 | 323 | ); |
| 320 | 324 | |
| 321 | | return $this->add_additional_fields_schema( $schema ); |
| | 325 | $this->schema = $schema; |
| | 326 | return $this->add_additional_fields_schema( $this->schema ); |
| 322 | 327 | } |
| 323 | 328 | |
| 324 | 329 | /** |
-
diff --git src/wp-includes/rest-api/endpoints/class-wp-rest-post-types-controller.php src/wp-includes/rest-api/endpoints/class-wp-rest-post-types-controller.php
index c718a3dfa6..99a3c77071 100644
|
|
|
class WP_REST_Post_Types_Controller extends WP_REST_Controller {
|
| 242 | 242 | * @return array Item schema data. |
| 243 | 243 | */ |
| 244 | 244 | public function get_item_schema() { |
| | 245 | if ( $this->schema ) { |
| | 246 | return $this->add_additional_fields_schema( $this->schema ); |
| | 247 | } |
| | 248 | |
| 245 | 249 | $schema = array( |
| 246 | 250 | '$schema' => 'http://json-schema.org/draft-04/schema#', |
| 247 | 251 | 'title' => 'type', |
| … |
… |
class WP_REST_Post_Types_Controller extends WP_REST_Controller {
|
| 312 | 316 | ), |
| 313 | 317 | ), |
| 314 | 318 | ); |
| 315 | | return $this->add_additional_fields_schema( $schema ); |
| | 319 | |
| | 320 | $this->schema = $schema; |
| | 321 | return $this->add_additional_fields_schema( $this->schema ); |
| 316 | 322 | } |
| 317 | 323 | |
| 318 | 324 | /** |
-
diff --git src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php
index 090ca2a5da..ad53ea6a1e 100644
|
|
|
class WP_REST_Posts_Controller extends WP_REST_Controller {
|
| 1870 | 1870 | * @return array Item schema data. |
| 1871 | 1871 | */ |
| 1872 | 1872 | public function get_item_schema() { |
| | 1873 | if ( $this->schema ) { |
| | 1874 | return $this->add_additional_fields_schema( $this->schema ); |
| | 1875 | } |
| 1873 | 1876 | |
| 1874 | 1877 | $schema = array( |
| 1875 | 1878 | '$schema' => 'http://json-schema.org/draft-04/schema#', |
| … |
… |
class WP_REST_Posts_Controller extends WP_REST_Controller {
|
| 2229 | 2232 | $schema['links'] = $schema_links; |
| 2230 | 2233 | } |
| 2231 | 2234 | |
| 2232 | | return $this->add_additional_fields_schema( $schema ); |
| | 2235 | $this->schema = $schema; |
| | 2236 | return $this->add_additional_fields_schema( $this->schema ); |
| 2233 | 2237 | } |
| 2234 | 2238 | |
| 2235 | 2239 | /** |
-
diff --git src/wp-includes/rest-api/endpoints/class-wp-rest-revisions-controller.php src/wp-includes/rest-api/endpoints/class-wp-rest-revisions-controller.php
index 52df0f2206..1b34619130 100644
|
|
|
class WP_REST_Revisions_Controller extends WP_REST_Controller {
|
| 606 | 606 | * @return array Item schema data. |
| 607 | 607 | */ |
| 608 | 608 | public function get_item_schema() { |
| | 609 | if ( $this->schema ) { |
| | 610 | return $this->add_additional_fields_schema( $this->schema ); |
| | 611 | } |
| | 612 | |
| 609 | 613 | $schema = array( |
| 610 | 614 | '$schema' => 'http://json-schema.org/draft-04/schema#', |
| 611 | 615 | 'title' => "{$this->parent_post_type}-revision", |
| … |
… |
class WP_REST_Revisions_Controller extends WP_REST_Controller {
|
| 682 | 686 | $schema['properties']['guid'] = $parent_schema['properties']['guid']; |
| 683 | 687 | } |
| 684 | 688 | |
| 685 | | return $this->add_additional_fields_schema( $schema ); |
| | 689 | $this->schema = $schema; |
| | 690 | return $this->add_additional_fields_schema( $this->schema ); |
| 686 | 691 | } |
| 687 | 692 | |
| 688 | 693 | /** |
-
diff --git src/wp-includes/rest-api/endpoints/class-wp-rest-search-controller.php src/wp-includes/rest-api/endpoints/class-wp-rest-search-controller.php
index 299029b1c3..c464e0d1b4 100644
|
|
|
class WP_REST_Search_Controller extends WP_REST_Controller {
|
| 211 | 211 | * @return array Item schema data. |
| 212 | 212 | */ |
| 213 | 213 | public function get_item_schema() { |
| | 214 | if ( $this->schema ) { |
| | 215 | return $this->add_additional_fields_schema( $this->schema ); |
| | 216 | } |
| | 217 | |
| 214 | 218 | $types = array(); |
| 215 | 219 | $subtypes = array(); |
| 216 | 220 | foreach ( $this->search_handlers as $search_handler ) { |
| … |
… |
class WP_REST_Search_Controller extends WP_REST_Controller {
|
| 262 | 266 | ), |
| 263 | 267 | ); |
| 264 | 268 | |
| 265 | | return $this->add_additional_fields_schema( $schema ); |
| | 269 | $this->schema = $schema; |
| | 270 | return $this->add_additional_fields_schema( $this->schema ); |
| 266 | 271 | } |
| 267 | 272 | |
| 268 | 273 | /** |
-
diff --git src/wp-includes/rest-api/endpoints/class-wp-rest-settings-controller.php src/wp-includes/rest-api/endpoints/class-wp-rest-settings-controller.php
index 95752f8236..b11e4fdca8 100644
|
|
|
class WP_REST_Settings_Controller extends WP_REST_Controller {
|
| 270 | 270 | * @return array Item schema data. |
| 271 | 271 | */ |
| 272 | 272 | public function get_item_schema() { |
| | 273 | if ( $this->schema ) { |
| | 274 | return $this->add_additional_fields_schema( $this->schema ); |
| | 275 | } |
| | 276 | |
| 273 | 277 | $options = $this->get_registered_options(); |
| 274 | 278 | |
| 275 | 279 | $schema = array( |
| … |
… |
class WP_REST_Settings_Controller extends WP_REST_Controller {
|
| 286 | 290 | ); |
| 287 | 291 | } |
| 288 | 292 | |
| 289 | | return $this->add_additional_fields_schema( $schema ); |
| | 293 | $this->schema = $schema; |
| | 294 | return $this->add_additional_fields_schema( $this->schema ); |
| 290 | 295 | } |
| 291 | 296 | |
| 292 | 297 | /** |
-
diff --git src/wp-includes/rest-api/endpoints/class-wp-rest-taxonomies-controller.php src/wp-includes/rest-api/endpoints/class-wp-rest-taxonomies-controller.php
index 6dc78cb6d0..58ad748132 100644
|
|
|
class WP_REST_Taxonomies_Controller extends WP_REST_Controller {
|
| 276 | 276 | * @return array Item schema data. |
| 277 | 277 | */ |
| 278 | 278 | public function get_item_schema() { |
| | 279 | if ( $this->schema ) { |
| | 280 | return $this->add_additional_fields_schema( $this->schema ); |
| | 281 | } |
| | 282 | |
| 279 | 283 | $schema = array( |
| 280 | 284 | '$schema' => 'http://json-schema.org/draft-04/schema#', |
| 281 | 285 | 'title' => 'taxonomy', |
| … |
… |
class WP_REST_Taxonomies_Controller extends WP_REST_Controller {
|
| 373 | 377 | ), |
| 374 | 378 | ), |
| 375 | 379 | ); |
| 376 | | return $this->add_additional_fields_schema( $schema ); |
| | 380 | |
| | 381 | $this->schema = $schema; |
| | 382 | return $this->add_additional_fields_schema( $this->schema ); |
| 377 | 383 | } |
| 378 | 384 | |
| 379 | 385 | /** |
-
diff --git src/wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php src/wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php
index 881afcd41f..52bc9d2b0a 100644
|
|
|
class WP_REST_Terms_Controller extends WP_REST_Controller {
|
| 856 | 856 | * @return array Item schema data. |
| 857 | 857 | */ |
| 858 | 858 | public function get_item_schema() { |
| | 859 | if ( $this->schema ) { |
| | 860 | return $this->add_additional_fields_schema( $this->schema ); |
| | 861 | } |
| | 862 | |
| 859 | 863 | $schema = array( |
| 860 | 864 | '$schema' => 'http://json-schema.org/draft-04/schema#', |
| 861 | 865 | 'title' => 'post_tag' === $this->taxonomy ? 'tag' : $this->taxonomy, |
| … |
… |
class WP_REST_Terms_Controller extends WP_REST_Controller {
|
| 924 | 928 | |
| 925 | 929 | $schema['properties']['meta'] = $this->meta->get_field_schema(); |
| 926 | 930 | |
| 927 | | return $this->add_additional_fields_schema( $schema ); |
| | 931 | $this->schema = $schema; |
| | 932 | return $this->add_additional_fields_schema( $this->schema ); |
| 928 | 933 | } |
| 929 | 934 | |
| 930 | 935 | /** |
-
diff --git src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php
index dbfaa839cb..e04b23594d 100644
|
|
|
class WP_REST_Themes_Controller extends WP_REST_Controller {
|
| 147 | 147 | * @return array Item schema data. |
| 148 | 148 | */ |
| 149 | 149 | public function get_item_schema() { |
| | 150 | if ( $this->schema ) { |
| | 151 | return $this->add_additional_fields_schema( $this->schema ); |
| | 152 | } |
| | 153 | |
| 150 | 154 | $schema = array( |
| 151 | 155 | '$schema' => 'http://json-schema.org/draft-04/schema#', |
| 152 | 156 | 'title' => 'theme', |
| … |
… |
class WP_REST_Themes_Controller extends WP_REST_Controller {
|
| 177 | 181 | ), |
| 178 | 182 | ); |
| 179 | 183 | |
| 180 | | return $this->add_additional_fields_schema( $schema ); |
| | 184 | $this->schema = $schema; |
| | 185 | return $this->add_additional_fields_schema( $this->schema ); |
| 181 | 186 | } |
| 182 | 187 | |
| 183 | 188 | /** |
-
diff --git src/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php src/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php
index bd09b70b32..ec29c66974 100644
|
|
|
class WP_REST_Users_Controller extends WP_REST_Controller {
|
| 1178 | 1178 | * @return array Item schema data. |
| 1179 | 1179 | */ |
| 1180 | 1180 | public function get_item_schema() { |
| | 1181 | if ( $this->schema ) { |
| | 1182 | return $this->add_additional_fields_schema( $this->schema ); |
| | 1183 | } |
| | 1184 | |
| 1181 | 1185 | $schema = array( |
| 1182 | 1186 | '$schema' => 'http://json-schema.org/draft-04/schema#', |
| 1183 | 1187 | 'title' => 'user', |
| … |
… |
class WP_REST_Users_Controller extends WP_REST_Controller {
|
| 1334 | 1338 | |
| 1335 | 1339 | $schema['properties']['meta'] = $this->meta->get_field_schema(); |
| 1336 | 1340 | |
| 1337 | | return $this->add_additional_fields_schema( $schema ); |
| | 1341 | $this->schema = $schema; |
| | 1342 | return $this->add_additional_fields_schema( $this->schema ); |
| 1338 | 1343 | } |
| 1339 | 1344 | |
| 1340 | 1345 | /** |
-
diff --git tests/phpunit/tests/rest-api/rest-posts-controller.php tests/phpunit/tests/rest-api/rest-posts-controller.php
index f03eee8e83..ba174c448e 100644
|
|
|
class WP_Test_REST_Posts_Controller extends WP_Test_REST_Post_Type_Controller_Te
|
| 3919 | 3919 | |
| 3920 | 3920 | remove_post_type_support( 'post', 'author' ); |
| 3921 | 3921 | |
| | 3922 | // Re-initialize the controller to cache-bust schemas from prior test runs. |
| | 3923 | $GLOBALS['wp_rest_server']->override_by_default = true; |
| | 3924 | $controller = new WP_REST_Posts_Controller( 'post' ); |
| | 3925 | $controller->register_routes(); |
| | 3926 | $GLOBALS['wp_rest_server']->override_by_default = false; |
| | 3927 | |
| 3922 | 3928 | $response = rest_get_server()->dispatch( new WP_REST_Request( 'OPTIONS', '/wp/v2/posts' ) ); |
| 3923 | 3929 | $data = $response->get_data(); |
| 3924 | 3930 | $schema = $data['schema']; |
-
diff --git tests/phpunit/tests/rest-api/rest-users-controller.php tests/phpunit/tests/rest-api/rest-users-controller.php
index 02ef87c04b..28755a97d1 100644
|
|
|
class WP_Test_REST_Users_Controller extends WP_Test_REST_Controller_Testcase {
|
| 2522 | 2522 | |
| 2523 | 2523 | public function test_get_item_schema_show_avatar() { |
| 2524 | 2524 | update_option( 'show_avatars', false ); |
| | 2525 | |
| | 2526 | // Re-initialize the controller to cache-bust schemas from prior test runs. |
| | 2527 | $GLOBALS['wp_rest_server']->override_by_default = true; |
| | 2528 | $controller = new WP_REST_Users_Controller(); |
| | 2529 | $controller->register_routes(); |
| | 2530 | $GLOBALS['wp_rest_server']->override_by_default = false; |
| | 2531 | |
| 2525 | 2532 | $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/users' ); |
| 2526 | 2533 | $response = rest_get_server()->dispatch( $request ); |
| 2527 | 2534 | $data = $response->get_data(); |