rest_insert_<post_type>
Fires after a single post is created or updated via the REST API.
Description
The dynamic portion(s) of the hook name refer to the post type slug.
Parameters (3)
- 0. $post (WP_Post)
- Inserted or updated post object.
- 1. $request (WP_REST_Request)
- Request object.
- 2. $true (bool) =>
true
- True when creating a post, false when updating.
Usage
- To run the hook, copy the example below.
- // run the action
- do_action( 'rest_insert_{$post_type}', $post, $request, $true );
- The following example is for adding a hook callback.
- // define the rest_insert_<post_type> callback
- function action_rest_insert_post_type( $post, $request, $true ) {
- // make action magic happen here...
- };
- // add the action
- add_action( "rest_insert_{$post_type}", 'action_rest_insert_post_type', 10, 3 );
- To remove a hook callback, use the example below.
- // remove the action
- remove_action( "rest_insert_{$post_type}", 'action_rest_insert_post_type', 10, 3 );
Defined (2)
The action is defined in the following location(s).
- /wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php
- do_action( "rest_insert_{$this->post_type}", $post, $request, true );
- do_action( "rest_insert_{$this->post_type}", $post, $request, false );