[wp-trac] [WordPress Trac] #18947: get_intermediate_image_sizes() should also contain width/height/crop values as sub array

WordPress Trac noreply at wordpress.org
Mon Jun 2 19:54:34 UTC 2014


#18947: get_intermediate_image_sizes() should also contain width/height/crop values
as sub array
-----------------------------------+-----------------------
 Reporter:  F J Kaiser             |       Owner:
     Type:  enhancement            |      Status:  assigned
 Priority:  normal                 |   Milestone:  4.0
Component:  Media                  |     Version:  3.2.1
 Severity:  normal                 |  Resolution:
 Keywords:  has-patch 2nd-opinion  |     Focuses:
-----------------------------------+-----------------------

Comment (by F J Kaiser):

 Replying to [comment:13 ericlewis]:
 > Custom image sizes width/height info is not stored in the database,
 there should be a fallback to go to the `global
 $_wp_addtional_image_sizes` array to fetch this data.

 Actually the options have defaults... well, partly. I took a clean
 (single- as well as multi-site) install, added a blank dev/test theme
 (nothing aside from an empty style.css, index.php and functions.php) and
 wrote the following (mu-)plugin to confirm:


 {{{
 <?php
 /** Plugin Name: (dev) Options and Globals dump on shotdown */

 /**/
 add_action( 'shutdown', function()
 {
         $defaults = wp_load_alloptions();

         foreach ( get_intermediate_image_sizes() as $s )
         {
                 var_dump( "Currently looking at size: {$s}" );

                 # Remove "post-" from `post-thumbnail`
                 # Use it with the Twenty* themes and calls
                 # to set_post_thumbnail_size(), else you will hit notices
                 # $s = str_replace( "post-", '', $s );

                 # Dump of attached callbacks
                 $cbs = [
                         "default_option_{$s}_size_w",
                         "default_option_{$s}_size_h",
                         "default_option_{$s}_crop",
                 ];
                 foreach ( $cbs as $cb )
                         isset( $GLOBALS['wp_filter'][ $cb ] )
                                 ? var_dump( $GLOBALS['wp_filter'][ $cb ] )
                                 : var_dump( "No callback on the options
 defaults for: {$cb}" );

                 # Dump of default option values
                 foreach ( [
                         'size_w',
                         'size_h',
                         'crop',
                         ] as $part )
                 {
                         # Let's take a look at the default options output:
                         isset( $defaults["{$s}_{$part}"] )
                                 ? var_dump( $defaults["{$s}_{$part}"] )
                                 : var_dump( "No default for: {$s}_{$part}"
 );

                         # Let's take a look at the option output:
                         var_dump( get_option( "{$s}_{$part}" ) );
                 }
         }

         var_dump( $GLOBALS['_wp_additional_image_sizes'] );

 }, PHP_INT_MAX -1 );
 /**/
 }}}

 The output in a completely vanilla install will be the following:

 {{{
 string 'Currently looking at size: thumbnail' (length=36)
 string 'No callback on the options defaults for:
 default_option_thumbnail_size_w' (length=72)
 string 'No callback on the options defaults for:
 default_option_thumbnail_size_h' (length=72)
 string 'No callback on the options defaults for:
 default_option_thumbnail_crop' (length=70)
 string '150' (length=3)
 string '150' (length=3)
 string '150' (length=3)
 string '150' (length=3)
 string '1' (length=1)
 string '1' (length=1)
 string 'Currently looking at size: medium' (length=33)
 string 'No callback on the options defaults for:
 default_option_medium_size_w' (length=69)
 string 'No callback on the options defaults for:
 default_option_medium_size_h' (length=69)
 string 'No callback on the options defaults for:
 default_option_medium_crop' (length=67)
 string '300' (length=3)
 string '300' (length=3)
 string '300' (length=3)
 string '300' (length=3)
 string 'No default for: medium_crop' (length=27)
 boolean false
 string 'Currently looking at size: large' (length=32)
 string 'No callback on the options defaults for:
 default_option_large_size_w' (length=68)
 string 'No callback on the options defaults for:
 default_option_large_size_h' (length=68)
 string 'No callback on the options defaults for:
 default_option_large_crop' (length=66)
 string '1024' (length=4)
 string '1024' (length=4)
 string '1024' (length=4)
 string '1024' (length=4)
 string 'No default for: large_crop' (length=26)
 boolean false
 null
 }}}

 I've written it so it is quite verbose in its output. As you can see,
 there are no callbacks attached for defaults, but everything has a default
 value. Ok, everything aside from the medium and large crop sizes - this
 would maybe need a separate ticket - which I will take into account with
 the upcoming patch.

 The last value is the return from what you suggested,
 {{{$GLOBALS['_wp_additional_image_sizes']}}}, which is {{{NULL}}}. The
 reason for that is quite simple: The global gets filled by
 {{{add_image_size()}}}. And if it was not used (which is the case for core
 image sizes) then the global simply stays empty.

 Conclusion: Don't rely on globals.

 > Also, suggested previously `get_image_sizes()`. `_data()` sounds
 superfluous and lacks parity with `add_image_size()`.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/18947#comment:14>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list