diff --git a/lib/compat/wordpress-5.9/class-gutenberg-rest-templates-controller.php b/lib/compat/wordpress-5.9/class-gutenberg-rest-templates-controller.php index eb7f047a8e98df..12aa2124da3731 100644 --- a/lib/compat/wordpress-5.9/class-gutenberg-rest-templates-controller.php +++ b/lib/compat/wordpress-5.9/class-gutenberg-rest-templates-controller.php @@ -414,6 +414,10 @@ public function prepare_item_for_response( $template, $request ) { // phpcs:igno 'has_theme_file' => $template->has_theme_file, ); + if ( 'wp_template' === $template->type ) { + $result['is_custom'] = $template->is_custom; + } + if ( 'wp_template_part' === $template->type ) { $result['area'] = $template->area; } @@ -582,6 +586,15 @@ public function get_item_schema() { ), ); + if ( 'wp_template' === $this->post_type ) { + $schema['properties']['is_custom'] = array( + 'description' => __( 'Whether a template is a custom template.', 'gutenberg' ), + 'type' => 'bool', + 'context' => array( 'embed', 'view', 'edit' ), + 'readonly' => true, + ); + } + if ( 'wp_template_part' === $this->post_type ) { $schema['properties']['area'] = array( 'description' => __( 'Where the template part is intended for use (header, footer, etc.)', 'gutenberg' ), diff --git a/phpunit/class-gutenberg-rest-template-controller-test.php b/phpunit/class-gutenberg-rest-template-controller-test.php index 4fc3b5407e06e9..6c6d62be1b417d 100644 --- a/phpunit/class-gutenberg-rest-template-controller-test.php +++ b/phpunit/class-gutenberg-rest-template-controller-test.php @@ -76,6 +76,7 @@ function find_and_normalize_template_by_id( $templates, $id ) { 'type' => 'wp_template', 'wp_id' => null, 'has_theme_file' => true, + 'is_custom' => false, ), find_and_normalize_template_by_id( $data, 'tt1-blocks//index' ) ); @@ -129,6 +130,7 @@ public function test_get_item() { 'type' => 'wp_template', 'wp_id' => null, 'has_theme_file' => true, + 'is_custom' => false, ), $data ); @@ -193,6 +195,7 @@ public function test_create_item() { 'raw' => 'Content', ), 'has_theme_file' => false, + 'is_custom' => true, ), $data );