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.

git-svn-id: https://develop.svn.wordpress.org/trunk@52268 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Jonny Harris 2021-11-29 11:41:50 +00:00
parent 64b7eb383a
commit 4ff41edf97

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