From 9d00289c601a34f2cd89f84eae0c3f7379d7356b Mon Sep 17 00:00:00 2001 From: Andrew Ozz Date: Tue, 16 Jul 2019 21:47:35 +0000 Subject: [PATCH] Media: Sort the new sizes array by priority when creating image sub-sizes. See #40439. git-svn-id: https://develop.svn.wordpress.org/trunk@45645 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/includes/image.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/wp-admin/includes/image.php b/src/wp-admin/includes/image.php index 374bde41c8..9328b1d7d3 100644 --- a/src/wp-admin/includes/image.php +++ b/src/wp-admin/includes/image.php @@ -227,6 +227,18 @@ function _wp_make_subsizes( $new_sizes, $file, $image_meta, $attachment_id ) { } if ( ! empty( $new_sizes ) ) { + // Sort the image sub-sizes in order of priority when creating them. + // This ensures there is an appropriate sub-size the user can access immediately + // even when there was an error and not all sub-sizes were created. + $priority = array( + 'medium' => null, + 'large' => null, + 'thumbnail' => null, + 'medium_large' => null, + ); + + $new_sizes = array_filter( array_merge( $priority, $new_sizes ) ); + $editor = wp_get_image_editor( $file ); if ( ! is_wp_error( $editor ) ) {