Changeset 57628
- Timestamp:
- 02/13/2024 03:10:37 PM (6 months ago)
- Location:
- trunk
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-wp-post-type.php
r57624 r57628 914 914 * 915 915 * @since 6.4.0 916 * @since 6.5.0 Prevents autosave class instantiation for wp_global_styles post types.917 916 * 918 917 * @return WP_REST_Controller|null The controller instance, or null if the post type … … 924 923 } 925 924 926 if ( in_array( $this->name, array( 'attachment', 'wp_global_styles' ), true )) {925 if ( ) { 927 926 return null; 928 927 } -
trunk/src/wp-includes/post.php
r57624 r57628 474 474 'wp_global_styles', 475 475 array( 476 'label' => _x( 'Global Styles', 'post type general name' ), 477 'description' => __( 'Global styles to include in themes.' ), 478 'public' => false, 479 '_builtin' => true, /* internal use only. don't use this when registering your own post type. */ 480 '_edit_link' => '/site-editor.php?canvas=edit', /* internal use only. don't use this when registering your own post type. */ 481 'show_ui' => false, 482 'show_in_rest' => true, 483 'rewrite' => false, 484 'rest_base' => 'global-styles', 485 'rest_controller_class' => 'WP_REST_Global_Styles_Controller', 486 'revisions_rest_controller_class' => 'WP_REST_Global_Styles_Revisions_Controller', 487 'late_route_registration' => true, 488 'capabilities' => array( 476 'label' => _x( 'Global Styles', 'post type general name' ), 477 'description' => __( 'Global styles to include in themes.' ), 478 'public' => false, 479 '_builtin' => true, /* internal use only. don't use this when registering your own post type. */ 480 '_edit_link' => '/site-editor.php?canvas=edit', /* internal use only. don't use this when registering your own post type. */ 481 'show_ui' => false, 482 'show_in_rest' => false, 483 'rewrite' => false, 484 'capabilities' => array( 489 485 'read' => 'edit_theme_options', 490 486 'create_posts' => 'edit_theme_options', … … 495 491 'delete_others_posts' => 'edit_theme_options', 496 492 ), 497 'map_meta_cap' 498 'supports' 493 'map_meta_cap' => true, 494 'supports' => array( 499 495 'title', 500 496 'editor', -
trunk/src/wp-includes/rest-api.php
r57624 r57628 322 322 // Block Types. 323 323 $controller = new WP_REST_Block_Types_Controller(); 324 325 326 327 328 329 330 331 324 332 $controller->register_routes(); 325 333 -
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-global-styles-controller.php
r57624 r57628 11 11 * Base Global Styles REST API Controller. 12 12 */ 13 class WP_REST_Global_Styles_Controller extends WP_REST_Posts_Controller { 14 /** 15 * Whether the controller supports batching. 16 * 17 * @since 6.5.0 18 * @var array 19 */ 20 protected $allow_batch = array( 'v1' => false ); 13 class WP_REST_Global_Styles_Controller extends WP_REST_Controller { 14 15 /** 16 * Post type. 17 * 18 * @since 5.9.0 19 * @var string 20 */ 21 protected $post_type; 22 23 /** 24 * Constructor. 25 * @since 5.9.0 26 */ 27 public function __construct() { 28 $this->namespace = 'wp/v2'; 29 $this->rest_base = 'global-styles'; 30 $this->post_type = 'wp_global_styles'; 31 } 21 32 22 33 /** … … 184 195 * @return bool Whether the post can be read. 185 196 */ 186 p ublicfunction check_read_permission( $post ) {197 p function check_read_permission( $post ) { 187 198 return current_user_can( 'read_post', $post->ID ); 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 188 217 } 189 218 … … 211 240 212 241 return true; 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 213 291 } 214 292 … … 330 408 $response->add_links( $links ); 331 409 if ( ! empty( $links['self']['href'] ) ) { 332 $actions = $this->get_available_actions( $post, $request);410 $actions = $this->get_available_actions(); 333 411 $self = $links['self']['href']; 334 412 foreach ( $actions as $rel ) { … … 354 432 355 433 $links = array( 356 'self' 434 'self' => array( 357 435 'href' => rest_url( trailingslashit( $base ) . $id ), 358 ),359 'about' => array(360 'href' => rest_url( 'wp/v2/types/' . $this->post_type ),361 436 ), 362 437 ); … … 380 455 * @since 5.9.0 381 456 * @since 6.2.0 Added 'edit-css' action. 382 * @since 6.5.0 Added $post and $request parameters. 383 * 384 * @param WP_Post $post Post object. 385 * @param WP_REST_Request $request Request object. 457 * 386 458 * @return array List of link relations. 387 459 */ 388 protected function get_available_actions( $post, $request) {460 protected function get_available_actions() { 389 461 $rels = array(); 390 462 391 $post_type = get_post_type_object( $ post->post_type );463 $post_type = get_post_type_object( $->post_type ); 392 464 if ( current_user_can( $post_type->cap->publish_posts ) ) { 393 465 $rels[] = 'https://api.w.org/action-publish'; … … 399 471 400 472 return $rels; 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 401 488 } 402 489 -
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-global-styles-revisions-controller.php
r57624 r57628 15 15 * @see WP_REST_Controller 16 16 */ 17 class WP_REST_Global_Styles_Revisions_Controller extends WP_REST_ Revisions_Controller {18 /** 19 * Parent controller.20 * 21 * @since 6. 5.022 * @var WP_REST_Controller23 */ 24 pr ivate $parent_controller;17 class WP_REST_Global_Styles_Revisions_Controller extends WP_REST_Controller { 18 /** 19 * Parent . 20 * 21 * @since 6..0 22 * @var 23 */ 24 pr; 25 25 26 26 /** … … 36 36 * 37 37 * @since 6.3.0 38 * @since 6.5.0 Extends class from WP_REST_Revisions_Controller. 39 * 40 * @param string $parent_post_type Post type of the parent. 41 */ 42 public function __construct( $parent_post_type ) { 43 parent::__construct( $parent_post_type ); 44 $post_type_object = get_post_type_object( $parent_post_type ); 45 $parent_controller = $post_type_object->get_rest_controller(); 46 47 if ( ! $parent_controller ) { 48 $parent_controller = new WP_REST_Global_Styles_Controller( $parent_post_type ); 49 } 50 51 $this->parent_controller = $parent_controller; 52 $this->rest_base = 'revisions'; 53 $this->parent_base = ! empty( $post_type_object->rest_base ) ? $post_type_object->rest_base : $post_type_object->name; 54 $this->namespace = ! empty( $post_type_object->rest_namespace ) ? $post_type_object->rest_namespace : 'wp/v2'; 38 */ 39 public function __construct() { 40 $this->parent_post_type = 'wp_global_styles'; 41 $this->rest_base = 'revisions'; 42 $this->parent_base = 'global-styles'; 43 $this->namespace = 'wp/v2'; 55 44 } 56 45 … … 75 64 'methods' => WP_REST_Server::READABLE, 76 65 'callback' => array( $this, 'get_items' ), 77 'permission_callback' => array( $this, 'get_item s_permissions_check' ),66 'permission_callback' => array( $this, 'get_item_permissions_check' ), 78 67 'args' => $this->get_collection_params(), 79 68 ), … … 107 96 ) 108 97 ); 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 109 121 } 110 122 … … 258 270 259 271 /** 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 260 346 * Prepares the revision for the REST response. 261 347 * … … 326 412 * 327 413 * @since 6.3.0 328 * @since 6.5.0 Merged parent and parent controller schema data.329 414 * 330 415 * @return array Item schema data. … … 335 420 } 336 421 337 $schema = parent::get_item_schema(); 338 $parent_schema = $this->parent_controller->get_item_schema(); 339 $schema['properties'] = array_merge( $schema['properties'], $parent_schema['properties'] ); 340 341 unset( $schema['properties']['guid'] ); 342 unset( $schema['properties']['slug'] ); 343 unset( $schema['properties']['meta'] ); 344 unset( $schema['properties']['content'] ); 345 unset( $schema['properties']['title'] ); 422 $schema = array( 423 '$schema' => 'http://json-schema.org/draft-04/schema#', 424 'title' => "{$this->parent_post_type}-revision", 425 'type' => 'object', 426 // Base properties for every revision. 427 'properties' => array( 428 429 /* 430 * Adds settings and styles from the WP_REST_Revisions_Controller item fields. 431 * Leaves out GUID as global styles shouldn't be accessible via URL. 432 */ 433 'author' => array( 434 'description' => __( 'The ID for the author of the revision.' ), 435 'type' => 'integer', 436 'context' => array( 'view', 'edit', 'embed' ), 437 ), 438 'date' => array( 439 'description' => __( "The date the revision was published, in the site's timezone." ), 440 'type' => 'string', 441 'format' => 'date-time', 442 'context' => array( 'view', 'edit', 'embed' ), 443 ), 444 'date_gmt' => array( 445 'description' => __( 'The date the revision was published, as GMT.' ), 446 'type' => 'string', 447 'format' => 'date-time', 448 'context' => array( 'view', 'edit' ), 449 ), 450 'id' => array( 451 'description' => __( 'Unique identifier for the revision.' ), 452 'type' => 'integer', 453 'context' => array( 'view', 'edit', 'embed' ), 454 ), 455 'modified' => array( 456 'description' => __( "The date the revision was last modified, in the site's timezone." ), 457 'type' => 'string', 458 'format' => 'date-time', 459 'context' => array( 'view', 'edit' ), 460 ), 461 'modified_gmt' => array( 462 'description' => __( 'The date the revision was last modified, as GMT.' ), 463 'type' => 'string', 464 'format' => 'date-time', 465 'context' => array( 'view', 'edit' ), 466 ), 467 'parent' => array( 468 'description' => __( 'The ID for the parent of the revision.' ), 469 'type' => 'integer', 470 'context' => array( 'view', 'edit', 'embed' ), 471 ), 472 473 // Adds settings and styles from the WP_REST_Global_Styles_Controller parent schema. 474 'styles' => array( 475 'description' => __( 'Global styles.' ), 476 'type' => array( 'object' ), 477 'context' => array( 'view', 'edit' ), 478 ), 479 'settings' => array( 480 'description' => __( 'Global settings.' ), 481 'type' => array( 'object' ), 482 'context' => array( 'view', 'edit' ), 483 ), 484 ), 485 ); 346 486 347 487 $this->schema = $schema; … … 351 491 352 492 /** 353 * Retrieves the query params for collections. 354 * Removes params that are not supported by global styles revisions. 355 * 356 * @since 6.5.0 357 * 358 * @return array Collection parameters. 359 */ 360 public function get_collection_params() { 361 $query_params = parent::get_collection_params(); 362 unset( $query_params['exclude'] ); 363 unset( $query_params['include'] ); 364 unset( $query_params['search'] ); 365 unset( $query_params['order'] ); 366 unset( $query_params['orderby'] ); 367 return $query_params; 493 * Checks if a given request has access to read a single global style. 494 * 495 * @since 6.3.0 496 * 497 * @param WP_REST_Request $request Full details about the request. 498 * @return true|WP_Error True if the request has read access, WP_Error object otherwise. 499 */ 500 public function get_item_permissions_check( $request ) { 501 $post = $this->get_parent( $request['parent'] ); 502 if ( is_wp_error( $post ) ) { 503 return $post; 504 } 505 506 /* 507 * The same check as WP_REST_Global_Styles_Controller::get_item_permissions_check. 508 */ 509 if ( ! current_user_can( 'read_post', $post->ID ) ) { 510 return new WP_Error( 511 'rest_cannot_view', 512 __( 'Sorry, you are not allowed to view revisions for this global style.' ), 513 array( 'status' => rest_authorization_required_code() ) 514 ); 515 } 516 517 return true; 518 } 519 520 /** 521 * Gets the parent post, if the ID is valid. 522 * 523 * Duplicate of WP_REST_Revisions_Controller::get_parent. 524 * 525 * @since 6.3.0 526 * 527 * @param int $parent_post_id Supplied ID. 528 * @return WP_Post|WP_Error Post object if ID is valid, WP_Error otherwise. 529 */ 530 protected function get_parent( $parent_post_id ) { 531 $error = new WP_Error( 532 'rest_post_invalid_parent', 533 __( 'Invalid post parent ID.' ), 534 array( 'status' => 404 ) 535 ); 536 537 if ( (int) $parent_post_id <= 0 ) { 538 return $error; 539 } 540 541 $parent_post = get_post( (int) $parent_post_id ); 542 543 if ( empty( $parent_post ) || empty( $parent_post->ID ) 544 || $this->parent_post_type !== $parent_post->post_type 545 ) { 546 return $error; 547 } 548 549 return $parent_post; 368 550 } 369 551 } -
trunk/src/wp-settings.php
r57624 r57628 277 277 require ABSPATH . WPINC . '/rest-api/endpoints/class-wp-rest-attachments-controller.php'; 278 278 require ABSPATH . WPINC . '/rest-api/endpoints/class-wp-rest-global-styles-controller.php'; 279 279 280 require ABSPATH . WPINC . '/rest-api/endpoints/class-wp-rest-post-types-controller.php'; 280 281 require ABSPATH . WPINC . '/rest-api/endpoints/class-wp-rest-post-statuses-controller.php'; 281 282 require ABSPATH . WPINC . '/rest-api/endpoints/class-wp-rest-revisions-controller.php'; 282 require ABSPATH . WPINC . '/rest-api/endpoints/class-wp-rest-global-styles-revisions-controller.php';283 283 require ABSPATH . WPINC . '/rest-api/endpoints/class-wp-rest-template-revisions-controller.php'; 284 284 require ABSPATH . WPINC . '/rest-api/endpoints/class-wp-rest-autosaves-controller.php'; -
trunk/tests/phpunit/tests/rest-api/rest-global-styles-revisions-controller.php
r57624 r57628 421 421 /** 422 422 * @ticket 58524 423 * @ticket 60131424 423 * 425 424 * @covers WP_REST_Global_Styles_Controller::get_item_permissions_check … … 430 429 $response = rest_get_server()->dispatch( $request ); 431 430 432 $this->assertErrorResponse( 'rest_cannot_ read', $response, 403 );431 $this->assertErrorResponse( 'rest_cannot_', $response, 403 ); 433 432 } 434 433 … … 831 830 */ 832 831 public function test_context_param() { 833 // Controller does not implement get_context_param().832 // Controller does not implement t_context_param(). 834 833 } 835 834 -
trunk/tests/qunit/fixtures/wp-api-generated.js
r57624 r57628 5806 5806 "default": false, 5807 5807 "description": "Whether to bypass Trash and force deletion.", 5808 "required": false5809 }5810 }5811 }5812 ]5813 },5814 "/wp/v2/global-styles/(?P<parent>[\\d]+)/revisions": {5815 "namespace": "wp/v2",5816 "methods": [5817 "GET"5818 ],5819 "endpoints": [5820 {5821 "methods": [5822 "GET"5823 ],5824 "args": {5825 "parent": {5826 "description": "The ID for the parent of the revision.",5827 "type": "integer",5828 "required": false5829 },5830 "context": {5831 "description": "Scope under which the request is made; determines fields present in response.",5832 "type": "string",5833 "enum": [5834 "view",5835 "embed",5836 "edit"5837 ],5838 "default": "view",5839 "required": false5840 },5841 "page": {5842 "description": "Current page of the collection.",5843 "type": "integer",5844 "default": 1,5845 "minimum": 1,5846 "required": false5847 },5848 "per_page": {5849 "description": "Maximum number of items to be returned in result set.",5850 "type": "integer",5851 "minimum": 1,5852 "maximum": 100,5853 "required": false5854 },5855 "offset": {5856 "description": "Offset the result set by a specific number of items.",5857 "type": "integer",5858 "required": false5859 }5860 }5861 }5862 ]5863 },5864 "/wp/v2/global-styles/(?P<parent>[\\d]+)/revisions/(?P<id>[\\d]+)": {5865 "namespace": "wp/v2",5866 "methods": [5867 "GET"5868 ],5869 "endpoints": [5870 {5871 "methods": [5872 "GET"5873 ],5874 "args": {5875 "parent": {5876 "description": "The ID for the parent of the global styles revision.",5877 "type": "integer",5878 "required": false5879 },5880 "id": {5881 "description": "Unique identifier for the global styles revision.",5882 "type": "integer",5883 "required": false5884 },5885 "context": {5886 "description": "Scope under which the request is made; determines fields present in response.",5887 "type": "string",5888 "enum": [5889 "view",5890 "embed",5891 "edit"5892 ],5893 "default": "view",5894 "required": false5895 }5896 }5897 }5898 ]5899 },5900 "/wp/v2/global-styles/themes/(?P<stylesheet>[\\/\\s%\\w\\.\\(\\)\\[\\]\\@_\\-]+)/variations": {5901 "namespace": "wp/v2",5902 "methods": [5903 "GET"5904 ],5905 "endpoints": [5906 {5907 "methods": [5908 "GET"5909 ],5910 "args": {5911 "stylesheet": {5912 "description": "The theme identifier",5913 "type": "string",5914 "required": false5915 }5916 }5917 }5918 ]5919 },5920 "/wp/v2/global-styles/themes/(?P<stylesheet>[^\\/:<>\\*\\?\"\\|]+(?:\\/[^\\/:<>\\*\\?\"\\|]+)?)": {5921 "namespace": "wp/v2",5922 "methods": [5923 "GET"5924 ],5925 "endpoints": [5926 {5927 "methods": [5928 "GET"5929 ],5930 "args": {5931 "stylesheet": {5932 "description": "The theme identifier",5933 "type": "string",5934 "required": false5935 }5936 }5937 }5938 ]5939 },5940 "/wp/v2/global-styles/(?P<id>[\\/\\w-]+)": {5941 "namespace": "wp/v2",5942 "methods": [5943 "GET",5944 "POST",5945 "PUT",5946 "PATCH"5947 ],5948 "endpoints": [5949 {5950 "methods": [5951 "GET"5952 ],5953 "args": {5954 "id": {5955 "description": "The id of a template",5956 "type": "string",5957 "required": false5958 }5959 }5960 },5961 {5962 "methods": [5963 "POST",5964 "PUT",5965 "PATCH"5966 ],5967 "args": {5968 "styles": {5969 "description": "Global styles.",5970 "type": [5971 "object"5972 ],5973 "required": false5974 },5975 "settings": {5976 "description": "Global settings.",5977 "type": [5978 "object"5979 ],5980 "required": false5981 },5982 "title": {5983 "description": "Title of the global styles variation.",5984 "type": [5985 "object",5986 "string"5987 ],5988 "properties": {5989 "raw": {5990 "description": "Title for the global styles variation, as it exists in the database.",5991 "type": "string",5992 "context": [5993 "view",5994 "edit",5995 "embed"5996 ]5997 },5998 "rendered": {5999 "description": "HTML title for the post, transformed for display.",6000 "type": "string",6001 "context": [6002 "view",6003 "edit",6004 "embed"6005 ],6006 "readonly": true6007 }6008 },6009 5808 "required": false 6010 5809 } … … 9371 9170 "wp_template": "wp_template", 9372 9171 "wp_template_part": "wp_template_part", 9373 "wp_global_styles": "wp_global_styles",9374 9172 "wp_navigation": "wp_navigation", 9375 9173 "wp_font_family": "wp_font_family", … … 10578 10376 ], 10579 10377 "default": "view", 10378 10379 10380 10381 10382 10383 10384 10385 10386 10387 10388 10389 10390 10391 10392 10393 10394 10395 10396 10397 10398 10399 10400 10401 10402 10403 10404 10405 10406 10407 10408 10409 10410 10411 10412 10413 10414 10415 10416 10417 10418 10419 10420 10421 10422 10423 10424 10425 10426 10427 10428 10429 10430 10431 10432 10433 10434 10435 10436 10437 10438 10439 10440 10441 10442 10443 10444 10445 10446 10447 10448 10449 10450 10451 10452 10453 10454 10455 10456 10457 10458 10459 10460 10461 10462 10463 10464 10465 10466 10467 10468 10469 10470 10471 10472 10473 10474 10475 10476 10477 10478 10479 10480 10481 10482 10483 10484 10485 10486 10487 10488 10489 10490 10491 10492 10493 10494 10495 10496 10497 10498 10499 10500 10501 10502 10503 10504 10505 10506 10507 10508 10509 10510 10511 10512 10513 10514 10515 10516 10517 10518 10519 10520 10521 10522 10523 10524 10525 10526 10527 10528 10529 10530 10531 10532 10533 10534 10535 10536 10537 10538 10539 10540 10541 10542 10543 10544 10545 10546 10547 10548 10549 10550 10551 10552 10553 10554 10555 10556 10557 10558 10559 10560 10561 10562 10563 10564 10565 10566 10567 10568 10569 10570 10571 10572 10573 10574 10575 10576 10577 10578 10580 10579 "required": false 10581 10580 } … … 12976 12975 } 12977 12976 }, 12978 "wp_global_styles": {12979 "description": "Global styles to include in themes.",12980 "hierarchical": false,12981 "has_archive": false,12982 "name": "Global Styles",12983 "slug": "wp_global_styles",12984 "icon": null,12985 "taxonomies": [],12986 "rest_base": "global-styles",12987 "rest_namespace": "wp/v2",12988 "_links": {12989 "collection": [12990 {12991 "href": "http://example.org/index.php?rest_route=/wp/v2/types"12992 }12993 ],12994 "wp:items": [12995 {12996 "href": "http://example.org/index.php?rest_route=/wp/v2/global-styles"12997 }12998 ],12999 "curies": [13000 {13001 "name": "wp",13002 "href": "https://api.w.org/{rel}",13003 "templated": true13004 }13005 ]13006 }13007 },13008 12977 "wp_navigation": { 13009 12978 "description": "Navigation menus that can be inserted into your site.",
Note: See TracChangeset
for help on using the changeset viewer.