Skip to content

Commit

Permalink
WIP - origin
Browse files Browse the repository at this point in the history
  • Loading branch information
talldan committed Nov 25, 2021
1 parent 823d502 commit e0a4bd8
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/compat/wordpress-5.9/block-template-utils.php
Expand Up @@ -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 );
Expand All @@ -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;
Expand Down
Expand Up @@ -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;
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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' ),
Expand Down
10 changes: 10 additions & 0 deletions lib/full-site-editing/class-wp-block-template.php
Expand Up @@ -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.
*
Expand Down

0 comments on commit e0a4bd8

Please sign in to comment.