From 9da9eeaa9d77db91a6b44b9c8a37f19c5b0b7ba3 Mon Sep 17 00:00:00 2001 From: Daniel Richards Date: Thu, 25 Nov 2021 19:12:59 +0800 Subject: [PATCH] Replicate more core changes in gutenberg --- ...lass-gutenberg-rest-templates-controller.php | 17 ++++++++++++++--- .../class-wp-block-template.php | 1 - 2 files changed, 14 insertions(+), 4 deletions(-) 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 e35214bbca1ec..0a793583873bd 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 @@ -214,6 +214,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 { @@ -252,7 +256,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 ) ) { @@ -354,7 +363,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; @@ -564,7 +575,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' ), diff --git a/lib/full-site-editing/class-wp-block-template.php b/lib/full-site-editing/class-wp-block-template.php index 397d864f941b4..0068ebb6eec90 100644 --- a/lib/full-site-editing/class-wp-block-template.php +++ b/lib/full-site-editing/class-wp-block-template.php @@ -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;