Make WordPress Core


Ignore:
Timestamp:
10/21/2025 01:40:28 PM (5 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/post.php

    r60987 r61029  
    399399            'show_in_rest'                    => true,
    400400            'rewrite'                         => false,
    401             'rest_base'                       => 'templates',
    402             'rest_controller_class'           => 'WP_REST_Templates_Controller',
    403             'autosave_rest_controller_class'  => 'WP_REST_Template_Autosaves_Controller',
    404             'revisions_rest_controller_class' => 'WP_REST_Template_Revisions_Controller',
     401            'rest_base'                       => 'wp_template',
     402            'rest_controller_class'           => 'WP_REST_Posts_Controller',
    405403            'late_route_registration'         => true,
    406404            'capability_type'                 => array( 'template', 'templates' ),
     
    427425                'revisions',
    428426                'author',
     427                'custom-fields',
    429428            ),
    430429        )
     
    86308629        )
    86318630    );
    8632 }
     8631
     8632    // Allow setting the is_wp_suggestion meta field, which partly determines if
     8633    // a template is a custom template.
     8634    register_post_meta(
     8635        'wp_template',
     8636        'is_wp_suggestion',
     8637        array(
     8638            'type'         => 'boolean',
     8639            'show_in_rest' => true,
     8640            'single'       => true,
     8641        )
     8642    );
     8643}
Note: See TracChangeset for help on using the changeset viewer.