WordPress.org

Make WordPress Core

Ticket #18947: 18947_6.patch

File 18947_6.patch, 1.5 KB (added by johnnyb, 4 years ago)

Adds a get_image_size() (singular) function. Very similar to @krogsgard's code in comment 16.

  • wp-includes/media.php

    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
     
    277277        return false;
    278278}
    279279
     280
     281/**
     282 * Gets the width, height, and cropping behaviour of the named image size specified by $size.
     283 *
     284 * @see add_image_size() for details on cropping behaviour.
     285 *
     286 * @global array $_wp_additional_image_sizes Associative array of additional image sizes.
     287 *
     288 * @param string $size  A named image size, either built-in or added to WordPress using add_image_size()
     289 *
     290 * @return array|bool   Associative array with 'width', 'height', and (boolean) crop. These correspond to arguments
     291 *                      for add_image_size();
     292 */
     293function get_image_size( $size = '' ) {
     294
     295
     296
     297        $size_atts = false;
     298
     299        if ( in_array( $size, array( 'thumbnail', 'medium', 'large' ) ) ) {
     300
     301                $size_atts = array(
     302                        'width'  => get_option( $size . '_size_w' ),
     303                        'height' => get_option( $size . '_size_h' ),
     304                        'crop'   => (bool) get_option( $size . '_crop' )
     305                );
     306
     307        } elseif ( has_image_size( $size ) ) {
     308
     309                global $_wp_additional_image_sizes;
     310                $size_atts = array(
     311                        'width'  => $_wp_additional_image_sizes[ $size ]['width'],
     312                        'height' => $_wp_additional_image_sizes[ $size ]['height'],
     313                        'crop'   => (bool) $_wp_additional_image_sizes[ $size ]['crop']
     314                );
     315        }
     316
     317        return $size_atts;
     318}
     319
     320
    280321/**
    281322 * Registers an image size for the post thumbnail.
    282323 *