Make WordPress Core


Ignore:
Timestamp:
10/21/2025 01:40:28 PM (8 months ago)
Author:
ellatrix
Message:

Templates: add PHP changes required for the template activation feature.

  • Adds the active_templates setting, which is an object holding the template slug as a key and template post ID as the value.
  • To maintain backwards compatibility, any wp_template (post type) not created through the new API will be activated.
  • get_block_template and get_block_templates have been adjusted to check active_templates. These functions should never return inactive templates, just like before, to maintain backwards compatibility.
  • The pre-existing /templates endpoint and sub-endpoints remain and work exactly as before.
  • A new endpoint /wp_template has been added, but this is just a regular posts controller (WP_REST_Posts_Controller). We do register an additional theme field and expose the is_wp_suggestion meta.
  • Another new endpoint /wp_registered_template has been added, which is read-only and lists the registered templates from themes and plugin (un-edited, without activations applied).

These changes are to be iterated on.

See https://github.com/WordPress/wordpress-develop/pull/8063.

Props ellatrix, shailu25, ntsekouras.
Fixes #62755.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/default-filters.php

    r61022 r61029  
    741741add_filter( 'render_block_context', '_block_template_render_without_post_block_context' );
    742742add_filter( 'pre_wp_unique_post_slug', 'wp_filter_wp_template_unique_post_slug', 10, 5 );
     743add_action( 'save_post_wp_template', 'wp_maybe_activate_template' );
    743744add_action( 'save_post_wp_template_part', 'wp_set_unique_slug_on_create_template_part' );
    744745add_action( 'wp_enqueue_scripts', 'wp_enqueue_block_template_skip_link' );
     
    781782add_filter( 'rest_pre_insert_wp_template_part', 'inject_ignored_hooked_blocks_metadata_attributes' );
    782783
     784// Assign the wp_theme term to any newly created wp_template with the new endpoint.
     785// Must run before `inject_ignored_hooked_blocks_metadata_attributes`.
     786add_action( 'rest_pre_insert_wp_template', 'wp_assign_new_template_to_theme', 9, 2 );
     787
    783788// Update ignoredHookedBlocks postmeta for some post types.
    784789add_filter( 'rest_pre_insert_page', 'update_ignored_hooked_blocks_postmeta' );
Note: See TracChangeset for help on using the changeset viewer.