I got strange behaviour when I added filter for attachment_fields_to_save, when I save the images, it does not want to save image metadata such as title, description and caption.
Why I need to add this filter? Because I have lots of custom sizes using this code:
add_image_size("imagesize-940x360", 940, 360, true);
And the image may not correctly put in good place, so the user need to use WordPress awesome tools to edit the image like cropping and scaling.
For some silly reason (or perhaps this is bug), the WordPress does not generate image for custom image sizes.
In order to achieve generation for custom sizes, I need to add filter when user press save button in the WordPress image editor. Here is the piece code that I been using:
add_filter("attachment_fields_to_save", "rl_regenerate_image", 99, 2);
function rl_regenerate_image($post, $attachment)
{
$id = $post['ID'];
$fullsizepath = get_attached_file($id);
wp_update_attachment_metadata($id, wp_generate_attachment_metadata($id, $fullsizepath));
return true;
}
The code above generates the custom sizes when user edit the image correctly but sadly it does not save all updated metadata images such as title, caption and description.
Do you guys know how to solve this problem? So what I would like to achieve is how to generate “edited” images for custom sizes and save the metadata correctly.
Thanks in advance!
In case this hasn’t been solved yet, or for any Googler’s out there.. Here’s a plugin called Post Thumbnail Editor that lets you edit individual custom image sizes. Works well.
http://wordpress.org/extend/plugins/post-thumbnail-editor/