From c12992dc9a276a0d03c86a644f649c8260730ceb Mon Sep 17 00:00:00 2001 From: Jb Audras Date: Fri, 20 Jan 2023 14:15:42 +0000 Subject: [PATCH] Media: Add an action hook on `wp_ajax_save_attachment()`. This changeset introduces the `wp_ajax_save_attachment` action hook, triggered after an attachment has been updated and before the JSON response is sent. For example, it allows developers to update any additional attachment fields that have been rendered by extending the `media.view.Attachment.Details` subview. Props griffinjt, bradyvercher, pputzer, antpb, sc0ttkclark, audrasjb, costdev, hellofromTonya. Fixes #23148. git-svn-id: https://develop.svn.wordpress.org/trunk@55106 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/includes/ajax-actions.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/wp-admin/includes/ajax-actions.php b/src/wp-admin/includes/ajax-actions.php index 995433eaba..2fd1662800 100644 --- a/src/wp-admin/includes/ajax-actions.php +++ b/src/wp-admin/includes/ajax-actions.php @@ -3144,6 +3144,17 @@ function wp_ajax_save_attachment() { wp_delete_post( $id ); } else { wp_update_post( $post ); + + /** + * Fires after an attachment has been updated and before + * the JSON response is sent. + * + * @since 6.2.0 + * + * @param array $post The attachment. + * @param array $changes An array of changes. + */ + do_action( 'wp_ajax_save_attachment', $post, $changes ); } wp_send_json_success();