From 00d369692334486aafc204d275bf3082c0c680a7 Mon Sep 17 00:00:00 2001 From: whyisjake Date: Thu, 4 Jun 2020 15:00:09 +0000 Subject: [PATCH] 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. Built from https://develop.svn.wordpress.org/trunk@47909 git-svn-id: http://core.svn.wordpress.org/trunk@47683 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/includes/media.php | 19 +++++++++++++++---- wp-includes/version.php | 2 +- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/wp-admin/includes/media.php b/wp-admin/includes/media.php index feebbd9bff..35080275ed 100644 --- a/wp-admin/includes/media.php +++ b/wp-admin/includes/media.php @@ -3724,13 +3724,24 @@ function wp_media_attach_action( $parent_id, $action = 'attach' ) { } else { $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 ) ) { + 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'; $referer = wp_get_referer(); diff --git a/wp-includes/version.php b/wp-includes/version.php index cc749f776b..0e4a6d016e 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -13,7 +13,7 @@ * * @global string $wp_version */ -$wp_version = '5.5-alpha-47908'; +$wp_version = '5.5-alpha-47909'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.