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
This commit is contained in:
spacedmonkey 2021-11-29 11:43:01 +00:00
parent 0ca6469410
commit 2f6cf4ba81
2 changed files with 9 additions and 1 deletions

View File

@ -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 );

View File

@ -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.