Cant get plugin to work

The asset optimisation isnt working for me, I run the test and it gets to 100% then goes back to the same page again. Then if i click the activate button again it starts at 99%, gets to 100 then goes back to same screen.

  • Lindeni Mahlalela

    Hello craig

    I hope you are doing great today. I am sorry for the delayed response from our side and for the inconveniences caused.

    I have gone through your website's settings in an attempt to try and figure out what the issue is. I have uninstalled and reinstalled the plugin and finally did a quick conflict test to determine if there is any plugin that might be conflicting. I have noticed you have several optimization plugins and so I thought it might be related to cache or asset optimization by another plugin.

    I have tried deactivating some plugins and after deactivating Breeze, the caching plugin, I was able to activate the plugin and get it to work. When I checked the debug logs I found this debug entry which comes from the this caching plugin.

    PHP Fatal error: Uncaught Error: Call to undefined function wp_get_current_user() in /WP_CONTENT_DIR/plugins/breeze/inc/cache/execute-cache.php:120

    It is possible that some function are not yet available when requesting the in the WordPress life cycle especially when the function is called too early. To avoid this error, you or the plugin developer can wrap this call in a condition to check if the function exists and only call it if it exists or manually load the file that defines that function. Unfortunately this is a third party plugin so I cannot provide a fix for it, you should contact the plugin developer and report this or do the modification yourself if you are comfortable doing it.

    I verified that Breeze is the main cause by clicking "RE-CHECK FILES" in Hummingbird and the progress stayed at 0% all the time and when I refreshed the page Asset Optimization was deactivated again, any attempt to activate it with Breeze active was unsuccessful, bit once I deactivate Breeze and start over it all goes smoothly.

    There was also a warning with Hummingbird which was shown by the following entry in debug log:

    PHP Notice: Undefined index: HTTP_USER_AGENT in /WP_CONTENT_DIR/plugins/wp-hummingbird/core/modules/class-module-page-cache.php on line 509

    I have downloaded and modified the file to fix the issue but I could not uplaod it to your website as it seems the user account you shared does not have write permissions to your server. So what you can do is to modify the file by replacing the line:

    $agent = $_SERVER['HTTP_USER_AGENT'] ;

    WIth

    $agent = $_SERVER['HTTP_USER_AGENT'] ? $_SERVER['HTTP_USER_AGENT'] : "";

    On line 509 of the file mentioned in the warning. Please note that this is just a warning and should not cause any issues, Hummingbird should continue to work even without the modification. You may also simply replace the file in the location:

    /WP_CONTENT_DIR/plugins/wp-hummingbird/core/modules/class-module-page-cache.php
    With the one contained in the attached 'class-module-page-cache.zip' file.

    Please note that it may not be a good idea to have multiple plugins doing the same thing as I have noticed that Autoptimize plugin is already attempting to do the exact same thing that Hummingbird Asset Optimization does, please double check your setting and whether you need this duplicate functionality or not, or maybe you are migrating to use one of them instead.

    I suggest you patch the files mentioned above and all should work properly, for the Breeze plugin you should contact the developer which seems to be CloudWays and for the Hummingbird PHP warning you can patch as mentioned above.

    For now, all seems to be working fine and I hope it continues to work. Please run some tests on your side and let us know if you have any further issues with regards to this and we will be happy to help.

    Have a nice day.
    Lindeni

  • Lindeni Mahlalela

    Hello again craig

    I forgot to add alittle help with regards to the PHP Fatal Error related to Breeze. The reason why the function is not defined is because it was called before it was made available by WordPress, the appropriate time to call it is after or on the plugins_loaded hook. If not, it must be wrapped as follows:

    if ( function_exists('wp_get_current_user') ) {
                $current_user = wp_get_current_user();
                if (in_array('administrator', $current_user->roles)) {
                    return $buffer;
                }
    }

    This should replace line 120 to 123 on the file in:

    /WP_CONTENT_DIR/plugins/breeze/inc/cache/execute-cache.php

    Usually, it might be of great benefit to call the entire function 'breeze_cache' with the plugins_loaded action hook, at which point the function will be available, it can be called like so:

    add_action("plugins_loaded", "breeze_cache");

    This is just an example, implementing this will require restructuring the bloc of code above the line:

    function breeze_cache($buffer, $flags)

    To wrap it inside its own function which can then be called with

    add_action('plugins_loaded', 'function_name');

    And that should get rid of the error, but I am not sure about the reason why the developers of Breeze implemented it like that, it might be because they wanted the code to execute earlier than plugins_loaded, in which case the best way is to wrap it in the if function_exists condition as in the first option above, this might break the intended functionality because the code inside the condition will not be executed if the function does not exist regardless of whether the user is logged in or not.

    You can patch this or contact the plugin's developer about this and they will be able to find the most appropriate solution for this.

    I hope this helps, please let us know if you need any further information.

    Have a nice day.
    Lindeni