Ticket #22100: 22100.3.diff
File 22100.3.diff, 10.7 KB (added by , 12 years ago) |
---|
-
wp-admin/includes/image.php
diff --git wp-admin/includes/image.php wp-admin/includes/image.php index 2a5123e..de5b470 100644
function wp_generate_attachment_metadata( $attachment_id, $file ) { 72 72 // Make the file path relative to the upload dir 73 73 $metadata['file'] = _wp_relative_upload_path($file); 74 74 75 // make thumbnails and other intermediate sizes 76 global $_wp_additional_image_sizes; 77 78 foreach ( get_intermediate_image_sizes() as $s ) { 79 $sizes[$s] = array( 'width' => '', 'height' => '', 'crop' => false ); 80 if ( isset( $_wp_additional_image_sizes[$s]['width'] ) ) 81 $sizes[$s]['width'] = intval( $_wp_additional_image_sizes[$s]['width'] ); // For theme-added sizes 82 else 83 $sizes[$s]['width'] = get_option( "{$s}_size_w" ); // For default sizes set in options 84 if ( isset( $_wp_additional_image_sizes[$s]['height'] ) ) 85 $sizes[$s]['height'] = intval( $_wp_additional_image_sizes[$s]['height'] ); // For theme-added sizes 86 else 87 $sizes[$s]['height'] = get_option( "{$s}_size_h" ); // For default sizes set in options 88 if ( isset( $_wp_additional_image_sizes[$s]['crop'] ) ) 89 $sizes[$s]['crop'] = intval( $_wp_additional_image_sizes[$s]['crop'] ); // For theme-added sizes 90 else 91 $sizes[$s]['crop'] = get_option( "{$s}_crop" ); // For default sizes set in options 75 $sizes = array(); 76 77 foreach ( get_intermediate_image_sizes( array(), 'objects' ) as $name => $size ) { 78 $sizes[ $name ] = array( 79 'width' => $size->width, 80 'height' => $size->height, 81 'crop' => $size->crop, 82 ); 92 83 } 93 84 94 85 $sizes = apply_filters( 'intermediate_image_sizes_advanced', $sizes ); -
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) { 1011 1011 * @since 2.9.0 1012 1012 */ 1013 1013 function post_thumbnail_meta_box( $post ) { 1014 global $_wp_additional_image_sizes;1015 1016 1014 ?><script type="text/javascript"> 1017 1015 jQuery( function($) { 1018 1016 var $element = $('#select-featured-image'), … … function post_thumbnail_meta_box( $post ) { 1073 1071 1074 1072 <?php 1075 1073 $thumbnail_id = get_post_meta( $post->ID, '_thumbnail_id', true ); 1076 $thumbnail_size = i sset( $_wp_additional_image_sizes['post-thumbnail']) ? 'post-thumbnail' : 'medium';1074 $thumbnail_size = image_size_exists( 'post-thumbnail' ) ? 'post-thumbnail' : 'medium'; 1077 1075 $thumbnail_html = wp_get_attachment_image( $thumbnail_id, $thumbnail_size ); 1078 1076 1079 1077 $classes = empty( $thumbnail_id ) ? '' : 'has-featured-image'; … … function post_thumbnail_meta_box( $post ) { 1087 1085 <a href="#" class="remove"><?php _e( 'Remove Featured Image' ); ?></a> 1088 1086 </div> 1089 1087 <?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 44bc7c2..740817c 100644
function get_sample_permalink_html( $id, $new_title = null, $new_slug = null ) { 1124 1124 * @return string html 1125 1125 */ 1126 1126 function _wp_post_thumbnail_html( $thumbnail_id = null, $post = null ) { 1127 global $content_width , $_wp_additional_image_sizes;1127 global $content_width; 1128 1128 1129 1129 $post = get_post( $post ); 1130 1130 … … function _wp_post_thumbnail_html( $thumbnail_id = null, $post = null ) { 1135 1135 if ( $thumbnail_id && get_post( $thumbnail_id ) ) { 1136 1136 $old_content_width = $content_width; 1137 1137 $content_width = 266; 1138 if ( !i sset( $_wp_additional_image_sizes['post-thumbnail']) )1138 if ( !image_size_exists( 'post-thumbnail' ) ) 1139 1139 $thumbnail_html = wp_get_attachment_image( $thumbnail_id, array( $content_width, $content_width ) ); 1140 1140 else 1141 1141 $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 8615e32..9070701 100644
function wp_list_pluck( $list, $field ) { 2584 2584 } 2585 2585 2586 2586 /** 2587 * Convert a numeric array to an associative array, based on a list of keys. 2588 * 2589 * @since 3.6.0 2590 * 2591 * @param array $list Numeric array to be converted 2592 * @param array $keys A list of keys 2593 * @return array Resulting array 2594 */ 2595 function wp_numeric_to_assoc( $vector, $keys ) { 2596 $assoc = array(); 2597 2598 foreach ( $keys as $i => $key ) { 2599 if ( isset( $vector[ $i ] ) ) 2600 $assoc[ $key ] = $vector[ $i ]; 2601 else 2602 break; 2603 } 2604 2605 return $assoc; 2606 } 2607 2608 /** 2587 2609 * Determines if Widgets library should be loaded. 2588 2610 * 2589 2611 * Checks to make sure that the widgets library hasn't already been loaded. If … … function wp_is_stream( $path ) { 3781 3803 function wp_checkdate( $month, $day, $year, $source_date ) { 3782 3804 return apply_filters( 'wp_checkdate', checkdate( $month, $day, $year ), $source_date ); 3783 3805 } 3806 -
wp-includes/media.php
diff --git wp-includes/media.php wp-includes/media.php index 1fc4383..6b2c915 100644
32 32 * @return array Width and height of what the result image should resize to. 33 33 */ 34 34 function 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'; 36 39 37 40 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; 54 42 } 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() ) ) 68 50 $max_width = min( intval($content_width), $max_width ); 69 51 } 70 52 // $size == 'full' has no constraint … … function image_downsize($id, $size = 'medium') { 176 158 } 177 159 178 160 /** 179 * Register s a new image size161 * Register a new image size. 180 162 * 181 163 * @since 2.9.0 164 * 165 * @param string $name The new image size name 166 * @param array $args The new image size parameters 167 */ 168 function add_image_size( $name, $args ) { 169 if ( !is_array( $args ) ) { 170 $argv = func_get_args(); 171 $name = array_shift( $argv ); 172 $args = wp_numeric_to_assoc( $argv, array( 'width', 'height', 'crop' ) ); 173 } 174 175 $defaults = array( 176 'width' => 0, 177 'height' => 0, 178 'crop' => false, 179 ); 180 181 $args = array_merge( $defaults, $args ); 182 183 $size = new stdClass; 184 185 $size->name = $name; 186 $size->width = absint( $args['width'] ); 187 $size->height = absint( $args['height'] ); 188 $size->crop = (bool) $args['crop']; 189 190 global $wp_image_sizes; 191 192 if ( !is_array( $wp_image_sizes ) ) 193 $wp_image_sizes = array(); 194 195 $wp_image_sizes[ $name ] = $size; 196 } 197 198 /** 199 * Get a registered image size object by name. 200 * 201 * @since 3.5.0 202 * 203 * @param string $image_size Image size name 204 * @return object 205 */ 206 function get_image_size( $image_size ) { 207 global $wp_image_sizes; 208 209 if ( empty( $wp_image_sizes[ $image_size ] ) ) 210 return null; 211 212 return $wp_image_sizes[ $image_size ]; 213 } 214 215 /** 216 * Checks if an image size is registered. 217 * 218 * @since 3.5.0 219 * 220 * @param string $image_size Image size name 221 * @return bool 182 222 */ 183 function add_image_size( $name, $width = 0, $height = 0, $crop = false ) { 184 global $_wp_additional_image_sizes; 185 $_wp_additional_image_sizes[$name] = array( 'width' => absint( $width ), 'height' => absint( $height ), 'crop' => (bool) $crop ); 223 function image_size_exists( $image_size ) { 224 return (bool) get_image_size( $image_size ); 186 225 } 187 226 188 227 /** 228 * Get the available image sizes. 229 * 230 * @since 3.0.0 231 * 232 * @return array 233 */ 234 function get_intermediate_image_sizes( $args = array(), $output = 'names', $operator = 'and' ) { 235 global $wp_image_sizes; 236 237 $field = ( 'names' == $output ) ? 'name' : false; 238 239 $list = wp_filter_object_list( $wp_image_sizes, $args, $operator, $field ); 240 241 if ( 'names' == $output ) 242 return apply_filters( 'intermediate_image_sizes', $list ); 243 244 return $list; 245 } 246 247 function create_initial_image_sizes() { 248 foreach ( array( 'thumbnail', 'medium', 'large' ) as $s ) { 249 $args = array( 250 'width' => get_option( "{$s}_size_w" ), 251 'height' => get_option( "{$s}_size_h" ), 252 'crop' => get_option( "{$s}_crop" ), 253 ); 254 255 add_image_size( $s, $args ); 256 } 257 } 258 add_action( 'init', 'create_initial_image_sizes', 0 ); // highest priority 259 260 /** 189 261 * Registers an image size for the post thumbnail 190 262 * 191 263 * @since 2.9.0 192 264 */ 193 265 function set_post_thumbnail_size( $width = 0, $height = 0, $crop = false ) { 194 add_image_size( 'post-thumbnail', $width, $height, $crop ); 266 add_image_size( 'post-thumbnail', array( 267 'width' => $width, 268 'height' => $height, 269 'crop' => $crop, 270 ) ); 195 271 } 196 272 197 273 /** … … function image_get_intermediate_size($post_id, $size='thumbnail') { 473 549 } 474 550 475 551 /** 476 * Get the available image sizes477 * @since 3.0.0478 * @return array Returns a filtered array of image size strings479 */480 function get_intermediate_image_sizes() {481 global $_wp_additional_image_sizes;482 $image_sizes = array('thumbnail', 'medium', 'large'); // Standard sizes483 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 /**490 552 * Retrieve an image to represent an attachment. 491 553 * 492 554 * A mime icon for files, thumbnail or intermediate size for images.