-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Template activation: merge new GB changes for Beta 2 #10425
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
fa04cbc
a2d0e99
8dfcd52
73060b8
f8f44c7
33fa916
9892a04
20415f4
13c40c8
937f020
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -263,15 +263,6 @@ function rest_api_default_filters() { | |
| * @since 4.7.0 | ||
| */ | ||
| function create_initial_rest_routes() { | ||
| global $wp_post_types; | ||
|
|
||
| // Register the registered templates endpoint. For that we need to copy the | ||
| // wp_template post type so that it's available as an entity in core-data. | ||
| $wp_post_types['wp_registered_template'] = clone $wp_post_types['wp_template']; | ||
| $wp_post_types['wp_registered_template']->name = 'wp_registered_template'; | ||
| $wp_post_types['wp_registered_template']->rest_base = 'wp_registered_template'; | ||
| $wp_post_types['wp_registered_template']->rest_controller_class = 'WP_REST_Registered_Templates_Controller'; | ||
|
|
||
|
Comment on lines
-266
to
-274
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's great this is being removed. It caused issues due to
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wow, I didn't know there's a max length |
||
| foreach ( get_post_types( array( 'show_in_rest' => true ), 'objects' ) as $post_type ) { | ||
| $controller = $post_type->get_rest_controller(); | ||
|
|
||
|
|
@@ -298,11 +289,14 @@ function create_initial_rest_routes() { | |
| } | ||
| } | ||
|
|
||
| global $wp_post_types; | ||
|
|
||
| // Register the old templates endpoints. The WP_REST_Templates_Controller | ||
| // and sub-controllers used linked to the wp_template post type, but are no | ||
| // longer. They still require a post type object when contructing the class. | ||
| // To maintain backward and changes to these controller classes, we make use | ||
| // that the wp_template post type has the right information it needs. | ||
| $current_wp_template_rest_base = $wp_post_types['wp_template']->rest_base; | ||
| $wp_post_types['wp_template']->rest_base = 'templates'; | ||
| // Store the classes so they can be restored. | ||
| $original_rest_controller_class = $wp_post_types['wp_template']->rest_controller_class; | ||
|
|
@@ -328,7 +322,7 @@ function create_initial_rest_routes() { | |
| $wp_post_types['wp_template']->autosave_rest_controller_class = $original_autosave_rest_controller_class; | ||
| $wp_post_types['wp_template']->revisions_rest_controller_class = $original_revisions_rest_controller_class; | ||
| // Restore the original base. | ||
| $wp_post_types['wp_template']->rest_base = 'wp_template'; | ||
| $wp_post_types['wp_template']->rest_base = $current_wp_template_rest_base; | ||
|
|
||
| // Register the old routes. | ||
| $autosaves_controller->register_routes(); | ||
|
|
@@ -356,6 +350,10 @@ function create_initial_rest_routes() { | |
| ) | ||
| ); | ||
|
|
||
| // Registered templates. | ||
| $controller = new WP_REST_Registered_Templates_Controller(); | ||
| $controller->register_routes(); | ||
|
|
||
| // Post types. | ||
| $controller = new WP_REST_Post_Types_Controller(); | ||
| $controller->register_routes(); | ||
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This file is missing phpdoc. We should add it at some point during beta. |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,6 +1,12 @@ | ||||||||||||||||||||
| <?php | ||||||||||||||||||||
|
|
||||||||||||||||||||
| class WP_REST_Registered_Templates_Controller extends WP_REST_Templates_Controller { | ||||||||||||||||||||
| public function __construct() { | ||||||||||||||||||||
| parent::__construct( 'wp_template' ); | ||||||||||||||||||||
| $this->rest_base = 'registered-templates'; | ||||||||||||||||||||
| $this->namespace = 'wp/v2'; | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
Comment on lines
4
to
8
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. PhpStorm is complaining about this not calling
Maybe this class shouldn't be extending Or should this be passing
Suggested change
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Otherwise, there are methods in
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's true, though I think none of these methods will be called. And yes, ideally we refactor this to not extend
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Though
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added the parent construct call. I'll avoid extending |
||||||||||||||||||||
|
|
||||||||||||||||||||
| public function register_routes() { | ||||||||||||||||||||
| // Lists all templates. | ||||||||||||||||||||
| register_rest_route( | ||||||||||||||||||||
|
|
@@ -81,9 +87,8 @@ public function get_items( $request ) { | |||||||||||||||||||
| $query_result = get_registered_block_templates( $query ); | ||||||||||||||||||||
| $templates = array(); | ||||||||||||||||||||
| foreach ( $query_result as $template ) { | ||||||||||||||||||||
| $item = $this->prepare_item_for_response( $template, $request ); | ||||||||||||||||||||
| $item->data['type'] = 'wp_registered_template'; | ||||||||||||||||||||
| $templates[] = $this->prepare_response_for_collection( $item ); | ||||||||||||||||||||
| $item = $this->prepare_item_for_response( $template, $request ); | ||||||||||||||||||||
| $templates[] = $this->prepare_response_for_collection( $item ); | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| return rest_ensure_response( $templates ); | ||||||||||||||||||||
|
|
@@ -97,8 +102,6 @@ public function get_item( $request ) { | |||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| $item = $this->prepare_item_for_response( $template, $request ); | ||||||||||||||||||||
| // adjust the template type here instead | ||||||||||||||||||||
| $item->data['type'] = 'wp_registered_template'; | ||||||||||||||||||||
| return rest_ensure_response( $item ); | ||||||||||||||||||||
| } | ||||||||||||||||||||
| } | ||||||||||||||||||||

There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was forgotten before Beta 1. There's a follow-up PR, but it still unsure what the final migration should look like. In the meantime, let's merge the changes we have worked with so far in Gutenberg.