Make WordPress Core


Ignore:
Timestamp:
11/07/2025 12:41:01 PM (5 months ago)
Author:
ellatrix
Message:

Revert template activation.

This commit reverts the PHP changes that were made to support the template activation feature. The UI was already reverted through the packages sync in [61177] (Gutenberg PR: https://github.com/WordPress/gutenberg/pull/73025).

Developed in https://github.com/WordPress/wordpress-develop/pull/10473.

Fixes #64214.
Props ellatrix, t-hamano, mcsf, ramonjd.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/rest-api.php

    r61078 r61178  
    290290    }
    291291
    292     global $wp_post_types;
    293 
    294     // Register the old templates endpoints. The WP_REST_Templates_Controller
    295     // and sub-controllers used linked to the wp_template post type, but are no
    296     // longer. They still require a post type object when contructing the class.
    297     // To maintain backward and changes to these controller classes, we make use
    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;
    300     $wp_post_types['wp_template']->rest_base = 'templates';
    301     // Store the classes so they can be restored.
    302     $original_rest_controller_class           = $wp_post_types['wp_template']->rest_controller_class;
    303     $original_autosave_rest_controller_class  = $wp_post_types['wp_template']->autosave_rest_controller_class;
    304     $original_revisions_rest_controller_class = $wp_post_types['wp_template']->revisions_rest_controller_class;
    305     // Temporarily set the old classes.
    306     $wp_post_types['wp_template']->rest_controller_class           = 'WP_REST_Templates_Controller';
    307     $wp_post_types['wp_template']->autosave_rest_controller_class  = 'WP_REST_Template_Autosaves_Controller';
    308     $wp_post_types['wp_template']->revisions_rest_controller_class = 'WP_REST_Template_Revisions_Controller';
    309     // Initialize the controllers. The order is important: the autosave
    310     // controller needs both the templates and revisions controllers.
    311     $controller                                    = new WP_REST_Templates_Controller( 'wp_template' );
    312     $wp_post_types['wp_template']->rest_controller = $controller;
    313     $revisions_controller                          = new WP_REST_Template_Revisions_Controller( 'wp_template' );
    314     $wp_post_types['wp_template']->revisions_rest_controller = $revisions_controller;
    315     $autosaves_controller                                    = new WP_REST_Template_Autosaves_Controller( 'wp_template' );
    316     // Unset the controller cache, it will be re-initialized when
    317     // get_rest_controller is called.
    318     $wp_post_types['wp_template']->rest_controller           = null;
    319     $wp_post_types['wp_template']->revisions_rest_controller = null;
    320     // Restore the original classes.
    321     $wp_post_types['wp_template']->rest_controller_class           = $original_rest_controller_class;
    322     $wp_post_types['wp_template']->autosave_rest_controller_class  = $original_autosave_rest_controller_class;
    323     $wp_post_types['wp_template']->revisions_rest_controller_class = $original_revisions_rest_controller_class;
    324     // Restore the original base.
    325     $wp_post_types['wp_template']->rest_base = $current_wp_template_rest_base;
    326 
    327     // Register the old routes.
    328     $autosaves_controller->register_routes();
    329     $revisions_controller->register_routes();
    330     $controller->register_routes();
    331 
    332     register_rest_field(
    333         'wp_template',
    334         'theme',
    335         array(
    336             'get_callback' => function ( $post_arr ) {
    337                 // add_additional_fields_to_object is also called for the old
    338                 // templates controller, so we need to check if the id is an
    339                 // integer to make sure it's the proper post type endpoint.
    340                 if ( ! is_int( $post_arr['id'] ) ) {
    341                     $template = get_block_template( $post_arr['id'], 'wp_template' );
    342                     return $template ? $template->theme : null;
    343                 }
    344                 $terms = get_the_terms( $post_arr['id'], 'wp_theme' );
    345                 if ( is_wp_error( $terms ) || empty( $terms ) ) {
    346                     return null;
    347                 }
    348                 return $terms[0]->slug;
    349             },
    350         )
    351     );
    352 
    353     // Registered templates.
    354     $controller = new WP_REST_Registered_Templates_Controller();
    355     $controller->register_routes();
    356 
    357292    // Post types.
    358293    $controller = new WP_REST_Post_Types_Controller();
Note: See TracChangeset for help on using the changeset viewer.