Make WordPress Core

Ticket #18947: 18947_5_2.patch

File 18947_5_2.patch, 1.4 KB (added by F J Kaiser, 11 years ago)

For the sake of discussion, here's a second patch which moves the additional functionality outside the originally patched function and builds upon it.

  • wp-includes/media.php

    From 63a92698d05d6f13920d72ebaeeb831475466805 Mon Sep 17 00:00:00 2001
    From: Kaiser Franz Josef <wecodemore@gmail.com>
    Date: Sun, 25 May 2014 14:36:19 +0200
    Subject: [PATCH] Added new function get_images_sizes_data() that returns an
     array of registered image sizes alongside their width, height and crop value
    
    ---
     wp-includes/media.php | 23 +++++++++++++++++++++++
     1 file changed, 23 insertions(+)
    
    diff --git a/wp-includes/media.php b/wp-includes/media.php
    index f9b47e4..b695527 100644
    a b function get_intermediate_image_sizes() { 
    643643}
    644644
    645645/**
     646 * Get an array of image size names with their width, height and crop value.
     647 * @uses get_intermediate_image_sizes()
     648 * @since 4.0.0
     649 * @return array
     650 */
     651function get_image_sizes_data() {
     652        $image_sizes = get_intermediate_image_sizes();
     653
     654        $result = array();
     655        foreach ( $image_sizes as $size ) {
     656                $result[ $size ]['width']  = absint( get_option( "{$size}_size_w" ) );
     657                $result[ $size ]['height'] = absint( get_option( "{$size}_size_h" ) );
     658                // If not set: crop false per default.
     659                $result[ $size ]['crop']   = false;
     660                if ( get_option( "{$size}_crop" ) ) {
     661                        $result[ $size ]['crop'] = get_option( "{$size}_crop" );
     662                }
     663        }
     664
     665        return $result;
     666}
     667
     668/**
    646669 * Retrieve an image to represent an attachment.
    647670 *
    648671 * A mime icon for files, thumbnail or intermediate size for images.