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.
  1. // run the action 
  2. do_action( 'rest_insert_attachment', $attachment, $request, $true ); 
The following example is for adding a hook callback.
  1. // define the rest_insert_attachment callback 
  2. function action_rest_insert_attachment( $attachment, $request, $true ) { 
  3. // make action magic happen here... 
  4. }; 
  5.  
  6. // add the action 
  7. add_action( 'rest_insert_attachment', 'action_rest_insert_attachment', 10, 3 ); 
To remove a hook callback, use the example below.
  1. // remove the action 
  2. 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  
  1. do_action( 'rest_insert_attachment', $attachment, $request, true ); 
  1. do_action( 'rest_insert_attachment', $data, $request, false );