Changeset 61078
- Timestamp:
- 10/28/2025 01:34:00 PM (7 weeks ago)
- Location:
- trunk
- Files:
-
- 9 edited
-
src/wp-admin/site-editor.php (modified) (1 diff)
-
src/wp-includes/block-template-utils.php (modified) (2 diffs)
-
src/wp-includes/block-template.php (modified) (2 diffs)
-
src/wp-includes/default-filters.php (modified) (1 diff)
-
src/wp-includes/post.php (modified) (1 diff)
-
src/wp-includes/rest-api.php (modified) (5 diffs)
-
src/wp-includes/rest-api/endpoints/class-wp-rest-registered-templates-controller.php (modified) (3 diffs)
-
tests/phpunit/tests/rest-api/rest-schema-setup.php (modified) (1 diff)
-
tests/qunit/fixtures/wp-api-generated.js (modified) (13 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/site-editor.php
r61029 r61078 183 183 array( rest_get_route_for_post_type_items( 'page' ), 'OPTIONS' ), 184 184 '/wp/v2/types?context=view', 185 '/wp/v2/wp_registered_template?context=edit',186 185 '/wp/v2/types/wp_template?context=edit', 187 186 '/wp/v2/types/wp_template_part?context=edit', -
trunk/src/wp-includes/block-template-utils.php
r61029 r61078 1359 1359 } 1360 1360 } 1361 } elseif ( false === $active_templates[ $slug ] ) {1362 return null;1363 1361 } 1364 1362 } … … 1883 1881 update_option( 'active_templates', $active_templates ); 1884 1882 } 1883 1884 function _wp_migrate_active_templates() { 1885 // Do not run during installation when the database is not yet available. 1886 if ( wp_installing() ) { 1887 return; 1888 } 1889 1890 $active_templates = get_option( 'active_templates', false ); 1891 1892 if ( false !== $active_templates ) { 1893 return; 1894 } 1895 1896 // Query all templates in the database. See `get_block_templates`. 1897 $wp_query_args = array( 1898 'post_status' => 'publish', 1899 'post_type' => 'wp_template', 1900 'posts_per_page' => -1, 1901 'no_found_rows' => true, 1902 'lazy_load_term_meta' => false, 1903 'tax_query' => array( 1904 array( 1905 'taxonomy' => 'wp_theme', 1906 'field' => 'name', 1907 'terms' => get_stylesheet(), 1908 ), 1909 ), 1910 // Only get templates that are not inactive by default. We check these 1911 // meta to make sure we don't fill the option with inactive templates 1912 // created after the 6.9 release when for some reason the option is 1913 // deleted. 1914 'meta_query' => array( 1915 'relation' => 'OR', 1916 array( 1917 'key' => 'is_inactive_by_default', 1918 'compare' => 'NOT EXISTS', 1919 ), 1920 array( 1921 'key' => 'is_inactive_by_default', 1922 'value' => false, 1923 'compare' => '=', 1924 ), 1925 ), 1926 ); 1927 1928 $template_query = new WP_Query( $wp_query_args ); 1929 $active_templates = array(); 1930 1931 foreach ( $template_query->posts as $post ) { 1932 $active_templates[ $post->post_name ] = $post->ID; 1933 } 1934 1935 update_option( 'active_templates', $active_templates ); 1936 } -
trunk/src/wp-includes/block-template.php
r61029 r61078 165 165 ); 166 166 167 $object = get_queried_object();168 $specific_template = $object ? get_page_template_slug( $object) : null;167 $object_id = get_queried_object_id(); 168 $specific_template = $object_id && get_post( $object_id ) ? get_page_template_slug( $object_id ) : null; 169 169 $active_templates = (array) get_option( 'active_templates', array() ); 170 171 // Remove templates slugs that are deactivated, except if it's the specific172 // template or index.173 $slugs = array_filter(174 $slugs,175 function ( $slug ) use ( $specific_template, $active_templates ) {176 $should_ignore = $slug === $specific_template || 'index' === $slug;177 return $should_ignore || ( ! isset( $active_templates[ $slug ] ) || false !== $active_templates[ $slug ] );178 }179 );180 170 181 171 // We expect one template for each slug. Use the active template if it is … … 233 223 $templates = array_merge( $templates, get_registered_block_templates( $query ) ); 234 224 235 if ( $specific_template ) {225 if ( $specific_template && in_array( $specific_template, $remaining_slugs, true ) ) { 236 226 $templates = array_merge( $templates, get_block_templates( array( 'slug__in' => array( $specific_template ) ) ) ); 237 227 } -
trunk/src/wp-includes/default-filters.php
r61063 r61078 571 571 // Post. 572 572 add_action( 'init', 'create_initial_post_types', 0 ); // Highest priority. 573 add_action( 'init', '_wp_migrate_active_templates', 0 ); // Highest priority. 573 574 add_action( 'admin_menu', '_add_post_type_submenus' ); 574 575 add_action( 'before_delete_post', '_reset_front_page_settings_for_post' ); -
trunk/src/wp-includes/post.php
r61036 r61078 399 399 'show_in_rest' => true, 400 400 'rewrite' => false, 401 'rest_base' => ' wp_template',401 'rest_base' => 'created-templates', 402 402 'rest_controller_class' => 'WP_REST_Posts_Controller', 403 403 'late_route_registration' => true, -
trunk/src/wp-includes/rest-api.php
r61045 r61078 264 264 */ 265 265 function create_initial_rest_routes() { 266 global $wp_post_types;267 268 // Register the registered templates endpoint. For that we need to copy the269 // wp_template post type so that it's available as an entity in core-data.270 $wp_post_types['wp_registered_template'] = clone $wp_post_types['wp_template'];271 $wp_post_types['wp_registered_template']->name = 'wp_registered_template';272 $wp_post_types['wp_registered_template']->rest_base = 'wp_registered_template';273 $wp_post_types['wp_registered_template']->rest_controller_class = 'WP_REST_Registered_Templates_Controller';274 275 266 foreach ( get_post_types( array( 'show_in_rest' => true ), 'objects' ) as $post_type ) { 276 267 $controller = $post_type->get_rest_controller(); … … 298 289 } 299 290 } 291 292 global $wp_post_types; 300 293 301 294 // Register the old templates endpoints. The WP_REST_Templates_Controller … … 304 297 // To maintain backward and changes to these controller classes, we make use 305 298 // that the wp_template post type has the right information it needs. 299 $current_wp_template_rest_base = $wp_post_types['wp_template']->rest_base; 306 300 $wp_post_types['wp_template']->rest_base = 'templates'; 307 301 // Store the classes so they can be restored. … … 329 323 $wp_post_types['wp_template']->revisions_rest_controller_class = $original_revisions_rest_controller_class; 330 324 // Restore the original base. 331 $wp_post_types['wp_template']->rest_base = 'wp_template';325 $wp_post_types['wp_template']->rest_base = $current_wp_template_rest_base; 332 326 333 327 // Register the old routes. … … 356 350 ) 357 351 ); 352 353 // Registered templates. 354 $controller = new WP_REST_Registered_Templates_Controller(); 355 $controller->register_routes(); 358 356 359 357 // Post types. -
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-registered-templates-controller.php
r61033 r61078 2 2 3 3 class WP_REST_Registered_Templates_Controller extends WP_REST_Templates_Controller { 4 public function __construct() { 5 parent::__construct( 'wp_template' ); 6 $this->rest_base = 'registered-templates'; 7 $this->namespace = 'wp/v2'; 8 } 9 4 10 public function register_routes() { 5 11 // Lists all templates. … … 82 88 $templates = array(); 83 89 foreach ( $query_result as $template ) { 84 $item = $this->prepare_item_for_response( $template, $request ); 85 $item->data['type'] = 'wp_registered_template'; 86 $templates[] = $this->prepare_response_for_collection( $item ); 90 $item = $this->prepare_item_for_response( $template, $request ); 91 $templates[] = $this->prepare_response_for_collection( $item ); 87 92 } 88 93 … … 98 103 99 104 $item = $this->prepare_item_for_response( $template, $request ); 100 // adjust the template type here instead101 $item->data['type'] = 'wp_registered_template';102 105 return rest_ensure_response( $item ); 103 106 } -
trunk/tests/phpunit/tests/rest-api/rest-schema-setup.php
r61045 r61078 158 158 '/wp/v2/templates/(?P<parent>([^\/:<>\*\?"\|]+(?:\/[^\/:<>\*\?"\|]+)?)[\/\w%-]+)/revisions', 159 159 '/wp/v2/templates/(?P<parent>([^\/:<>\*\?"\|]+(?:\/[^\/:<>\*\?"\|]+)?)[\/\w%-]+)/revisions/(?P<id>[\d]+)', 160 '/wp/v2/ wp_registered_template',161 '/wp/v2/ wp_registered_template/(?P<id>([^\/:<>\*\?"\|]+(?:\/[^\/:<>\*\?"\|]+)?)[\/\w%-]+)',162 '/wp/v2/ wp_template',163 '/wp/v2/ wp_template/(?P<id>[\d]+)',164 '/wp/v2/ wp_template/(?P<id>[\d]+)/autosaves',165 '/wp/v2/ wp_template/(?P<parent>[\d]+)/autosaves/(?P<id>[\d]+)',166 '/wp/v2/ wp_template/(?P<parent>[\d]+)/revisions',167 '/wp/v2/ wp_template/(?P<parent>[\d]+)/revisions/(?P<id>[\d]+)',160 '/wp/v2/registered-templates', 161 '/wp/v2/registered-templates/(?P<id>([^\/:<>\*\?"\|]+(?:\/[^\/:<>\*\?"\|]+)?)[\/\w%-]+)', 162 '/wp/v2/created-templates', 163 '/wp/v2/created-templates/(?P<id>[\d]+)', 164 '/wp/v2/created-templates/(?P<id>[\d]+)/autosaves', 165 '/wp/v2/created-templates/(?P<parent>[\d]+)/autosaves/(?P<id>[\d]+)', 166 '/wp/v2/created-templates/(?P<parent>[\d]+)/revisions', 167 '/wp/v2/created-templates/(?P<parent>[\d]+)/revisions/(?P<id>[\d]+)', 168 168 '/wp/v2/templates/lookup', 169 169 '/wp/v2/themes', -
trunk/tests/qunit/fixtures/wp-api-generated.js
r61045 r61078 5509 5509 ] 5510 5510 }, 5511 "/wp/v2/ wp_template/(?P<parent>[\\d]+)/revisions": {5511 "/wp/v2/created-templates/(?P<parent>[\\d]+)/revisions": { 5512 5512 "namespace": "wp/v2", 5513 5513 "methods": [ … … 5607 5607 ] 5608 5608 }, 5609 "/wp/v2/ wp_template/(?P<parent>[\\d]+)/revisions/(?P<id>[\\d]+)": {5609 "/wp/v2/created-templates/(?P<parent>[\\d]+)/revisions/(?P<id>[\\d]+)": { 5610 5610 "namespace": "wp/v2", 5611 5611 "methods": [ … … 5667 5667 ] 5668 5668 }, 5669 "/wp/v2/ wp_template/(?P<id>[\\d]+)/autosaves": {5669 "/wp/v2/created-templates/(?P<id>[\\d]+)/autosaves": { 5670 5670 "namespace": "wp/v2", 5671 5671 "methods": [ … … 5866 5866 ] 5867 5867 }, 5868 "/wp/v2/ wp_template/(?P<parent>[\\d]+)/autosaves/(?P<id>[\\d]+)": {5868 "/wp/v2/created-templates/(?P<parent>[\\d]+)/autosaves/(?P<id>[\\d]+)": { 5869 5869 "namespace": "wp/v2", 5870 5870 "methods": [ … … 5902 5902 ] 5903 5903 }, 5904 "/wp/v2/ wp_template": {5904 "/wp/v2/created-templates": { 5905 5905 "namespace": "wp/v2", 5906 5906 "methods": [ … … 6266 6266 "self": [ 6267 6267 { 6268 "href": "http://example.org/index.php?rest_route=/wp/v2/ wp_template"6268 "href": "http://example.org/index.php?rest_route=/wp/v2/created-templates" 6269 6269 } 6270 6270 ] 6271 6271 } 6272 6272 }, 6273 "/wp/v2/ wp_template/(?P<id>[\\d]+)": {6273 "/wp/v2/created-templates/(?P<id>[\\d]+)": { 6274 6274 "namespace": "wp/v2", 6275 6275 "methods": [ … … 8672 8672 ] 8673 8673 }, 8674 "/wp/v2/wp_registered_template": {8675 "namespace": "wp/v2",8676 "methods": [8677 "GET"8678 ],8679 "endpoints": [8680 {8681 "methods": [8682 "GET"8683 ],8684 "args": {8685 "context": {8686 "description": "Scope under which the request is made; determines fields present in response.",8687 "type": "string",8688 "enum": [8689 "view",8690 "embed",8691 "edit"8692 ],8693 "default": "view",8694 "required": false8695 },8696 "wp_id": {8697 "description": "Limit to the specified post id.",8698 "type": "integer",8699 "required": false8700 },8701 "area": {8702 "description": "Limit to the specified template part area.",8703 "type": "string",8704 "required": false8705 },8706 "post_type": {8707 "description": "Post type to get the templates for.",8708 "type": "string",8709 "required": false8710 }8711 }8712 }8713 ],8714 "_links": {8715 "self": [8716 {8717 "href": "http://example.org/index.php?rest_route=/wp/v2/wp_registered_template"8718 }8719 ]8720 }8721 },8722 "/wp/v2/wp_registered_template/(?P<id>([^\\/:<>\\*\\?\"\\|]+(?:\\/[^\\/:<>\\*\\?\"\\|]+)?)[\\/\\w%-]+)": {8723 "namespace": "wp/v2",8724 "methods": [8725 "GET"8726 ],8727 "endpoints": [8728 {8729 "methods": [8730 "GET"8731 ],8732 "args": {8733 "id": {8734 "description": "The id of a template",8735 "type": "string",8736 "required": false8737 },8738 "context": {8739 "description": "Scope under which the request is made; determines fields present in response.",8740 "type": "string",8741 "enum": [8742 "view",8743 "embed",8744 "edit"8745 ],8746 "default": "view",8747 "required": false8748 }8749 }8750 }8751 ]8752 },8753 8674 "/wp/v2/templates/(?P<id>([^\\/:<>\\*\\?\"\\|]+(?:\\/[^\\/:<>\\*\\?\"\\|]+)?)[\\/\\w%-]+)/autosaves": { 8754 8675 "namespace": "wp/v2", … … 9429 9350 "default": false, 9430 9351 "description": "Whether to bypass Trash and force deletion.", 9352 "required": false 9353 } 9354 } 9355 } 9356 ] 9357 }, 9358 "/wp/v2/registered-templates": { 9359 "namespace": "wp/v2", 9360 "methods": [ 9361 "GET" 9362 ], 9363 "endpoints": [ 9364 { 9365 "methods": [ 9366 "GET" 9367 ], 9368 "args": { 9369 "context": { 9370 "description": "Scope under which the request is made; determines fields present in response.", 9371 "type": "string", 9372 "enum": [ 9373 "view", 9374 "embed", 9375 "edit" 9376 ], 9377 "default": "view", 9378 "required": false 9379 }, 9380 "wp_id": { 9381 "description": "Limit to the specified post id.", 9382 "type": "integer", 9383 "required": false 9384 }, 9385 "area": { 9386 "description": "Limit to the specified template part area.", 9387 "type": "string", 9388 "required": false 9389 }, 9390 "post_type": { 9391 "description": "Post type to get the templates for.", 9392 "type": "string", 9393 "required": false 9394 } 9395 } 9396 } 9397 ], 9398 "_links": { 9399 "self": [ 9400 { 9401 "href": "http://example.org/index.php?rest_route=/wp/v2/registered-templates" 9402 } 9403 ] 9404 } 9405 }, 9406 "/wp/v2/registered-templates/(?P<id>([^\\/:<>\\*\\?\"\\|]+(?:\\/[^\\/:<>\\*\\?\"\\|]+)?)[\\/\\w%-]+)": { 9407 "namespace": "wp/v2", 9408 "methods": [ 9409 "GET" 9410 ], 9411 "endpoints": [ 9412 { 9413 "methods": [ 9414 "GET" 9415 ], 9416 "args": { 9417 "id": { 9418 "description": "The id of a template", 9419 "type": "string", 9420 "required": false 9421 }, 9422 "context": { 9423 "description": "Scope under which the request is made; determines fields present in response.", 9424 "type": "string", 9425 "enum": [ 9426 "view", 9427 "embed", 9428 "edit" 9429 ], 9430 "default": "view", 9431 9431 "required": false 9432 9432 } … … 10810 10810 "wp_navigation": "wp_navigation", 10811 10811 "wp_font_family": "wp_font_family", 10812 "wp_font_face": "wp_font_face", 10813 "wp_registered_template": "wp_registered_template" 10812 "wp_font_face": "wp_font_face" 10814 10813 } 10815 10814 }, … … 14769 14768 "icon": null, 14770 14769 "taxonomies": [], 14771 "rest_base": " wp_template",14770 "rest_base": "created-templates", 14772 14771 "rest_namespace": "wp/v2", 14773 14772 "template": [], … … 14781 14780 "wp:items": [ 14782 14781 { 14783 "href": "http://example.org/index.php?rest_route=/wp/v2/ wp_template"14782 "href": "http://example.org/index.php?rest_route=/wp/v2/created-templates" 14784 14783 } 14785 14784 ], … … 14942 14941 { 14943 14942 "href": "http://example.org/index.php?rest_route=/wp/v2/font-families/(?P<font_family_id>[\\d]+)/font-faces" 14944 }14945 ],14946 "curies": [14947 {14948 "name": "wp",14949 "href": "https://api.w.org/{rel}",14950 "templated": true14951 }14952 ]14953 }14954 },14955 "wp_registered_template": {14956 "description": "Templates to include in your theme.",14957 "hierarchical": false,14958 "has_archive": false,14959 "name": "Templates",14960 "slug": "wp_registered_template",14961 "icon": null,14962 "taxonomies": [],14963 "rest_base": "wp_registered_template",14964 "rest_namespace": "wp/v2",14965 "template": [],14966 "template_lock": false,14967 "_links": {14968 "collection": [14969 {14970 "href": "http://example.org/index.php?rest_route=/wp/v2/types"14971 }14972 ],14973 "wp:items": [14974 {14975 "href": "http://example.org/index.php?rest_route=/wp/v2/wp_registered_template"14976 14943 } 14977 14944 ], … … 15591 15558 "default_ping_status": "open", 15592 15559 "default_comment_status": "open", 15593 "active_templates": null,15560 "active_templates": [], 15594 15561 "site_logo": null, 15595 15562 "site_icon": 0
Note: See TracChangeset
for help on using the changeset viewer.