From 2613ed9ea5ce41ef6b3a9c7b4e9cf3d561e868d1 Mon Sep 17 00:00:00 2001 From: jorgefilipecosta Date: Fri, 21 Jun 2024 13:06:12 +0000 Subject: [PATCH] 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 --- .../class-wp-rest-post-types-controller.php | 21 +++++++++++++++++++ wp-includes/version.php | 2 +- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/wp-includes/rest-api/endpoints/class-wp-rest-post-types-controller.php b/wp-includes/rest-api/endpoints/class-wp-rest-post-types-controller.php index 0d3d0e1279..d766d5c61d 100644 --- a/wp-includes/rest-api/endpoints/class-wp-rest-post-types-controller.php +++ b/wp-includes/rest-api/endpoints/class-wp-rest-post-types-controller.php @@ -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' ), + ), ), ); diff --git a/wp-includes/version.php b/wp-includes/version.php index 48907c8358..5cf05ce279 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -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.