REST API: Add template and template_lock to post types endpoint.

Adds template and template_lock property of the post type to post types REST API endpoint.
This change allows us to fix a bug where the template of a page is not respected when creating a new page on the site editor.

Props jorgefilipecosta, oandregal, timothyblynjacobs, mukesh27.
Fixes #61477.
Built from https://develop.svn.wordpress.org/trunk@58452


git-svn-id: http://core.svn.wordpress.org/trunk@57901 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
jorgefilipecosta 2024-06-21 13:06:12 +00:00
parent 3e0408db89
commit 2613ed9ea5
2 changed files with 22 additions and 1 deletions

View File

@ -246,6 +246,14 @@ class WP_REST_Post_Types_Controller extends WP_REST_Controller {
$data['rest_namespace'] = $namespace;
}
if ( rest_is_field_included( 'template', $fields ) ) {
$data['template'] = $post_type->template ?? array();
}
if ( rest_is_field_included( 'template_lock', $fields ) ) {
$data['template_lock'] = ! empty( $post_type->template_lock ) ? $post_type->template_lock : false;
}
$context = ! empty( $request['context'] ) ? $request['context'] : 'view';
$data = $this->add_additional_fields_to_object( $data, $request );
$data = $this->filter_response_by_context( $data, $context );
@ -407,6 +415,19 @@ class WP_REST_Post_Types_Controller extends WP_REST_Controller {
'context' => array( 'view', 'edit', 'embed' ),
'readonly' => true,
),
'template' => array(
'type' => array( 'array' ),
'description' => __( 'The block template associated with the post type.' ),
'readonly' => true,
'context' => array( 'view', 'edit', 'embed' ),
),
'template_lock' => array(
'type' => array( 'string', 'boolean' ),
'enum' => array( 'all', 'insert', 'contentOnly', false ),
'description' => __( 'The template_lock associated with the post type, or false if none.' ),
'readonly' => true,
'context' => array( 'view', 'edit', 'embed' ),
),
),
);

View File

@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
$wp_version = '6.6-beta3-58451';
$wp_version = '6.6-beta3-58452';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.