• Resolved Henk Barreveld

    (@henk-barreveld)


    Dear WP-Optimize team,

    I am using a facility on my website to put it in maintenance mode, so that only admin users get access and other users get a nice “website out of order”-message.

    The changes on the website for which I put it in maintenance mode often require that old cached data will no longer be used afterwards. Therefore I built in my software a facility so that, when the website is put back online, the WP-Optimize page and minify caches are automatically purged.

    To do this I used an ‘undocumented’ WP-Optimize feature and I would like to be sure that the way I did this is correct.

    Here is my PHP function:

    function my_theme_clear_wpo_caches() {
        if ( ! defined( 'WPO_PLUGIN_MAIN_PATH' ) ) return false;
        if ( ! class_exists( 'WP_Optimize_Minify_Commands' ) )
            include_once( WPO_PLUGIN_MAIN_PATH . 
            'minify/class-wp-optimize-minify-commands.php' );
    
        $minify_commands = new WP_Optimize_Minify_Commands();
        return $minify_commands->purge_all_minify_cache();
    }

    I would very much appreciate if you could let me know if this is indeed all right. Of course I could simply delete the folders wpo-cache and wpo-minify but I would like to be sure to avoid creating conflicts with any administration WP-Optimize may maintain about its cache data.

    Best regards,
    Henk Barreveld

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hi Henk,

    Yes this should work fine. You could also directly use the class WP_Optimize_Minify_Cache_Functions which handles the cache, something like WP_Optimize_Minify_Cache_Functions::reset().

    Your method also clears the page cache.
    For making your code future proof, you’d probably want to check that WPO_PLUGIN_MAIN_PATH . 'minify/class-wp-optimize-minify-commands.php' exists
    and that $minify_commands->purge_all_minify_cache() is callable, in case the code structure was to change.

    Best regards,
    Marc

    Thread Starter Henk Barreveld

    (@henk-barreveld)

    Hi Marc,

    Thank you, also for your suggestions to make this more robust! I will look into this further, following your advice.

    For now I am happy to conclude that this issue can be closed. I still have a question, but that is about something different, so I will open a new item for it.

    Best regards,
    Henk

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Programmatically purge all cache and minify data’ is closed to new replies.