Media: Move `wp_default_image_output_mapping()` filter callback to frontend scope.

While the `image_editor_output_format` filter is primarily used in WP Admin, it can also be executed in frontend scope, as the related `WP_Image_Editor` class and `wp_unique_filename()` function are being loaded in that scope.

Follow up to [54086].

See #55443, #56526.

Built from https://develop.svn.wordpress.org/trunk@54094


git-svn-id: http://core.svn.wordpress.org/trunk@53653 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Felix Arntz 2022-09-07 15:41:15 +00:00
parent ca1a756ff2
commit 42416cf392
5 changed files with 18 additions and 18 deletions

View File

@ -37,8 +37,6 @@ add_filter( 'media_upload_library', 'media_upload_library' );
add_filter( 'media_upload_tabs', 'update_gallery_tab' ); add_filter( 'media_upload_tabs', 'update_gallery_tab' );
add_filter( 'image_editor_output_format', 'wp_default_image_output_mapping' );
// Admin color schemes. // Admin color schemes.
add_action( 'admin_init', 'register_admin_color_schemes', 1 ); add_action( 'admin_init', 'register_admin_color_schemes', 1 );
add_action( 'admin_head', 'wp_color_scheme_settings' ); add_action( 'admin_head', 'wp_color_scheme_settings' );

View File

@ -3843,18 +3843,3 @@ function wp_media_attach_action( $parent_id, $action = 'attach' ) {
exit; exit;
} }
} }
/**
* Filters the default image output mapping.
*
* With this filter callback, WebP image files will be generated for certain JPEG source files.
*
* @since 6.1.0
*
* @param array $output_mapping Map of mime type to output format.
* @retun array The adjusted default output mapping.
*/
function wp_default_image_output_mapping( $output_mapping ) {
$output_mapping['image/jpeg'] = 'image/webp';
return $output_mapping;
}

View File

@ -632,6 +632,8 @@ add_action( 'media_buttons', 'media_buttons' );
add_filter( 'image_send_to_editor', 'image_add_caption', 20, 8 ); add_filter( 'image_send_to_editor', 'image_add_caption', 20, 8 );
add_filter( 'media_send_to_editor', 'image_media_send_to_editor', 10, 3 ); add_filter( 'media_send_to_editor', 'image_media_send_to_editor', 10, 3 );
add_filter( 'image_editor_output_format', 'wp_default_image_output_mapping' );
// Embeds. // Embeds.
add_action( 'rest_api_init', 'wp_oembed_register_route' ); add_action( 'rest_api_init', 'wp_oembed_register_route' );
add_filter( 'rest_pre_serve_request', '_oembed_rest_pre_serve_request', 10, 4 ); add_filter( 'rest_pre_serve_request', '_oembed_rest_pre_serve_request', 10, 4 );

View File

@ -3904,6 +3904,21 @@ function _wp_image_editor_choose( $args = array() ) {
return false; return false;
} }
/**
* Filters the default image output mapping.
*
* With this filter callback, WebP image files will be generated for certain JPEG source files.
*
* @since 6.1.0
*
* @param array $output_mapping Map of mime type to output format.
* @retun array The adjusted default output mapping.
*/
function wp_default_image_output_mapping( $output_mapping ) {
$output_mapping['image/jpeg'] = 'image/webp';
return $output_mapping;
}
/** /**
* Prints default Plupload arguments. * Prints default Plupload arguments.
* *

View File

@ -16,7 +16,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '6.1-alpha-54093'; $wp_version = '6.1-alpha-54094';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.