Media: Add an action for `wp_media_attach_action`.

This action fires when media is attached/detached from a post.

Fixes: #49614.
Props: jonoaldersonwp, antpb, rebasaurus, donmhico. 



git-svn-id: https://develop.svn.wordpress.org/trunk@47909 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Jake Spurlock 2020-06-04 14:58:58 +00:00
parent cc62b4ba1d
commit 5b2eaae4cf
1 changed files with 15 additions and 4 deletions

View File

@ -3724,13 +3724,24 @@ function wp_media_attach_action( $parent_id, $action = 'attach' ) {
} else { } else {
$result = $wpdb->query( "UPDATE $wpdb->posts SET post_parent = 0 WHERE post_type = 'attachment' AND ID IN ( $ids_string )" ); $result = $wpdb->query( "UPDATE $wpdb->posts SET post_parent = 0 WHERE post_type = 'attachment' AND ID IN ( $ids_string )" );
} }
foreach ( $ids as $att_id ) {
clean_attachment_cache( $att_id );
}
} }
if ( isset( $result ) ) { if ( isset( $result ) ) {
foreach ( $ids as $att_id ) {
/**
* Fires when media is attached/detached from a post.
*
* @since 5.5
*
* @param string $action Attach/detach action.
* @param int $att_id The attachment ID.
* @param int $parent_id Attachment parent ID.
*/
do_action( 'wp_media_attach_action', $action, $att_id, $parent_id );
clean_attachment_cache( $att_id );
}
$location = 'upload.php'; $location = 'upload.php';
$referer = wp_get_referer(); $referer = wp_get_referer();