Support » Plugin: EWWW Image Optimizer » Calling Function Manually

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author nosilver4u


    it’s going to be a while (if ever), since I’m in the middle of expanding support to Windows & FreeBSD, and I’ve not seen the documentation for creating a new wp_image_editor class yet. At any rate, EWWW IO works with the existing Worpdress resize functions by running when the metadata is updated, so I’m curious to see why/if the one you are using skips that step. Generally, any resize operation (at least using the default WP method) creates a file with a new name, which requires calling the function to update metadata, which is where I’ve hooked into.

    All that to say, it SHOULD already work. If it doesn’t, that is quite strange.

    Interesting, can you point me to the best place to throw in an output to see when it runs? Something like echo “I am running”; exit();?


    Maybe it is running, but PageSpeed is kicking the new images back saying they need to be optimized by about 4% each. You can see below that wp_update_attachment_metadata does get called.

    $editor->crop( $src_x, $src_y, $src_w, $src_h, $dest_width, $dest_height );
    $saved = $editor->save( $dest_file_name );
    // Add the resized dimensions to original image metadata (so we can delete our resized images when the original image is delete from the Media Library)
    $metadata = wp_get_attachment_metadata( $get_attachment[0]->ID );
    if ( isset( $metadata['image_meta'] ) ) {
    	$metadata['image_meta']['resized_images'][] = $resized_width .'x'. $resized_height;
    	wp_update_attachment_metadata( $get_attachment[0]->ID, $metadata );

    Here is a link to the core file that handles the ->save above:

    Plugin Author nosilver4u


    You could put that somewhere around line 787 in ewww-image-optimizer.php
    The ewww_image_optimizer() function gets called anytime an optimize is called for (on a resize, upload, bulk action, etc.), and that would let you know if the hook is working.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Calling Function Manually’ is closed to new replies.