[wp-hackers] add_image_size() possible to restrict to just one size?..

Patrik Bóna patrik.bona at mrhead.sk
Mon Sep 6 06:39:05 UTC 2010


Hi Mike,

Yes i am replacing thumbnail size with that line. To be honest on that 
site from which is this code, thumbnail size is not even set, but it 
doesn't matter. I have different post types on that site and i don't 
need to generate same image sizes for each post type, so this is my 
solution...

I think that best would be to change add_image_size, so it would be 
possible to register image size just for one post type, not for whole 
site, but perhaps somebody else should do it, because i am not sure how ;).

Btw. this is code for deleting all image sizes:

function delete_all_sizes($attachment_id) {
	$metadata = wp_get_attachment_metadata($attachment_id);
	if(!$metadata)
		return false;
	$upload_dir = wp_upload_dir();
	$subdir = dirname($metadata['file']);
	foreach($metadata['sizes'] as $size) {
		$file = $upload_dir['basedir'] . '/' . $subdir . '/' . $size['file'];
		if(file_exists($file)&&  is_file($file))
			unlink($file);
	}
}
add_action('delete_attachment', 'delete_all_sizes');

Patrik

On 09/05/2010 11:39 PM, Mike Schinkel wrote:
> I have one question though, on this line:
>
>    
>> >  	$metadata['sizes']['thumbnail'] = array('file' =>   basename($file), 'width' =>   100, 'height' =>   100);
>>      
> Are you replacing the thumbnail with your custom size?  I'm unclear on what you are attempting to achieve here (maybe because I'm not 100% clear how WordPress' image handling all works, but not for lack of inspecting the code that does image handling.)
>    



More information about the wp-hackers mailing list