0

I would like to use wp_save_image_editor_file filter, but there is no documentation on the internet. Also, it seems that no matter how many arguments I pass to the handler, all are null.

2
  • 2
    Could you please tell us for what purpose and how you want to use the filter?
    – kaiser
    Mar 15, 2013 at 14:57
  • @kaiser basically I want to do this: store all uploaded media on a different server (cdn or whatsoever). I managed to store all files, including image thumbnails, but I have some problems on moving edited images. Mar 15, 2013 at 15:53

1 Answer 1

2

The filter inside ~/wp-admin/includes/image.edit.php looks like this:

apply_filters('wp_save_image_editor_file', null, $filename, $image, $mime_type, $post_id);

So a callback would look like the following:

add_filter( 'wp_save_image_editor_file', 'wpse91038_saved_image_editor_file', 10, 5 );
function wpse91038_saved_image_editor_file( $saved, $filename, $image, $mime_type, $post_id )
{
    var_dump( $saved );
    var_dump( $filename );
    var_dump( $image );
    var_dump( $mime_type );
    var_dump( $post_id );
    return $saved;
}

Right above the core filter, there's another filter:

apply_filters('image_editor_save_pre', $image, $post_id);

The result of this filter, is then used as the 3rd argument inside the wp_save_image_editor_file-filter.

Then there's another important thing to note: If your custom wp_save_image_editor_file callback/function returns anything that is not NULL, then the core function will abort:

if ( null !== $saved )
    return $saved;

return $image->save( $filename, $mime_type );

So you either do the $image->save( $filename, $mime_type ); inside your callback, or you will be left with an image that doesn't get saved. And if you want to do so, then better don't return the $saved with no value/NULL.

3
  • @Marius.Radvan Then please mark it as "solution" by checking the check mark below the voting arrows. Thanks.
    – kaiser
    Mar 15, 2013 at 15:29
  • I will have one more question - since I only return $saved which is null, how can I change the filename saved in the database for the edited file? Eg: in this handler I make some more modifications to the file, saved it to altered($filename), then I want to add in the database the new filelocation Mar 15, 2013 at 15:29
  • @Marius.Radvan Just read the last paragraph of the answer again. :)
    – kaiser
    Mar 15, 2013 at 15:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.