rest_insert_attachment
Fires after a single attachment is created or updated via the REST API.
Description
do_action( 'rest_insert_attachment', (WP_Post) $attachment, (WP_REST_Request) $request, (bool) $true );
Parameters (3)
- 0. $attachment (WP_Post)
- Inserted or updated attachment object.
- 1. $request (WP_REST_Request)
- The request sent to the API.
- 2. $true (bool) =>
true
- True when creating an attachment, false when updating.
Usage
- To run the hook, copy the example below.
- // run the action
- do_action( 'rest_insert_attachment', $attachment, $request, $true );
- The following example is for adding a hook callback.
- // define the rest_insert_attachment callback
- function action_rest_insert_attachment( $attachment, $request, $true ) {
- // make action magic happen here...
- };
- // add the action
- add_action( 'rest_insert_attachment', 'action_rest_insert_attachment', 10, 3 );
- To remove a hook callback, use the example below.
- // remove the action
- remove_action( 'rest_insert_attachment', 'action_rest_insert_attachment', 10, 3 );
Defined (2)
The action is defined in the following location(s).
- /wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php
- do_action( 'rest_insert_attachment', $attachment, $request, true );
- do_action( 'rest_insert_attachment', $data, $request, false );