WP Smush Pro + WP Offload S3 - Critical Error: Ajax returns Error 500 on media library

The error was detected when smushing S3 images manually in media library. While investigating the Wordpress debug log the error could be pinpointed to the entry:

2018-06-14T10:32:17+00:00 CRITICAL Uncaught Error: Call to undefined method DeliciousBrains\WP_Offload_S3\Providers\AWS_Provider::doesObjectExist() in /********/plugins/wp-smush-pro/lib/class-wp-smush-s3.php:352

It seems that the function is called before the WP offload S3 plugin has fully loaded and initialised. Although the smushed images work this error effectively cripples the media library (e.g no further images can be loaded past the erroneous call while browsing the library and posts using the smushed images won't be able to load or select images in the post editor because of the error also breaking JS).

Fast responses and solutions are much appreciated.

  • Tedy Warsitha

    With further inspection I realised that the function called simply don't exist on line 352 in class-wp-smush-s3.php

    $file_exists = $s3client->doesObjectExist( $bucket, $s3_object['key'] );

    Should be

    $file_exists = $s3client->does_object_exist( $bucket, $s3_object['key'] );

    Notice the change from camel case to snake case.

    Once changed the error 500 disappears and smush is able to retrieve stats for the image.

    If there is any way I could submit my contribution in a pull request I'm happy to do it. Otherwise I'll leave this ticket open until an authored contributor can confirm this change.

  • Tedy Warsitha

    Thank you for the reply James!

    For anyone else looking for a temporary fix on plugin version here is how I did it. I copied and pasted the lines below from class-wp-smush-s3.php into a file required in my theme (e.g the theme file functions.php), containing

    // The plugin checks if this class exists - Replace it with your own
    class WpSmushS3 {
        [...] // Functions inside
    // Overriding also removes initialisation - Manually initialise the class
    global $wpsmush_s3;
    $wpsmush_s3 = new WpSmushS3();

    and replaced the faulty code inside the class as stated previously. By doing this you don't have to worry about the changes getting overwritten on deployment or plugin updates. Just remember to remove your own newly added patch once plugin authors have implemented a fix.

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.