wp_media_attach_action
Action HookDescription
Fires when media is attached or detached from a post.Hook Information
File Location |
wp-admin/includes/media.php
View on GitHub
|
Hook Type | Action |
Line Number | 3870 |
Hook Parameters
Type | Name | Description |
---|---|---|
string
|
$action
|
Attach/detach action. Accepts 'attach' or 'detach'. |
int
|
$attachment_id
|
The attachment ID. |
int
|
$parent_id
|
Attachment parent ID. |
Usage Examples
Basic Usage
<?php
// Hook into wp_media_attach_action
add_action('wp_media_attach_action', 'my_custom_function', 10, 3);
function my_custom_function($action, $attachment_id, $parent_id) {
// Your custom code here
}
Source Code Context
wp-admin/includes/media.php:3870
- How this hook is used in WordPress core
<?php
3865 *
3866 * @param string $action Attach/detach action. Accepts 'attach' or 'detach'.
3867 * @param int $attachment_id The attachment ID.
3868 * @param int $parent_id Attachment parent ID.
3869 */
3870 do_action( 'wp_media_attach_action', $action, $attachment_id, $parent_id );
3871
3872 clean_attachment_cache( $attachment_id );
3873 }
3874
3875 $location = 'upload.php';
PHP Documentation
<?php
/**
* Fires when media is attached or detached from a post.
*
* @since 5.5.0
*
* @param string $action Attach/detach action. Accepts 'attach' or 'detach'.
* @param int $attachment_id The attachment ID.
* @param int $parent_id Attachment parent ID.
*/
Quick Info
- Hook Type: Action
- Parameters: 3
- File: wp-admin/includes/media.php
Related Hooks
Related hooks will be displayed here in future updates.