| 1 | diff --git wp-admin/includes/image.php wp-admin/includes/image.php |
|---|
| 2 | index 6ea4ede..82394ad 100644 |
|---|
| 3 | --- wp-admin/includes/image.php |
|---|
| 4 | +++ wp-admin/includes/image.php |
|---|
| 5 | @@ -74,25 +74,7 @@ function wp_generate_attachment_metadata( $attachment_id, $file ) { |
|---|
| 6 | // Make the file path relative to the upload dir |
|---|
| 7 | $metadata['file'] = _wp_relative_upload_path($file); |
|---|
| 8 | |
|---|
| 9 | - // make thumbnails and other intermediate sizes |
|---|
| 10 | - global $_wp_additional_image_sizes; |
|---|
| 11 | - |
|---|
| 12 | - foreach ( get_intermediate_image_sizes() as $s ) { |
|---|
| 13 | - $sizes[$s] = array( 'width' => '', 'height' => '', 'crop' => false ); |
|---|
| 14 | - if ( isset( $_wp_additional_image_sizes[$s]['width'] ) ) |
|---|
| 15 | - $sizes[$s]['width'] = intval( $_wp_additional_image_sizes[$s]['width'] ); // For theme-added sizes |
|---|
| 16 | - else |
|---|
| 17 | - $sizes[$s]['width'] = get_option( "{$s}_size_w" ); // For default sizes set in options |
|---|
| 18 | - if ( isset( $_wp_additional_image_sizes[$s]['height'] ) ) |
|---|
| 19 | - $sizes[$s]['height'] = intval( $_wp_additional_image_sizes[$s]['height'] ); // For theme-added sizes |
|---|
| 20 | - else |
|---|
| 21 | - $sizes[$s]['height'] = get_option( "{$s}_size_h" ); // For default sizes set in options |
|---|
| 22 | - if ( isset( $_wp_additional_image_sizes[$s]['crop'] ) ) |
|---|
| 23 | - $sizes[$s]['crop'] = intval( $_wp_additional_image_sizes[$s]['crop'] ); // For theme-added sizes |
|---|
| 24 | - else |
|---|
| 25 | - $sizes[$s]['crop'] = get_option( "{$s}_crop" ); // For default sizes set in options |
|---|
| 26 | - } |
|---|
| 27 | - |
|---|
| 28 | + $sizes = get_intermediate_image_sizes( 'full' ); |
|---|
| 29 | $sizes = apply_filters( 'intermediate_image_sizes_advanced', $sizes ); |
|---|
| 30 | |
|---|
| 31 | $editor = WP_Image_Editor::get_instance( $file ); |
|---|
| 32 | diff --git wp-admin/includes/meta-boxes.php wp-admin/includes/meta-boxes.php |
|---|
| 33 | index f099627..0321aff 100644 |
|---|
| 34 | --- wp-admin/includes/meta-boxes.php |
|---|
| 35 | +++ wp-admin/includes/meta-boxes.php |
|---|
| 36 | @@ -1011,8 +1011,6 @@ function link_advanced_meta_box($link) { |
|---|
| 37 | * @since 2.9.0 |
|---|
| 38 | */ |
|---|
| 39 | function post_thumbnail_meta_box( $post ) { |
|---|
| 40 | - global $_wp_additional_image_sizes; |
|---|
| 41 | - |
|---|
| 42 | ?><script type="text/javascript"> |
|---|
| 43 | jQuery( function($) { |
|---|
| 44 | var $element = $('#select-featured-image'), |
|---|
| 45 | @@ -1073,7 +1071,7 @@ function post_thumbnail_meta_box( $post ) { |
|---|
| 46 | |
|---|
| 47 | <?php |
|---|
| 48 | $thumbnail_id = get_post_meta( $post->ID, '_thumbnail_id', true ); |
|---|
| 49 | - $thumbnail_size = isset( $_wp_additional_image_sizes['post-thumbnail'] ) ? 'post-thumbnail' : 'medium'; |
|---|
| 50 | + $thumbnail_size = image_size_exists( 'post-thumbnail' ) ? 'post-thumbnail' : 'medium'; |
|---|
| 51 | $thumbnail_html = wp_get_attachment_image( $thumbnail_id, $thumbnail_size ); |
|---|
| 52 | |
|---|
| 53 | $classes = empty( $thumbnail_id ) ? '' : 'has-featured-image'; |
|---|
| 54 | @@ -1087,4 +1085,4 @@ function post_thumbnail_meta_box( $post ) { |
|---|
| 55 | <a href="#" class="remove"><?php _e( 'Remove Featured Image' ); ?></a> |
|---|
| 56 | </div> |
|---|
| 57 | <?php |
|---|
| 58 | -} |
|---|
| 59 | \ No newline at end of file |
|---|
| 60 | +} |
|---|
| 61 | diff --git wp-admin/includes/post.php wp-admin/includes/post.php |
|---|
| 62 | index 5ce1064..47c9316 100644 |
|---|
| 63 | --- wp-admin/includes/post.php |
|---|
| 64 | +++ wp-admin/includes/post.php |
|---|
| 65 | @@ -1130,7 +1130,7 @@ function get_sample_permalink_html( $id, $new_title = null, $new_slug = null, $s |
|---|
| 66 | * @return string html |
|---|
| 67 | */ |
|---|
| 68 | function _wp_post_thumbnail_html( $thumbnail_id = null, $post = null ) { |
|---|
| 69 | - global $content_width, $_wp_additional_image_sizes; |
|---|
| 70 | + global $content_width; |
|---|
| 71 | |
|---|
| 72 | $post = get_post( $post ); |
|---|
| 73 | |
|---|
| 74 | @@ -1141,7 +1141,7 @@ function _wp_post_thumbnail_html( $thumbnail_id = null, $post = null ) { |
|---|
| 75 | if ( $thumbnail_id && get_post( $thumbnail_id ) ) { |
|---|
| 76 | $old_content_width = $content_width; |
|---|
| 77 | $content_width = 266; |
|---|
| 78 | - if ( !isset( $_wp_additional_image_sizes['post-thumbnail'] ) ) |
|---|
| 79 | + if ( !image_size_exists( 'post-thumbnail' ) ) |
|---|
| 80 | $thumbnail_html = wp_get_attachment_image( $thumbnail_id, array( $content_width, $content_width ) ); |
|---|
| 81 | else |
|---|
| 82 | $thumbnail_html = wp_get_attachment_image( $thumbnail_id, 'post-thumbnail' ); |
|---|
| 83 | diff --git wp-includes/functions.php wp-includes/functions.php |
|---|
| 84 | index c7d390b..7a01047 100644 |
|---|
| 85 | --- wp-includes/functions.php |
|---|
| 86 | +++ wp-includes/functions.php |
|---|
| 87 | @@ -2597,6 +2597,28 @@ function wp_list_pluck( $list, $field ) { |
|---|
| 88 | } |
|---|
| 89 | |
|---|
| 90 | /** |
|---|
| 91 | + * Convert a numeric array to an associative array, based on a list of keys. |
|---|
| 92 | + * |
|---|
| 93 | + * @since 3.6.0 |
|---|
| 94 | + * |
|---|
| 95 | + * @param array $list Numeric array to be converted |
|---|
| 96 | + * @param array $keys A list of keys |
|---|
| 97 | + * @return array Resulting array |
|---|
| 98 | + */ |
|---|
| 99 | +function wp_numeric_to_assoc( $vector, $keys ) { |
|---|
| 100 | + $assoc = array(); |
|---|
| 101 | + |
|---|
| 102 | + foreach ( $keys as $i => $key ) { |
|---|
| 103 | + if ( isset( $vector[ $i ] ) ) |
|---|
| 104 | + $assoc[ $key ] = $vector[ $i ]; |
|---|
| 105 | + else |
|---|
| 106 | + break; |
|---|
| 107 | + } |
|---|
| 108 | + |
|---|
| 109 | + return $assoc; |
|---|
| 110 | +} |
|---|
| 111 | + |
|---|
| 112 | +/** |
|---|
| 113 | * Determines if Widgets library should be loaded. |
|---|
| 114 | * |
|---|
| 115 | * Checks to make sure that the widgets library hasn't already been loaded. If |
|---|
| 116 | @@ -3794,3 +3816,4 @@ function wp_is_stream( $path ) { |
|---|
| 117 | function wp_checkdate( $month, $day, $year, $source_date ) { |
|---|
| 118 | return apply_filters( 'wp_checkdate', checkdate( $month, $day, $year ), $source_date ); |
|---|
| 119 | } |
|---|
| 120 | + |
|---|
| 121 | diff --git wp-includes/media.php wp-includes/media.php |
|---|
| 122 | index 8bd4286..0e5243c 100644 |
|---|
| 123 | --- wp-includes/media.php |
|---|
| 124 | +++ wp-includes/media.php |
|---|
| 125 | @@ -32,39 +32,21 @@ |
|---|
| 126 | * @return array Width and height of what the result image should resize to. |
|---|
| 127 | */ |
|---|
| 128 | function image_constrain_size_for_editor($width, $height, $size = 'medium') { |
|---|
| 129 | - global $content_width, $_wp_additional_image_sizes; |
|---|
| 130 | + global $content_width; |
|---|
| 131 | + |
|---|
| 132 | + if ( 'thumb' == $size ) |
|---|
| 133 | + $size = 'thumbnail'; |
|---|
| 134 | |
|---|
| 135 | if ( is_array($size) ) { |
|---|
| 136 | - $max_width = $size[0]; |
|---|
| 137 | - $max_height = $size[1]; |
|---|
| 138 | - } |
|---|
| 139 | - elseif ( $size == 'thumb' || $size == 'thumbnail' ) { |
|---|
| 140 | - $max_width = intval(get_option('thumbnail_size_w')); |
|---|
| 141 | - $max_height = intval(get_option('thumbnail_size_h')); |
|---|
| 142 | - // last chance thumbnail size defaults |
|---|
| 143 | - if ( !$max_width && !$max_height ) { |
|---|
| 144 | - $max_width = 128; |
|---|
| 145 | - $max_height = 96; |
|---|
| 146 | - } |
|---|
| 147 | - } |
|---|
| 148 | - elseif ( $size == 'medium' ) { |
|---|
| 149 | - $max_width = intval(get_option('medium_size_w')); |
|---|
| 150 | - $max_height = intval(get_option('medium_size_h')); |
|---|
| 151 | - // if no width is set, default to the theme content width if available |
|---|
| 152 | + list( $max_width, $max_height ) = $size; |
|---|
| 153 | } |
|---|
| 154 | - elseif ( $size == 'large' ) { |
|---|
| 155 | - // We're inserting a large size image into the editor. If it's a really |
|---|
| 156 | - // big image we'll scale it down to fit reasonably within the editor |
|---|
| 157 | - // itself, and within the theme's content width if it's known. The user |
|---|
| 158 | - // can resize it in the editor if they wish. |
|---|
| 159 | - $max_width = intval(get_option('large_size_w')); |
|---|
| 160 | - $max_height = intval(get_option('large_size_h')); |
|---|
| 161 | - if ( intval($content_width) > 0 ) |
|---|
| 162 | - $max_width = min( intval($content_width), $max_width ); |
|---|
| 163 | - } elseif ( isset( $_wp_additional_image_sizes ) && count( $_wp_additional_image_sizes ) && in_array( $size, array_keys( $_wp_additional_image_sizes ) ) ) { |
|---|
| 164 | - $max_width = intval( $_wp_additional_image_sizes[$size]['width'] ); |
|---|
| 165 | - $max_height = intval( $_wp_additional_image_sizes[$size]['height'] ); |
|---|
| 166 | - if ( intval($content_width) > 0 && is_admin() ) // Only in admin. Assume that theme authors know what they're doing. |
|---|
| 167 | + elseif ( image_size_exists( $size ) ) { |
|---|
| 168 | + $size_obj = get_image_size( $size ); |
|---|
| 169 | + |
|---|
| 170 | + $max_width = $size_obj->width; |
|---|
| 171 | + $max_height = $size_obj->height; |
|---|
| 172 | + |
|---|
| 173 | + if ( intval( $content_width ) > 0 && ( 'large' == $size || is_admin() ) ) |
|---|
| 174 | $max_width = min( intval($content_width), $max_width ); |
|---|
| 175 | } |
|---|
| 176 | // $size == 'full' has no constraint |
|---|
| 177 | @@ -176,22 +158,114 @@ function image_downsize($id, $size = 'medium') { |
|---|
| 178 | } |
|---|
| 179 | |
|---|
| 180 | /** |
|---|
| 181 | - * Registers a new image size |
|---|
| 182 | + * Register a new image size. |
|---|
| 183 | * |
|---|
| 184 | * @since 2.9.0 |
|---|
| 185 | + * |
|---|
| 186 | + * @param string $name The new image size name |
|---|
| 187 | + * @param array $args The new image size parameters |
|---|
| 188 | */ |
|---|
| 189 | -function add_image_size( $name, $width = 0, $height = 0, $crop = false ) { |
|---|
| 190 | +function add_image_size( $name, $args ) { |
|---|
| 191 | global $_wp_additional_image_sizes; |
|---|
| 192 | - $_wp_additional_image_sizes[$name] = array( 'width' => absint( $width ), 'height' => absint( $height ), 'crop' => (bool) $crop ); |
|---|
| 193 | + |
|---|
| 194 | + if ( !is_array( $args ) ) { |
|---|
| 195 | + $argv = func_get_args(); |
|---|
| 196 | + $name = array_shift( $argv ); |
|---|
| 197 | + $args = wp_numeric_to_assoc( $argv, array( 'width', 'height', 'crop' ) ); |
|---|
| 198 | + } |
|---|
| 199 | + |
|---|
| 200 | + $defaults = array( |
|---|
| 201 | + 'width' => 0, |
|---|
| 202 | + 'height' => 0, |
|---|
| 203 | + 'crop' => false, |
|---|
| 204 | + ); |
|---|
| 205 | + |
|---|
| 206 | + $size = array_merge( $defaults, $args ); |
|---|
| 207 | + |
|---|
| 208 | + $size['width'] = absint( $size['width'] ); |
|---|
| 209 | + $size['height'] = absint( $size['height'] ); |
|---|
| 210 | + $size['crop'] = (bool) $size['height']; |
|---|
| 211 | + |
|---|
| 212 | + $_wp_additional_image_sizes[ $name ] = $size; |
|---|
| 213 | } |
|---|
| 214 | |
|---|
| 215 | /** |
|---|
| 216 | + * Get a registered image size object by name. |
|---|
| 217 | + * |
|---|
| 218 | + * @since 3.5.0 |
|---|
| 219 | + * |
|---|
| 220 | + * @param string $image_size Image size name |
|---|
| 221 | + * @return bool|array |
|---|
| 222 | + */ |
|---|
| 223 | +function get_image_size( $image_size ) { |
|---|
| 224 | + global $_wp_additional_image_sizes; |
|---|
| 225 | + |
|---|
| 226 | + if ( !isset( $_wp_additional_image_sizes[ $image_size ] ) ) |
|---|
| 227 | + return false; |
|---|
| 228 | + |
|---|
| 229 | + return $_wp_additional_image_sizes[ $image_size ]; |
|---|
| 230 | +} |
|---|
| 231 | + |
|---|
| 232 | +/** |
|---|
| 233 | + * Checks if an image size is registered. |
|---|
| 234 | + * |
|---|
| 235 | + * @since 3.5.0 |
|---|
| 236 | + * |
|---|
| 237 | + * @param string $image_size Image size name |
|---|
| 238 | + * @return bool |
|---|
| 239 | + */ |
|---|
| 240 | +function image_size_exists( $image_size ) { |
|---|
| 241 | + return (bool) get_image_size( $image_size ); |
|---|
| 242 | +} |
|---|
| 243 | + |
|---|
| 244 | +/** |
|---|
| 245 | + * Get the available image sizes. |
|---|
| 246 | + * |
|---|
| 247 | + * @since 3.0.0 |
|---|
| 248 | + * |
|---|
| 249 | + * @param string $output What to return. 'names' just returns the name of the size. |
|---|
| 250 | + * @param array $filters key=>value pairs used for filtering the list of sizes. |
|---|
| 251 | + * @param string $operator The operator used for combining the filters. Can be 'and', 'or' and 'not'. |
|---|
| 252 | + * |
|---|
| 253 | + * @return array |
|---|
| 254 | + */ |
|---|
| 255 | +function get_intermediate_image_sizes( $output = 'names', $filters = array(), $operator = 'and' ) { |
|---|
| 256 | + global $_wp_additional_image_sizes; |
|---|
| 257 | + |
|---|
| 258 | + $field = ( 'names' == $output ) ? 'name' : false; |
|---|
| 259 | + |
|---|
| 260 | + $list = wp_filter_object_list( $_wp_additional_image_sizes, $filters, $operator, $field ); |
|---|
| 261 | + |
|---|
| 262 | + if ( 'names' == $output ) |
|---|
| 263 | + return apply_filters( 'intermediate_image_sizes', $list ); |
|---|
| 264 | + |
|---|
| 265 | + return $list; |
|---|
| 266 | +} |
|---|
| 267 | + |
|---|
| 268 | +function create_initial_image_sizes() { |
|---|
| 269 | + foreach ( array( 'thumbnail', 'medium', 'large' ) as $s ) { |
|---|
| 270 | + $args = array( |
|---|
| 271 | + 'width' => get_option( "{$s}_size_w" ), |
|---|
| 272 | + 'height' => get_option( "{$s}_size_h" ), |
|---|
| 273 | + 'crop' => get_option( "{$s}_crop" ), |
|---|
| 274 | + ); |
|---|
| 275 | + |
|---|
| 276 | + add_image_size( $s, $args ); |
|---|
| 277 | + } |
|---|
| 278 | +} |
|---|
| 279 | +add_action( 'init', 'create_initial_image_sizes', 0 ); // highest priority |
|---|
| 280 | + |
|---|
| 281 | +/** |
|---|
| 282 | * Registers an image size for the post thumbnail |
|---|
| 283 | * |
|---|
| 284 | * @since 2.9.0 |
|---|
| 285 | */ |
|---|
| 286 | function set_post_thumbnail_size( $width = 0, $height = 0, $crop = false ) { |
|---|
| 287 | - add_image_size( 'post-thumbnail', $width, $height, $crop ); |
|---|
| 288 | + add_image_size( 'post-thumbnail', array( |
|---|
| 289 | + 'width' => $width, |
|---|
| 290 | + 'height' => $height, |
|---|
| 291 | + 'crop' => $crop, |
|---|
| 292 | + ) ); |
|---|
| 293 | } |
|---|
| 294 | |
|---|
| 295 | /** |
|---|
| 296 | @@ -473,20 +547,6 @@ function image_get_intermediate_size($post_id, $size='thumbnail') { |
|---|
| 297 | } |
|---|
| 298 | |
|---|
| 299 | /** |
|---|
| 300 | - * Get the available image sizes |
|---|
| 301 | - * @since 3.0.0 |
|---|
| 302 | - * @return array Returns a filtered array of image size strings |
|---|
| 303 | - */ |
|---|
| 304 | -function get_intermediate_image_sizes() { |
|---|
| 305 | - global $_wp_additional_image_sizes; |
|---|
| 306 | - $image_sizes = array('thumbnail', 'medium', 'large'); // Standard sizes |
|---|
| 307 | - if ( isset( $_wp_additional_image_sizes ) && count( $_wp_additional_image_sizes ) ) |
|---|
| 308 | - $image_sizes = array_merge( $image_sizes, array_keys( $_wp_additional_image_sizes ) ); |
|---|
| 309 | - |
|---|
| 310 | - return apply_filters( 'intermediate_image_sizes', $image_sizes ); |
|---|
| 311 | -} |
|---|
| 312 | - |
|---|
| 313 | -/** |
|---|
| 314 | * Retrieve an image to represent an attachment. |
|---|
| 315 | * |
|---|
| 316 | * A mime icon for files, thumbnail or intermediate size for images. |
|---|