From e9375e0679bc2174f4616a21af78e28290347dac Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Fri, 13 Oct 2023 12:18:19 +0000 Subject: [PATCH] Media: Consistently call the `wp_create_file_in_uploads` hook as a filter. The filter was initially introduced for file replication purposes. Since the returned value is not always used directly, some instances were later converted to an action as part of removing unused variables, and the hook was documented as an action while still being called as a filter in other instances. This commit aims to correct the discrepancy between the code and the documentation. Follow-up to [4673], [4817], [4818], [6363], [6551], [13041], [25821], [33154], [33280]. Props Howdy_McGee, nicolefurlan, johnbillion, mhshujon, SergeyBiryukov. Fixes #57775. git-svn-id: https://develop.svn.wordpress.org/trunk@56929 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/includes/class-custom-background.php | 5 +++-- src/wp-admin/includes/class-custom-image-header.php | 6 ++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/wp-admin/includes/class-custom-background.php b/src/wp-admin/includes/class-custom-background.php index b818016b28..2eb3ccfd64 100644 --- a/src/wp-admin/includes/class-custom-background.php +++ b/src/wp-admin/includes/class-custom-background.php @@ -571,8 +571,9 @@ class Custom_Background { $thumbnail = wp_get_attachment_image_src( $id, 'thumbnail' ); set_theme_mod( 'background_image_thumb', sanitize_url( $thumbnail[0] ) ); - /** This action is documented in wp-admin/includes/class-custom-image-header.php */ - do_action( 'wp_create_file_in_uploads', $file, $id ); // For replication. + /** This filter is documented in wp-admin/includes/class-custom-image-header.php */ + $file = apply_filters( 'wp_create_file_in_uploads', $file, $id ); // For replication. + $this->updated = true; } diff --git a/src/wp-admin/includes/class-custom-image-header.php b/src/wp-admin/includes/class-custom-image-header.php index 9df725af0c..ee3bcb12ec 100644 --- a/src/wp-admin/includes/class-custom-image-header.php +++ b/src/wp-admin/includes/class-custom-image-header.php @@ -882,14 +882,16 @@ endif; $this->set_header_image( compact( 'url', 'attachment_id', 'width', 'height' ) ); /** - * Fires after the header image is set or an error is returned. + * Filters the attachment file path after the custom header or background image is set. + * + * Used for file replication. * * @since 2.1.0 * * @param string $file Path to the file. * @param int $attachment_id Attachment ID. */ - do_action( 'wp_create_file_in_uploads', $file, $attachment_id ); // For replication. + $file = apply_filters( 'wp_create_file_in_uploads', $file, $attachment_id ); // For replication. return $this->finished(); } elseif ( $width > $max_width ) {