502 Error while trying to load WP Smush Pro settings

I'm getting a 502 error while going to WP Smush Settings. I've already tried a plugin/theme conflict test and contacted the host, they don't see anything that could be causing this. I have enabled debug, but it doesn't show any familiar information. I've also tried putting WP_MEMORY_LIMIT in the wp-config.php which didn't help as well. Any help is appreciated.

  • Adam Czajczyk

    Hello Craig Elkins

    I hope you're well today and thank you for your question!

    I have checked the site and the configuration and settings looks fine. However, I have found that there's nearly 40,000 items in Media Library, which is quite a lot.

    Unfortunately, there's an issue with WP Smush Pro related to this. Basically, the way WP is caching some metadata in the database and the way WP Smush re-generates smushing statistics, seems to be failing in some cases if there's a large (tens of thousands or more) amount of items.

    Our developers are already aware of that and are working on a fix, though I'm not able to give you an ETA at the moment so please make sure that you keep plugin up to date.

    I've also talked to the lead developer of the plugin and he's looking for a workaround for us so please also keep an eye on this ticket and I'll update it once I only get that workaround from him.

    Best regards,
    Adam

  • Adam Czajczyk

    Hello Craig Elkins

    I got a feedback from the developer and while our dev team is looking for a permanent fix, there's a "workaround" that should temporarily solve this, though it would also affect statistics on "Media -> WP Smush" page (may not be showing at all or they may be wrong).

    The workaround requires changing core files and we rarely recommend it but in this case it's the only way. I'm not sure if you're feeling comfortable with doing such things so let me know please and if so, I'll give you an instruction on what should be changed and in which files.

    If you prefer me to do it for you, that's fine but I'd need a direct access to the site to be able to do this. In this case, please send in:

    Subject: "Attn: Adam Czajczyk"

    - Mark to my attention, the subject line should contain only: ATTN: Adam Czajczyk
    - Do not include anything else in the subject line, doing so may delay our response due to how email filtering works.
    - Link back to this thread
    - login URL and admin account login credentials (may be a temporary admin account) data
    - Include FTP log-in details (hostname, username & password) or cPanel login credentials
    - Include path on a server where the site's WP is installed/located
    - Include any relevant URLs for your site

    Please use our contact form here https://premium.wpmudev.org/contact/#i-have-a-different-question

    Best regards,
    Adam

  • Adam Czajczyk

    Hello Craig Elkins

    Thank you for your response.

    In this case please try this:

    1. Inside /wp-content/plugins/wp-smush-pro/lib/ folder there's a file "class-wp-smush-ui"

    Open that file for editing and around the line #619 find this code:

    <div class="wp-smushit-container-right col-half float-l"><?php
    //Stats
    $this->smush_stats_container();
    if ( ! $WpSmush->validate_install() ) {

    From this code comment out this line

    $this->smush_stats_container();

    Resulting code should look like this:

    <div class="wp-smushit-container-right col-half float-l"><?php
    //Stats
    //$this->smush_stats_container();
    if ( ! $WpSmush->validate_install() ) {

    Save the file, clear caches on site and see if that helped. It can still take a while to load the page and it will load without smushing stats but it should help.

    2. If above alone didn't help, try commenting out yet another piece of code. In a file "class-wp-smush-admin.php" in the same folder find this code around line #420

    //Get resmush list, If we have a resmush list already, localize those ids
    				if ( $resmush_ids = get_option( "wp-smush-resmush-list" ) ) {
    					//get the attachments, and get lossless count
    					$this->resmush_ids = $resmush_ids;
    				}
    
    				//Setup all the stats
    				$this->setup_global_stats( true );
    
    				//Localize smushit_ids variable, if there are fix number of ids
    				$this->unsmushed_attachments = ! empty( $_REQUEST['ids'] ) ? array_map( 'intval', explode( ',', $_REQUEST['ids'] ) ) : array();
    
    				if ( empty( $this->unsmushed_attachments ) ) {
    					//Get attachments if all the images are not smushed
    					$this->unsmushed_attachments = $this->remaining_count > 0 ? $wpsmush_db->get_unsmushed_attachments() : array();
    					$this->unsmushed_attachments = ! empty( $this->unsmushed_attachments ) && is_array( $this->unsmushed_attachments ) ? array_values( $this->unsmushed_attachments ) : $this->unsmushed_attachments;
    				}

    and comment it out entirely like this:

    /*
    //Get resmush list, If we have a resmush list already, localize those ids
    				if ( $resmush_ids = get_option( "wp-smush-resmush-list" ) ) {
    					//get the attachments, and get lossless count
    					$this->resmush_ids = $resmush_ids;
    				}
    
    				//Setup all the stats
    				$this->setup_global_stats( true );
    
    				//Localize smushit_ids variable, if there are fix number of ids
    				$this->unsmushed_attachments = ! empty( $_REQUEST['ids'] ) ? array_map( 'intval', explode( ',', $_REQUEST['ids'] ) ) : array();
    
    				if ( empty( $this->unsmushed_attachments ) ) {
    					//Get attachments if all the images are not smushed
    					$this->unsmushed_attachments = $this->remaining_count > 0 ? $wpsmush_db->get_unsmushed_attachments() : array();
    					$this->unsmushed_attachments = ! empty( $this->unsmushed_attachments ) && is_array( $this->unsmushed_attachments ) ? array_values( $this->unsmushed_attachments ) : $this->unsmushed_attachments;
    				}
    */

    I hope this helps. Please note, however, that these changes would need to be re-applied upon update until the fix is released or the plugin should not be updated (though I'd rather suggest to update and then either roll back to the "patched copy" if necessary or re-apply changes).

    Also, please make sure that you keep the original copies of the modified files in case anything went wrong and they'd need to be restored.

    Let me know if that solves the issue for now, please.

    Kind regards,
    Adam

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.