Make WordPress Core

Ticket #37699: 37699-images.diff

File 37699-images.diff, 7.2 KB (added by wonderboymusic, 9 years ago)
  • src/wp-admin/includes/image-edit.php

     
    700700 * Saves image to post along with enqueued changes
    701701 * in $_REQUEST['history']
    702702 *
    703  * @global array $_wp_additional_image_sizes
    704  *
    705703 * @param int $post_id
    706704 * @return \stdClass
    707705 */
    708706function wp_save_image( $post_id ) {
    709         global $_wp_additional_image_sizes;
     707        $_wp_additional_image_sizes = wp_get_additional_image_sizes();
    710708
    711709        $return = new stdClass;
    712710        $success = $delete = $scaled = $nocrop = false;
  • src/wp-admin/includes/image.php

     
    6767 *
    6868 * @since 2.1.0
    6969 *
    70  * @global array $_wp_additional_image_sizes
    71  *
    7270 * @param int $attachment_id Attachment Id to process.
    7371 * @param string $file Filepath of the Attached image.
    7472 * @return mixed Metadata for attachment.
     
    8785                $metadata['file'] = _wp_relative_upload_path($file);
    8886
    8987                // Make thumbnails and other intermediate sizes.
    90                 global $_wp_additional_image_sizes;
     88                $_wp_additional_image_sizes = wp_get_additional_image_sizes();
    9189
    9290                $sizes = array();
    9391                foreach ( get_intermediate_image_sizes() as $s ) {
    9492                        $sizes[$s] = array( 'width' => '', 'height' => '', 'crop' => false );
    95                         if ( isset( $_wp_additional_image_sizes[$s]['width'] ) )
    96                                 $sizes[$s]['width'] = intval( $_wp_additional_image_sizes[$s]['width'] ); // For theme-added sizes
    97                         else
    98                                 $sizes[$s]['width'] = get_option( "{$s}_size_w" ); // For default sizes set in options
    99                         if ( isset( $_wp_additional_image_sizes[$s]['height'] ) )
    100                                 $sizes[$s]['height'] = intval( $_wp_additional_image_sizes[$s]['height'] ); // For theme-added sizes
    101                         else
    102                                 $sizes[$s]['height'] = get_option( "{$s}_size_h" ); // For default sizes set in options
    103                         if ( isset( $_wp_additional_image_sizes[$s]['crop'] ) )
    104                                 $sizes[$s]['crop'] = $_wp_additional_image_sizes[$s]['crop']; // For theme-added sizes
    105                         else
    106                                 $sizes[$s]['crop'] = get_option( "{$s}_crop" ); // For default sizes set in options
     93                        if ( isset( $_wp_additional_image_sizes[$s]['width'] ) ) {
     94                                // For theme-added sizes
     95                                $sizes[$s]['width'] = intval( $_wp_additional_image_sizes[$s]['width'] );
     96                        } else {
     97                                // For default sizes set in options
     98                                $sizes[$s]['width'] = get_option( "{$s}_size_w" );
     99                        }
     100
     101                        if ( isset( $_wp_additional_image_sizes[$s]['height'] ) ) {
     102                                // For theme-added sizes
     103                                $sizes[$s]['height'] = intval( $_wp_additional_image_sizes[$s]['height'] );
     104                        } else {
     105                                // For default sizes set in options
     106                                $sizes[$s]['height'] = get_option( "{$s}_size_h" );
     107                        }
     108
     109                        if ( isset( $_wp_additional_image_sizes[$s]['crop'] ) ) {
     110                                // For theme-added sizes
     111                                $sizes[$s]['crop'] = $_wp_additional_image_sizes[$s]['crop'];
     112                        } else {
     113                                // For default sizes set in options
     114                                $sizes[$s]['crop'] = get_option( "{$s}_crop" );
     115                        }
    107116                }
    108117
    109118                /**
  • src/wp-admin/includes/post.php

     
    13671367 *
    13681368 * @since 2.9.0
    13691369 *
    1370  * @global array $_wp_additional_image_sizes
    1371  *
    13721370 * @param int $thumbnail_id ID of the attachment used for thumbnail
    13731371 * @param mixed $post The post ID or object associated with the thumbnail, defaults to global $post.
    13741372 * @return string html
    13751373 */
    13761374function _wp_post_thumbnail_html( $thumbnail_id = null, $post = null ) {
    1377         global $_wp_additional_image_sizes;
     1375        $_wp_additional_image_sizes = wp_get_additional_image_sizes();
    13781376
    13791377        $post               = get_post( $post );
    13801378        $post_type_object   = get_post_type_object( $post->post_type );
  • src/wp-includes/media.php

     
    77 */
    88
    99/**
     10 * Retrieve additional image sizes.
     11 *
     12 * @since 4.7.0
     13 *
     14 * @global array $_wp_additional_image_sizes
     15 */
     16function wp_get_additional_image_sizes() {
     17        global $_wp_additional_image_sizes;
     18        if ( ! $_wp_additional_image_sizes ) {
     19                $_wp_additional_image_sizes = array();
     20        }
     21        return $_wp_additional_image_sizes;
     22}
     23
     24/**
    1025 * Scale down the default size of an image.
    1126 *
    1227 * This is so that the image is a better fit for the editor and theme.
     
    2742 * @since 2.5.0
    2843 *
    2944 * @global int   $content_width
    30  * @global array $_wp_additional_image_sizes
    3145 *
    3246 * @param int          $width   Width of the image in pixels.
    3347 * @param int          $height  Height of the image in pixels.
     
    3953 * @return array Width and height of what the result image should resize to.
    4054 */
    4155function image_constrain_size_for_editor( $width, $height, $size = 'medium', $context = null ) {
    42         global $content_width, $_wp_additional_image_sizes;
     56        global $content_width;
    4357
     58        $_wp_additional_image_sizes = wp_get_additional_image_sizes();
     59
    4460        if ( ! $context )
    4561                $context = is_admin() ? 'edit' : 'display';
    4662
     
    8298                if ( intval($content_width) > 0 ) {
    8399                        $max_width = min( intval($content_width), $max_width );
    84100                }
    85         } elseif ( isset( $_wp_additional_image_sizes ) && count( $_wp_additional_image_sizes ) && in_array( $size, array_keys( $_wp_additional_image_sizes ) ) ) {
     101        } elseif ( ! empty( $_wp_additional_image_sizes ) && in_array( $size, array_keys( $_wp_additional_image_sizes ) ) ) {
    86102                $max_width = intval( $_wp_additional_image_sizes[$size]['width'] );
    87103                $max_height = intval( $_wp_additional_image_sizes[$size]['height'] );
    88                 if ( intval($content_width) > 0 && 'edit' == $context ) // Only in admin. Assume that theme authors know what they're doing.
    89                         $max_width = min( intval($content_width), $max_width );
     104                // Only in admin. Assume that theme authors know what they're doing.
     105                if ( intval( $content_width ) > 0 && 'edit' === $context ) {
     106                        $max_width = min( intval( $content_width ), $max_width );
     107                }
    90108        }
    91109        // $size == 'full' has no constraint
    92110        else {
     
    258276 *
    259277 * @since 3.9.0
    260278 *
    261  * @global array $_wp_additional_image_sizes
    262  *
    263279 * @param string $name The image size to check.
    264280 * @return bool True if the image size exists, false if not.
    265281 */
    266282function has_image_size( $name ) {
    267         global $_wp_additional_image_sizes;
    268 
    269         return isset( $_wp_additional_image_sizes[ $name ] );
     283        $sizes = wp_get_additional_image_sizes();
     284        return isset( $sizes[ $name ] );
    270285}
    271286
    272287/**
     
    748763 *
    749764 * @since 3.0.0
    750765 *
    751  * @global array $_wp_additional_image_sizes
    752  *
    753766 * @return array Returns a filtered array of image size strings.
    754767 */
    755768function get_intermediate_image_sizes() {
    756         global $_wp_additional_image_sizes;
     769        $_wp_additional_image_sizes = wp_get_additional_image_sizes();
    757770        $image_sizes = array('thumbnail', 'medium', 'medium_large', 'large'); // Standard sizes
    758         if ( isset( $_wp_additional_image_sizes ) && count( $_wp_additional_image_sizes ) )
     771        if ( ! empty( $_wp_additional_image_sizes ) ) {
    759772                $image_sizes = array_merge( $image_sizes, array_keys( $_wp_additional_image_sizes ) );
     773        }
    760774
    761775        /**
    762776         * Filters the list of intermediate image sizes.