Make WordPress Core

Ticket #22100: 22100.4.diff

File 22100.4.diff, 10.8 KB (added by scribu, 12 years ago)
  • wp-admin/includes/image.php

    diff --git wp-admin/includes/image.php wp-admin/includes/image.php
    index 6ea4ede..82394ad 100644
    function wp_generate_attachment_metadata( $attachment_id, $file ) { 
    7474                // Make the file path relative to the upload dir
    7575                $metadata['file'] = _wp_relative_upload_path($file);
    7676
    77                 // make thumbnails and other intermediate sizes
    78                 global $_wp_additional_image_sizes;
    79 
    80                 foreach ( get_intermediate_image_sizes() as $s ) {
    81                         $sizes[$s] = array( 'width' => '', 'height' => '', 'crop' => false );
    82                         if ( isset( $_wp_additional_image_sizes[$s]['width'] ) )
    83                                 $sizes[$s]['width'] = intval( $_wp_additional_image_sizes[$s]['width'] ); // For theme-added sizes
    84                         else
    85                                 $sizes[$s]['width'] = get_option( "{$s}_size_w" ); // For default sizes set in options
    86                         if ( isset( $_wp_additional_image_sizes[$s]['height'] ) )
    87                                 $sizes[$s]['height'] = intval( $_wp_additional_image_sizes[$s]['height'] ); // For theme-added sizes
    88                         else
    89                                 $sizes[$s]['height'] = get_option( "{$s}_size_h" ); // For default sizes set in options
    90                         if ( isset( $_wp_additional_image_sizes[$s]['crop'] ) )
    91                                 $sizes[$s]['crop'] = intval( $_wp_additional_image_sizes[$s]['crop'] ); // For theme-added sizes
    92                         else
    93                                 $sizes[$s]['crop'] = get_option( "{$s}_crop" ); // For default sizes set in options
    94                 }
    95 
     77                $sizes = get_intermediate_image_sizes( 'full' );
    9678                $sizes = apply_filters( 'intermediate_image_sizes_advanced', $sizes );
    9779
    9880                $editor = WP_Image_Editor::get_instance( $file );
  • wp-admin/includes/meta-boxes.php

    diff --git wp-admin/includes/meta-boxes.php wp-admin/includes/meta-boxes.php
    index f099627..0321aff 100644
    function link_advanced_meta_box($link) { 
    10111011 * @since 2.9.0
    10121012 */
    10131013function post_thumbnail_meta_box( $post ) {
    1014         global $_wp_additional_image_sizes;
    1015 
    10161014        ?><script type="text/javascript">
    10171015        jQuery( function($) {
    10181016                var $element     = $('#select-featured-image'),
    function post_thumbnail_meta_box( $post ) { 
    10731071
    10741072        <?php
    10751073        $thumbnail_id   = get_post_meta( $post->ID, '_thumbnail_id', true );
    1076         $thumbnail_size = isset( $_wp_additional_image_sizes['post-thumbnail'] ) ? 'post-thumbnail' : 'medium';
     1074        $thumbnail_size = image_size_exists( 'post-thumbnail' ) ? 'post-thumbnail' : 'medium';
    10771075        $thumbnail_html = wp_get_attachment_image( $thumbnail_id, $thumbnail_size );
    10781076
    10791077        $classes = empty( $thumbnail_id ) ? '' : 'has-featured-image';
    function post_thumbnail_meta_box( $post ) { 
    10871085                <a href="#" class="remove"><?php _e( 'Remove Featured Image' ); ?></a>
    10881086        </div>
    10891087        <?php
    1090 }
    1091  No newline at end of file
     1088}
  • wp-admin/includes/post.php

    diff --git wp-admin/includes/post.php wp-admin/includes/post.php
    index 5ce1064..47c9316 100644
    function get_sample_permalink_html( $id, $new_title = null, $new_slug = null, $s 
    11301130 * @return string html
    11311131 */
    11321132function _wp_post_thumbnail_html( $thumbnail_id = null, $post = null ) {
    1133         global $content_width, $_wp_additional_image_sizes;
     1133        global $content_width;
    11341134
    11351135        $post = get_post( $post );
    11361136
    function _wp_post_thumbnail_html( $thumbnail_id = null, $post = null ) { 
    11411141        if ( $thumbnail_id && get_post( $thumbnail_id ) ) {
    11421142                $old_content_width = $content_width;
    11431143                $content_width = 266;
    1144                 if ( !isset( $_wp_additional_image_sizes['post-thumbnail'] ) )
     1144                if ( !image_size_exists( 'post-thumbnail' ) )
    11451145                        $thumbnail_html = wp_get_attachment_image( $thumbnail_id, array( $content_width, $content_width ) );
    11461146                else
    11471147                        $thumbnail_html = wp_get_attachment_image( $thumbnail_id, 'post-thumbnail' );
  • wp-includes/functions.php

    diff --git wp-includes/functions.php wp-includes/functions.php
    index c7d390b..7a01047 100644
    function wp_list_pluck( $list, $field ) { 
    25972597}
    25982598
    25992599/**
     2600 * Convert a numeric array to an associative array, based on a list of keys.
     2601 *
     2602 * @since 3.6.0
     2603 *
     2604 * @param array $list Numeric array to be converted
     2605 * @param array $keys A list of keys
     2606 * @return array Resulting array
     2607 */
     2608function wp_numeric_to_assoc( $vector, $keys ) {
     2609        $assoc = array();
     2610
     2611        foreach ( $keys as $i => $key ) {
     2612                if ( isset( $vector[ $i ] ) )
     2613                        $assoc[ $key ] = $vector[ $i ];
     2614                else
     2615                        break;
     2616        }
     2617
     2618        return $assoc;
     2619}
     2620
     2621/**
    26002622 * Determines if Widgets library should be loaded.
    26012623 *
    26022624 * Checks to make sure that the widgets library hasn't already been loaded. If
    function wp_is_stream( $path ) { 
    37943816function wp_checkdate( $month, $day, $year, $source_date ) {
    37953817        return apply_filters( 'wp_checkdate', checkdate( $month, $day, $year ), $source_date );
    37963818}
     3819
  • wp-includes/media.php

    diff --git wp-includes/media.php wp-includes/media.php
    index 8bd4286..0e5243c 100644
     
    3232 * @return array Width and height of what the result image should resize to.
    3333 */
    3434function image_constrain_size_for_editor($width, $height, $size = 'medium') {
    35         global $content_width, $_wp_additional_image_sizes;
     35        global $content_width;
     36
     37        if ( 'thumb' == $size )
     38                $size = 'thumbnail';
    3639
    3740        if ( is_array($size) ) {
    38                 $max_width = $size[0];
    39                 $max_height = $size[1];
    40         }
    41         elseif ( $size == 'thumb' || $size == 'thumbnail' ) {
    42                 $max_width = intval(get_option('thumbnail_size_w'));
    43                 $max_height = intval(get_option('thumbnail_size_h'));
    44                 // last chance thumbnail size defaults
    45                 if ( !$max_width && !$max_height ) {
    46                         $max_width = 128;
    47                         $max_height = 96;
    48                 }
    49         }
    50         elseif ( $size == 'medium' ) {
    51                 $max_width = intval(get_option('medium_size_w'));
    52                 $max_height = intval(get_option('medium_size_h'));
    53                 // if no width is set, default to the theme content width if available
     41                list( $max_width, $max_height ) = $size;
    5442        }
    55         elseif ( $size == 'large' ) {
    56                 // We're inserting a large size image into the editor. If it's a really
    57                 // big image we'll scale it down to fit reasonably within the editor
    58                 // itself, and within the theme's content width if it's known. The user
    59                 // can resize it in the editor if they wish.
    60                 $max_width = intval(get_option('large_size_w'));
    61                 $max_height = intval(get_option('large_size_h'));
    62                 if ( intval($content_width) > 0 )
    63                         $max_width = min( intval($content_width), $max_width );
    64         } elseif ( isset( $_wp_additional_image_sizes ) && count( $_wp_additional_image_sizes ) && in_array( $size, array_keys( $_wp_additional_image_sizes ) ) ) {
    65                 $max_width = intval( $_wp_additional_image_sizes[$size]['width'] );
    66                 $max_height = intval( $_wp_additional_image_sizes[$size]['height'] );
    67                 if ( intval($content_width) > 0 && is_admin() ) // Only in admin. Assume that theme authors know what they're doing.
     43        elseif ( image_size_exists( $size ) ) {
     44                $size_obj = get_image_size( $size );
     45
     46                $max_width = $size_obj->width;
     47                $max_height = $size_obj->height;
     48
     49                if ( intval( $content_width ) > 0 && ( 'large' == $size || is_admin() ) )
    6850                        $max_width = min( intval($content_width), $max_width );
    6951        }
    7052        // $size == 'full' has no constraint
    function image_downsize($id, $size = 'medium') { 
    176158}
    177159
    178160/**
    179  * Registers a new image size
     161 * Register a new image size.
    180162 *
    181163 * @since 2.9.0
     164 *
     165 * @param string $name The new image size name
     166 * @param array $args The new image size parameters
    182167 */
    183 function add_image_size( $name, $width = 0, $height = 0, $crop = false ) {
     168function add_image_size( $name, $args ) {
    184169        global $_wp_additional_image_sizes;
    185         $_wp_additional_image_sizes[$name] = array( 'width' => absint( $width ), 'height' => absint( $height ), 'crop' => (bool) $crop );
     170
     171        if ( !is_array( $args ) ) {
     172                $argv = func_get_args();
     173                $name = array_shift( $argv );
     174                $args = wp_numeric_to_assoc( $argv, array( 'width', 'height', 'crop' ) );
     175        }
     176
     177        $defaults = array(
     178                'width' => 0,
     179                'height' => 0,
     180                'crop' => false,
     181        );
     182
     183        $size = array_merge( $defaults, $args );
     184
     185        $size['width'] = absint( $size['width'] );
     186        $size['height'] = absint( $size['height'] );
     187        $size['crop'] = (bool) $size['height'];
     188
     189        $_wp_additional_image_sizes[ $name ] = $size;
    186190}
    187191
    188192/**
     193 * Get a registered image size object by name.
     194 *
     195 * @since 3.5.0
     196 *
     197 * @param string $image_size Image size name
     198 * @return bool|array
     199 */
     200function get_image_size( $image_size ) {
     201        global $_wp_additional_image_sizes;
     202
     203        if ( !isset( $_wp_additional_image_sizes[ $image_size ] ) )
     204                return false;
     205
     206        return $_wp_additional_image_sizes[ $image_size ];
     207}
     208
     209/**
     210 * Checks if an image size is registered.
     211 *
     212 * @since 3.5.0
     213 *
     214 * @param string $image_size Image size name
     215 * @return bool
     216 */
     217function image_size_exists( $image_size ) {
     218        return (bool) get_image_size( $image_size );
     219}
     220
     221/**
     222 * Get the available image sizes.
     223 *
     224 * @since 3.0.0
     225 *
     226 * @param string $output What to return. 'names' just returns the name of the size.
     227 * @param array $filters key=>value pairs used for filtering the list of sizes.
     228 * @param string $operator The operator used for combining the filters. Can be 'and', 'or' and 'not'.
     229 *
     230 * @return array
     231 */
     232function get_intermediate_image_sizes( $output = 'names', $filters = array(), $operator = 'and' ) {
     233        global $_wp_additional_image_sizes;
     234
     235        $field = ( 'names' == $output ) ? 'name' : false;
     236
     237        $list = wp_filter_object_list( $_wp_additional_image_sizes, $filters, $operator, $field );
     238
     239        if ( 'names' == $output )
     240                return apply_filters( 'intermediate_image_sizes', $list );
     241
     242        return $list;
     243}
     244
     245function create_initial_image_sizes() {
     246        foreach ( array( 'thumbnail', 'medium', 'large' ) as $s ) {
     247                $args = array(
     248                        'width' => get_option( "{$s}_size_w" ),
     249                        'height' => get_option( "{$s}_size_h" ),
     250                        'crop' => get_option( "{$s}_crop" ),
     251                );
     252
     253                add_image_size( $s, $args );
     254        }
     255}
     256add_action( 'init', 'create_initial_image_sizes', 0 ); // highest priority
     257
     258/**
    189259 * Registers an image size for the post thumbnail
    190260 *
    191261 * @since 2.9.0
    192262 */
    193263function set_post_thumbnail_size( $width = 0, $height = 0, $crop = false ) {
    194         add_image_size( 'post-thumbnail', $width, $height, $crop );
     264        add_image_size( 'post-thumbnail', array(
     265                'width' => $width,
     266                'height' => $height,
     267                'crop' => $crop,
     268        ) );
    195269}
    196270
    197271/**
    function image_get_intermediate_size($post_id, $size='thumbnail') { 
    473547}
    474548
    475549/**
    476  * Get the available image sizes
    477  * @since 3.0.0
    478  * @return array Returns a filtered array of image size strings
    479  */
    480 function get_intermediate_image_sizes() {
    481         global $_wp_additional_image_sizes;
    482         $image_sizes = array('thumbnail', 'medium', 'large'); // Standard sizes
    483         if ( isset( $_wp_additional_image_sizes ) && count( $_wp_additional_image_sizes ) )
    484                 $image_sizes = array_merge( $image_sizes, array_keys( $_wp_additional_image_sizes ) );
    485 
    486         return apply_filters( 'intermediate_image_sizes', $image_sizes );
    487 }
    488 
    489 /**
    490550 * Retrieve an image to represent an attachment.
    491551 *
    492552 * A mime icon for files, thumbnail or intermediate size for images.