From 2f6cf4ba818863ee30bb6333183f95cc25a99fc9 Mon Sep 17 00:00:00 2001 From: spacedmonkey Date: Mon, 29 Nov 2021 11:43:01 +0000 Subject: [PATCH] REST API: Ensure that the rest_after_insert_ action is executed in the templates controller. Fire the that dynamic action `rest_after_insert_{$this->post_type}` in templates controller, as this action is fired in other post based REST API controllers. Props spacedmonkey, peterwilsoncc, zieladam. Fixes #54520. Built from https://develop.svn.wordpress.org/trunk@52268 git-svn-id: http://core.svn.wordpress.org/trunk@51860 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- .../endpoints/class-wp-rest-templates-controller.php | 8 ++++++++ wp-includes/version.php | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/wp-includes/rest-api/endpoints/class-wp-rest-templates-controller.php b/wp-includes/rest-api/endpoints/class-wp-rest-templates-controller.php index 951c8232dd..16bf3c7d73 100644 --- a/wp-includes/rest-api/endpoints/class-wp-rest-templates-controller.php +++ b/wp-includes/rest-api/endpoints/class-wp-rest-templates-controller.php @@ -267,6 +267,10 @@ class WP_REST_Templates_Controller extends WP_REST_Controller { $request->set_param( 'context', 'edit' ); + $post = get_post( $template->wp_id ); + /** This action is documented in wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php */ + do_action( "rest_after_insert_{$this->post_type}", $post, $request, false ); + $response = $this->prepare_item_for_response( $template, $request ); return rest_ensure_response( $response ); @@ -310,12 +314,16 @@ class WP_REST_Templates_Controller extends WP_REST_Controller { return new WP_Error( 'rest_template_insert_error', __( 'No templates exist with that id.' ), array( 'status' => 400 ) ); } $id = $posts[0]->id; + $post = get_post( $post_id ); $template = get_block_template( $id, $this->post_type ); $fields_update = $this->update_additional_fields_for_object( $template, $request ); if ( is_wp_error( $fields_update ) ) { return $fields_update; } + /** This action is documented in wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php */ + do_action( "rest_after_insert_{$this->post_type}", $post, $request, true ); + $response = $this->prepare_item_for_response( $template, $request ); $response = rest_ensure_response( $response ); diff --git a/wp-includes/version.php b/wp-includes/version.php index 06093e8130..ff937b318c 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '5.9-alpha-52267'; +$wp_version = '5.9-alpha-52268'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.