From e0a4bd843e68ed3f5cd2e233ef439d58a700135e Mon Sep 17 00:00:00 2001 From: Daniel Richards Date: Thu, 25 Nov 2021 15:28:24 +0800 Subject: [PATCH] WIP - origin --- lib/compat/wordpress-5.9/block-template-utils.php | 3 +++ .../class-gutenberg-rest-templates-controller.php | 8 ++++++++ lib/full-site-editing/class-wp-block-template.php | 10 ++++++++++ 3 files changed, 21 insertions(+) diff --git a/lib/compat/wordpress-5.9/block-template-utils.php b/lib/compat/wordpress-5.9/block-template-utils.php index b22732df001d4..3e2e06248ea29 100644 --- a/lib/compat/wordpress-5.9/block-template-utils.php +++ b/lib/compat/wordpress-5.9/block-template-utils.php @@ -527,6 +527,8 @@ function _build_block_template_result_from_post( $post ) { return new WP_Error( 'template_missing_theme', __( 'No theme is defined for this template.', 'gutenberg' ) ); } + $origin = get_post_meta( $post->ID, 'origin', true ); + $theme = $terms[0]->name; $has_theme_file = wp_get_theme()->get_stylesheet() === $theme && null !== _get_block_template_file( $post->post_type, $post->post_name ); @@ -538,6 +540,7 @@ function _build_block_template_result_from_post( $post ) { $template->content = $post->post_content; $template->slug = $post->post_name; $template->source = 'custom'; + $template->origin = ! empty( $origin ) ? $origin : null; $template->type = $post->post_type; $template->description = $post->post_excerpt; $template->title = $post->post_title; 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 6ec5db1dce988..63ab2cd4cba69 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 @@ -354,6 +354,7 @@ protected function prepare_item_for_database( $request ) { $changes->tax_input = array( 'wp_theme' => $template->theme, ); + $changes->origin = $template->source; } else { $changes->post_name = $template->slug; $changes->ID = $template->wp_id; @@ -421,6 +422,7 @@ public function prepare_item_for_response( $template, $request ) { // phpcs:igno 'content' => array( 'raw' => $template->content ), 'slug' => $template->slug, 'source' => $template->source, + 'origin' => $template->origin, 'type' => $template->type, 'description' => $template->description, 'title' => array( @@ -562,6 +564,12 @@ public function get_item_schema() { 'context' => array( 'embed', 'view', 'edit' ), 'readonly' => true, ), + 'source' => array( + 'description' => __( 'Source of customized template', 'gutenberg' ), + 'type' => 'string', + 'context' => array( 'embed', 'view', 'edit' ), + 'readonly' => true, + ), 'content' => array( 'description' => __( 'Content of template.', 'gutenberg' ), 'type' => array( 'object', 'string' ), diff --git a/lib/full-site-editing/class-wp-block-template.php b/lib/full-site-editing/class-wp-block-template.php index 967c49de953d7..1dbf482c66e06 100644 --- a/lib/full-site-editing/class-wp-block-template.php +++ b/lib/full-site-editing/class-wp-block-template.php @@ -67,6 +67,16 @@ class WP_Block_Template { */ public $source = 'theme'; + /** + * Origin of the content when the content has been customized. + * When customized, origin takes on the value of source and source becomes + * 'custom'. + * + * @since 5.9.0 + * @var string + */ + public $origin; + /** * Post Id. *