WordPress.org

Make WordPress Core

Changeset 38303


Ignore:
Timestamp:
08/22/2016 04:36:42 AM (3 years ago)
Author:
wonderboymusic
Message:

Media: add a function, wp_get_additional_image_sizes(), that wraps the retrieval of the global $_wp_additional_image_sizes. Removes 6 global imports.

See #37699.

Location:
trunk/src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/image-edit.php

    r38294 r38303  
    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;
  • trunk/src/wp-admin/includes/image.php

    r37488 r38303  
    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.
     
    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
  • trunk/src/wp-admin/includes/post.php

    r38272 r38303  
    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.
     
    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 );
  • trunk/src/wp-includes/media.php

    r38296 r38303  
    66 * @subpackage Media
    77 */
     8
     9/**
     10 * Retrieve additional image sizes.
     11 *
     12 * @since 4.7.0
     13 *
     14 * @global array $_wp_additional_image_sizes
     15 *
     16 * @return array Additional images size data.
     17 */
     18function wp_get_additional_image_sizes() {
     19    global $_wp_additional_image_sizes;
     20    if ( ! $_wp_additional_image_sizes ) {
     21        $_wp_additional_image_sizes = array();
     22    }
     23    return $_wp_additional_image_sizes;
     24}
    825
    926/**
     
    2845 *
    2946 * @global int   $content_width
    30  * @global array $_wp_additional_image_sizes
    3147 *
    3248 * @param int          $width   Width of the image in pixels.
     
    4056 */
    4157function image_constrain_size_for_editor( $width, $height, $size = 'medium', $context = null ) {
    42     global $content_width, $_wp_additional_image_sizes;
     58    global $content_width;
     59
     60    $_wp_additional_image_sizes = wp_get_additional_image_sizes();
    4361
    4462    if ( ! $context )
     
    83101            $max_width = min( intval($content_width), $max_width );
    84102        }
    85     } elseif ( isset( $_wp_additional_image_sizes ) && count( $_wp_additional_image_sizes ) && in_array( $size, array_keys( $_wp_additional_image_sizes ) ) ) {
     103    } elseif ( ! empty( $_wp_additional_image_sizes ) && in_array( $size, array_keys( $_wp_additional_image_sizes ) ) ) {
    86104        $max_width = intval( $_wp_additional_image_sizes[$size]['width'] );
    87105        $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 );
     106        // Only in admin. Assume that theme authors know what they're doing.
     107        if ( intval( $content_width ) > 0 && 'edit' === $context ) {
     108            $max_width = min( intval( $content_width ), $max_width );
     109        }
    90110    }
    91111    // $size == 'full' has no constraint
     
    259279 * @since 3.9.0
    260280 *
    261  * @global array $_wp_additional_image_sizes
    262  *
    263281 * @param string $name The image size to check.
    264282 * @return bool True if the image size exists, false if not.
    265283 */
    266284function has_image_size( $name ) {
    267     global $_wp_additional_image_sizes;
    268 
    269     return isset( $_wp_additional_image_sizes[ $name ] );
     285    $sizes = wp_get_additional_image_sizes();
     286    return isset( $sizes[ $name ] );
    270287}
    271288
     
    749766 * @since 3.0.0
    750767 *
    751  * @global array $_wp_additional_image_sizes
    752  *
    753768 * @return array Returns a filtered array of image size strings.
    754769 */
    755770function get_intermediate_image_sizes() {
    756     global $_wp_additional_image_sizes;
     771    $_wp_additional_image_sizes = wp_get_additional_image_sizes();
    757772    $image_sizes = array('thumbnail', 'medium', 'medium_large', 'large'); // Standard sizes
    758     if ( isset( $_wp_additional_image_sizes ) && count( $_wp_additional_image_sizes ) )
     773    if ( ! empty( $_wp_additional_image_sizes ) ) {
    759774        $image_sizes = array_merge( $image_sizes, array_keys( $_wp_additional_image_sizes ) );
     775    }
    760776
    761777    /**
Note: See TracChangeset for help on using the changeset viewer.