rest_insert_attachment
Action HookDescription
Fires after a single attachment is created or updated via the REST API.Hook Information
File Location |
wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php
View on GitHub
|
Hook Type | Action |
Line Number | 384 |
Hook Parameters
Type | Name | Description |
---|---|---|
WP_Post
|
$attachment
|
Inserted or updated attachment object. |
WP_REST_Request
|
$request
|
The request sent to the API. |
bool
|
$creating
|
True when creating an attachment, false when updating. |
Usage Examples
Basic Usage
<?php
// Hook into rest_insert_attachment
add_action('rest_insert_attachment', 'my_custom_function', 10, 3);
function my_custom_function($attachment, $request, $creating) {
// Your custom code here
}
Source Code Context
wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php:384
- How this hook is used in WordPress core
<?php
379 *
380 * @param WP_Post $attachment Inserted or updated attachment object.
381 * @param WP_REST_Request $request The request sent to the API.
382 * @param bool $creating True when creating an attachment, false when updating.
383 */
384 do_action( 'rest_insert_attachment', $attachment, $request, true );
385
386 return array(
387 'attachment_id' => $id,
388 'file' => $file,
389 );
PHP Documentation
<?php
/**
* Fires after a single attachment is created or updated via the REST API.
*
* @since 4.7.0
*
* @param WP_Post $attachment Inserted or updated attachment object.
* @param WP_REST_Request $request The request sent to the API.
* @param bool $creating True when creating an attachment, false when updating.
*/
Quick Info
- Hook Type: Action
- Parameters: 3
- File: wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php
Related Hooks
Related hooks will be displayed here in future updates.