Skip to content

Commit

Permalink
Media: Move wp_default_image_output_mapping() filter callback to fr…
Browse files Browse the repository at this point in the history
…ontend 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
  • Loading branch information
flixos90 committed Sep 7, 2022
1 parent a4399e8 commit 365cf32
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 18 deletions.
2 changes: 0 additions & 2 deletions wp-admin/includes/admin-filters.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@

add_filter( 'media_upload_tabs', 'update_gallery_tab' );

add_filter( 'image_editor_output_format', 'wp_default_image_output_mapping' );

// Admin color schemes.
add_action( 'admin_init', 'register_admin_color_schemes', 1 );
add_action( 'admin_head', 'wp_color_scheme_settings' );
Expand Down
15 changes: 0 additions & 15 deletions wp-admin/includes/media.php
Original file line number Diff line number Diff line change
Expand Up @@ -3843,18 +3843,3 @@ function wp_media_attach_action( $parent_id, $action = 'attach' ) {
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;
}
2 changes: 2 additions & 0 deletions wp-includes/default-filters.php
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,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( 'image_editor_output_format', 'wp_default_image_output_mapping' );

// Embeds.
add_action( 'rest_api_init', 'wp_oembed_register_route' );
add_filter( 'rest_pre_serve_request', '_oembed_rest_pre_serve_request', 10, 4 );
Expand Down
15 changes: 15 additions & 0 deletions wp-includes/media.php
Original file line number Diff line number Diff line change
Expand Up @@ -3904,6 +3904,21 @@ function _wp_image_editor_choose( $args = array() ) {
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.
*
Expand Down
2 changes: 1 addition & 1 deletion wp-includes/version.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*
* @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.
Expand Down

0 comments on commit 365cf32

Please sign in to comment.