diff --git a/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php b/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php index 4707dd4a62..2612f66c9f 100644 --- a/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php +++ b/wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php @@ -188,6 +188,18 @@ class WP_REST_Attachments_Controller extends WP_REST_Posts_Controller { } $request->set_param( 'context', 'edit' ); + + /** + * Fires after a single attachment is completely created or updated via the REST API. + * + * @since 5.0.0 + * + * @param WP_Post $attachment Inserted or updated attachment object. + * @param WP_REST_Request $request Request object. + * @param bool $creating True when creating an attachment, false when updating. + */ + do_action( 'rest_after_insert_attachment', $attachment, $request, true ); + $response = $this->prepare_item_for_response( $attachment, $request ); $response = rest_ensure_response( $response ); $response->set_status( 201 ); @@ -234,6 +246,10 @@ class WP_REST_Attachments_Controller extends WP_REST_Posts_Controller { } $request->set_param( 'context', 'edit' ); + + /** This action is documented in wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php */ + do_action( 'rest_after_insert_attachment', $attachment, $request, false ); + $response = $this->prepare_item_for_response( $attachment, $request ); $response = rest_ensure_response( $response ); diff --git a/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php b/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php index 05227a1d5f..f673450d41 100644 --- a/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php +++ b/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php @@ -633,9 +633,20 @@ class WP_REST_Comments_Controller extends WP_REST_Controller { } $context = current_user_can( 'moderate_comments' ) ? 'edit' : 'view'; - $request->set_param( 'context', $context ); + /** + * Fires completely after a comment is created or updated via the REST API. + * + * @since 5.0.0 + * + * @param WP_Comment $comment Inserted or updated comment object. + * @param WP_REST_Request $request Request object. + * @param bool $creating True when creating a comment, false + * when updating. + */ + do_action( 'rest_after_insert_comment', $comment, $request, true ); + $response = $this->prepare_item_for_response( $comment, $request ); $response = rest_ensure_response( $response ); @@ -757,6 +768,9 @@ class WP_REST_Comments_Controller extends WP_REST_Controller { $request->set_param( 'context', 'edit' ); + /** This action is documented in wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php */ + do_action( 'rest_after_insert_comment', $comment, $request, false ); + $response = $this->prepare_item_for_response( $comment, $request ); return rest_ensure_response( $response ); diff --git a/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php b/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php index 93b6608e7a..5002484ed8 100644 --- a/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php +++ b/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php @@ -608,6 +608,19 @@ class WP_REST_Posts_Controller extends WP_REST_Controller { $request->set_param( 'context', 'edit' ); + /** + * Fires after a single post is completely created or updated via the REST API. + * + * The dynamic portion of the hook name, `$this->post_type`, refers to the post type slug. + * + * @since 5.0.0 + * + * @param WP_Post $post Inserted or updated post object. + * @param WP_REST_Request $request Request object. + * @param bool $creating True when creating a post, false when updating. + */ + do_action( "rest_after_insert_{$this->post_type}", $post, $request, true ); + $response = $this->prepare_item_for_response( $post, $request ); $response = rest_ensure_response( $response ); @@ -734,6 +747,9 @@ class WP_REST_Posts_Controller extends WP_REST_Controller { $request->set_param( 'context', 'edit' ); + /** 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( $post, $request ); return rest_ensure_response( $response ); diff --git a/wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php b/wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php index 884e5f60f3..ff399cc60e 100644 --- a/wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php +++ b/wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php @@ -469,6 +469,19 @@ class WP_REST_Terms_Controller extends WP_REST_Controller { $request->set_param( 'context', 'view' ); + /** + * Fires after a single term is completely created or updated via the REST API. + * + * The dynamic portion of the hook name, `$this->taxonomy`, refers to the taxonomy slug. + * + * @since 5.0.0 + * + * @param WP_Term $term Inserted or updated term object. + * @param WP_REST_Request $request Request object. + * @param bool $creating True when creating a term, false when updating. + */ + do_action( "rest_after_insert_{$this->taxonomy}", $term, $request, true ); + $response = $this->prepare_item_for_response( $term, $request ); $response = rest_ensure_response( $response ); @@ -558,6 +571,9 @@ class WP_REST_Terms_Controller extends WP_REST_Controller { $request->set_param( 'context', 'view' ); + /** This action is documented in wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php */ + do_action( "rest_after_insert_{$this->taxonomy}", $term, $request, false ); + $response = $this->prepare_item_for_response( $term, $request ); return rest_ensure_response( $response ); diff --git a/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php b/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php index ec3f9ea204..6c9611c87b 100644 --- a/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php +++ b/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php @@ -566,6 +566,17 @@ class WP_REST_Users_Controller extends WP_REST_Controller { $request->set_param( 'context', 'edit' ); + /** + * Fires after a user is completely created or updated via the REST API. + * + * @since 5.0.0 + * + * @param WP_User $user Inserted or updated user object. + * @param WP_REST_Request $request Request object. + * @param bool $creating True when creating a user, false when updating. + */ + do_action( 'rest_after_insert_user', $user, $request, true ); + $response = $this->prepare_item_for_response( $user, $request ); $response = rest_ensure_response( $response ); @@ -689,6 +700,9 @@ class WP_REST_Users_Controller extends WP_REST_Controller { $request->set_param( 'context', 'edit' ); + /** This action is documented in wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php */ + do_action( 'rest_after_insert_user', $user, $request, false ); + $response = $this->prepare_item_for_response( $user, $request ); $response = rest_ensure_response( $response ); diff --git a/wp-includes/version.php b/wp-includes/version.php index 6707a3cb06..4edb8eb06d 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -13,7 +13,7 @@ * * @global string $wp_version */ -$wp_version = '5.1-alpha-43986'; +$wp_version = '5.1-alpha-43987'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.