Skip to content

Commit

Permalink
Replicate more core changes in gutenberg
Browse files Browse the repository at this point in the history
  • Loading branch information
talldan committed Nov 29, 2021
1 parent bd3680c commit 33f0890
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
Expand Up @@ -245,6 +245,10 @@ public function update_item( $request ) {

$changes = $this->prepare_item_for_database( $request );

if ( is_wp_error( $changes ) ) {
return $changes;
}

if ( 'custom' === $template->source ) {
$result = wp_update_post( wp_slash( (array) $changes ), true );
} else {
Expand Down Expand Up @@ -283,7 +287,12 @@ public function create_item_permissions_check( $request ) {
* @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
*/
public function create_item( $request ) {
$changes = $this->prepare_item_for_database( $request );
$changes = $this->prepare_item_for_database( $request );

if ( is_wp_error( $changes ) ) {
return $changes;
}

$changes->post_name = $request['slug'];
$result = wp_insert_post( wp_slash( (array) $changes ), true );
if ( is_wp_error( $result ) ) {
Expand Down Expand Up @@ -385,7 +394,9 @@ protected function prepare_item_for_database( $request ) {
$changes->tax_input = array(
'wp_theme' => $template->theme,
);
$changes->origin = $template->source;
$changes->meta_input = array(
'origin' => $template->source,
);
} else {
$changes->post_name = $template->slug;
$changes->ID = $template->wp_id;
Expand Down Expand Up @@ -599,7 +610,7 @@ public function get_item_schema() {
'context' => array( 'embed', 'view', 'edit' ),
'readonly' => true,
),
'source' => array(
'origin' => array(
'description' => __( 'Source of customized template', 'gutenberg' ),
'type' => 'string',
'context' => array( 'embed', 'view', 'edit' ),
Expand Down
1 change: 0 additions & 1 deletion lib/full-site-editing/class-wp-block-template.php
Expand Up @@ -72,7 +72,6 @@ class WP_Block_Template {
* When customized, origin takes on the value of source and source becomes
* 'custom'.
*
* @since 5.9.0
* @var string
*/
public $origin;
Expand Down

0 comments on commit 33f0890

Please sign in to comment.