Make WordPress Core

Ticket #48522: 48522.2.diff

File 48522.2.diff, 3.8 KB (added by vanyukov, 5 years ago)
  • wp-admin/async-upload.php

     
    9090        }
    9191}
    9292
    93 $id = media_handle_upload( 'async-upload', $post_id );
     93try {
     94        $id = media_handle_upload( 'async-upload', $post_id );
     95} catch ( Exception $e ) {
     96        printf(
     97                '<div class="error-div error">%s <strong>%s</strong></div>',
     98                sprintf(
     99                        '<button type="button" class="dismiss button-link" onclick="jQuery(this).parents(\'div.media-item\').slideUp(200, function(){jQuery(this).remove();});">%s</button>',
     100                        __( 'Dismiss' )
     101                ),
     102                sprintf(
     103                /* translators: %s: Name of the file that failed to upload. */
     104                        __( '&#8220;%s&#8221;: %s.' ),
     105                        esc_html( $_FILES['async-upload']['name'] ),
     106                        $e->getMessage(),
     107                )
     108        );
     109        exit;
     110}
     111
    94112if ( is_wp_error( $id ) ) {
    95113        printf(
    96114                '<div class="error-div error">%s <strong>%s</strong><br />%s</div>',
  • wp-admin/includes/image.php

     
    244244                $image_meta['image_meta'] = $exif_meta;
    245245        }
    246246
     247        // Initial save of the new metadata.
     248        // At this point the file was uploaded and moved to the uploads directory
     249        // but the image sub-sizes haven't been created yet and the `sizes` array is empty.
     250        wp_update_attachment_metadata( $attachment_id, $image_meta );
     251
     252        $new_sizes = wp_get_registered_image_subsizes();
     253
     254        /**
     255         * Filters the image sizes automatically generated when uploading an image.
     256         *
     257         * @since 2.9.0
     258         * @since 4.4.0 Added the `$image_meta` argument.
     259         * @since 5.3.0 Added the `$attachment_id` argument.
     260         *
     261         * @param array $new_sizes     Associative array of image sizes to be created.
     262         * @param array $image_meta    The image meta data: width, height, file, sizes, etc.
     263         * @param int   $attachment_id The attachment post ID for the image.
     264         */
     265        $new_sizes = apply_filters( 'intermediate_image_sizes_advanced', $new_sizes, $image_meta, $attachment_id );
     266
     267        $image_meta = _wp_make_subsizes( $new_sizes, $file, $image_meta, $attachment_id );
     268
    247269        /**
    248270         * Filters the "BIG image" threshold value.
    249271         *
     
    303325                                // TODO: log errors.
    304326                        }
    305327                } else {
    306                         // TODO: log errors.
     328                        $error_code = $resized->get_error_code();
     329
     330                        // The `error_getting_dimensions` error code means the original image is not large enough
     331                        // to create the requested sub-size. (Checked here for completeness.)
     332                        if ( $error_code !== 'error_getting_dimensions' ) {
     333                                throw new Exception( __( 'Could not generate scaled image' ) );
     334                        }
    307335                }
    308336        } elseif ( ! empty( $exif_meta['orientation'] ) && (int) $exif_meta['orientation'] !== 1 ) {
    309337                // Rotate the whole original image if there is EXIF data and "orientation" is not 1.
     
    335363                }
    336364        }
    337365
    338         // Initial save of the new metadata.
    339         // At this point the file was uploaded and moved to the uploads directory
    340         // but the image sub-sizes haven't been created yet and the `sizes` array is empty.
    341         wp_update_attachment_metadata( $attachment_id, $image_meta );
    342 
    343         $new_sizes = wp_get_registered_image_subsizes();
    344 
    345         /**
    346          * Filters the image sizes automatically generated when uploading an image.
    347          *
    348          * @since 2.9.0
    349          * @since 4.4.0 Added the `$image_meta` argument.
    350          * @since 5.3.0 Added the `$attachment_id` argument.
    351          *
    352          * @param array $new_sizes     Associative array of image sizes to be created.
    353          * @param array $image_meta    The image meta data: width, height, file, sizes, etc.
    354          * @param int   $attachment_id The attachment post ID for the image.
    355          */
    356         $new_sizes = apply_filters( 'intermediate_image_sizes_advanced', $new_sizes, $image_meta, $attachment_id );
    357 
    358         return _wp_make_subsizes( $new_sizes, $file, $image_meta, $attachment_id );
     366        return $image_meta;
    359367}
    360368
    361369/**