Introduce a single function for getting all the intermediate image sizes to be used both when adding attachements and deleting. Fixes #10263 props scribu.

git-svn-id: http://svn.automattic.com/wordpress/trunk@12659 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
westi 2010-01-08 08:51:12 +00:00
parent 4d0c9da793
commit cc30f8ad98
3 changed files with 16 additions and 8 deletions

View File

@ -102,13 +102,8 @@ function wp_generate_attachment_metadata( $attachment_id, $file ) {
// make thumbnails and other intermediate sizes // make thumbnails and other intermediate sizes
global $_wp_additional_image_sizes; global $_wp_additional_image_sizes;
$temp_sizes = array('thumbnail', 'medium', 'large'); // Standard sizes
if ( isset( $_wp_additional_image_sizes ) && count( $_wp_additional_image_sizes ) )
$temp_sizes = array_merge( $temp_sizes, array_keys( $_wp_additional_image_sizes ) );
$temp_sizes = apply_filters( 'intermediate_image_sizes', $temp_sizes ); foreach ( get_intermediate_image_sizes() as $s ) {
foreach ( $temp_sizes as $s ) {
$sizes[$s] = array( 'width' => '', 'height' => '', 'crop' => FALSE ); $sizes[$s] = array( 'width' => '', 'height' => '', 'crop' => FALSE );
if ( isset( $_wp_additional_image_sizes[$s]['width'] ) ) if ( isset( $_wp_additional_image_sizes[$s]['width'] ) )
$sizes[$s]['width'] = intval( $_wp_additional_image_sizes[$s]['width'] ); // For theme-added sizes $sizes[$s]['width'] = intval( $_wp_additional_image_sizes[$s]['width'] ); // For theme-added sizes

View File

@ -506,6 +506,20 @@ function image_get_intermediate_size($post_id, $size='thumbnail') {
return $data; return $data;
} }
/**
* Get the available image sizes
* @since 3.0
* @return array Returns a filtered array of image size strings
*/
function get_intermediate_image_sizes() {
global $_wp_additional_image_sizes;
$image_sizes = array('thumbnail', 'medium', 'large'); // Standard sizes
if ( isset( $_wp_additional_image_sizes ) && count( $_wp_additional_image_sizes ) )
$image_sizes = array_merge( $image_sizes, array_keys( $_wp_additional_image_sizes ) );
return apply_filters( 'intermediate_image_sizes', $image_sizes );
}
/** /**
* Retrieve an image to represent an attachment. * Retrieve an image to represent an attachment.
* *

View File

@ -2946,8 +2946,7 @@ function wp_delete_attachment( $post_id, $force_delete = false ) {
} }
// remove intermediate and backup images if there are any // remove intermediate and backup images if there are any
$sizes = apply_filters('intermediate_image_sizes', array('thumbnail', 'medium', 'large')); foreach ( get_intermediate_image_sizes() as $size ) {
foreach ( $sizes as $size ) {
if ( $intermediate = image_get_intermediate_size($post_id, $size) ) { if ( $intermediate = image_get_intermediate_size($post_id, $size) ) {
$intermediate_file = apply_filters('wp_delete_file', $intermediate['path']); $intermediate_file = apply_filters('wp_delete_file', $intermediate['path']);
@ unlink( path_join($uploadpath['basedir'], $intermediate_file) ); @ unlink( path_join($uploadpath['basedir'], $intermediate_file) );