• Resolved jordantrizz

    (@jordantrizz)


    Are you able to add SpinupWP to the list of providers.

    <?php
    /*
    * Add this to your theme functions.php, or add to a plugin.
    *
    */

    /**
    * Clear the SpinupWP Cache for the entire website.
    */
    function clear_spinup_cache(): bool
    {

    if (! class_exists('SpinupWp\Cache')) {
    return false;
    }

    $class_spinup_admin = new SpinupWp\AdminBar('/wp-content/plugins/spinupwp/');
    $class_spinup_cli = new SpinupWp\Cli;
    $class_spinup_cache = new SpinupWp\Cache($class_spinup_admin, $class_spinup_cli);

    if ($class_spinup_cache->is_page_cache_enabled()) {
    $purge = $GLOBALS['spinupwp']->cache->purge_page_cache();
    $type = 'Page cache';
    $res = $purge ? 'Cleared' : 'Not Cleared';
    helpers\log("Purging {$type} result: {$res}");
    }

    if ($class_spinup_cache->is_object_cache_enabled()) {
    $purge = $GLOBALS['spinupwp']->cache->purge_object_cache();
    $type = 'Object cache';
    $res = $purge ? 'Cleared' : 'Not Cleared';
    // Commenting out because this helper class is unique to stafflink.
    //helpers\log("Purging {$type} result: {$res}");
    }

    return true;
    }

    /**
    * Clear the cache for the specific URL only.
    */
    function clear_spinup_cache_for_this_url(): bool
    {
    // exit quickly if spinup plugin does not exist
    if (! class_exists('SpinupWp\Cache')) {
    return false;
    }

    $url = home_url().'/wp-content/plugins/spinupwp/';
    $class_spinup_admin = new SpinupWp\AdminBar($url);
    $class_spinup_cli = new SpinupWp\Cli;
    $class_spinup_cache = new SpinupWp\Cache($class_spinup_admin, $class_spinup_cli);

    if ($class_spinup_cache->is_page_cache_enabled()) {
    $url = $_SERVER['HTTP_REFERER'];
    $purge = $GLOBALS['spinupwp']->cache->purge_url($url);
    $type = 'URL page cache';
    $res = $purge ? 'Cleared' : 'Not Cleared';

    // Log page cache if success
    // Commented out because this helper class is unique to STAFFLINK.
    //helpers\log("Purging {$type} result: {$res}");
    }
    }
Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Kevin Pirnie

    (@kevp75)

    I will take a look

    Thanks

    Plugin Author Kevin Pirnie

    (@kevp75)

    This will be in the next version… will be out soon

    @kevp75 Thanks for adding this!

    Just a heads up that SpinupWP does disable opcache_get_status() by default, so this will throw a fatal php error (specifically it happened for me when trying to save a menu):

    Error Details
    =============
    An error of type E_ERROR was caused in line 126 of the file /sites/nda-mn.org/files/wp-content/plugins/the-cache-purger/work/inc/modules/php.php. Error message: Uncaught Error: Call to undefined function opcache_get_status() in /sites/nda-mn.org/files/wp-content/plugins/the-cache-purger/work/inc/modules/php.php:126
    Stack trace:
    #0 /sites/nda-mn.org/files/wp-content/plugins/the-cache-purger/work/inc/modules/php.php(65): KP_Cache_Purge->purge_php_opcache()
    #1 /sites/nda-mn.org/files/wp-content/plugins/the-cache-purger/work/inc/kp-cache-purge.php(123): KP_Cache_Purge->purge_php_caches()
    #2 /sites/nda-mn.org/files/wp-content/plugins/the-cache-purger/work/inc/kp-cache-purge-processor.php(606): KP_Cache_Purge->kp_do_purge()
    #3 /sites/nda-mn.org/files/wp-includes/class-wp-hook.php(326): KP_Cache_Purge_Processor->{closure}()
    #4 /sites/nda-mn.org/files/wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters()
    #5 /sites/nda-mn.org/files/wp-includes/plugin.php(517): WP_Hook->do_action()
    #6 /sites/nda-mn.org/files/wp-includes/taxonomy.php(3474): do_action()
    #7 /sites/nda-mn.org/files/wp-includes/nav-menu.php(386): wp_update_term()
    #8 /sites/nda-mn.org/files/wp-admin/nav-menus.php(486): wp_update_nav_menu_object()
    #9 {main}
    thrown

    The server admin can remove this in the php.ini to fix the fatal error which is what I ended up doing. I’m not sure if this function is crucial for your plugin to work but maybe it would be worth doing a function_exists('opcache_get_status') on it first to avoid the fatal error?

    Thanks again!

    Plugin Author Kevin Pirnie

    (@kevp75)

    Interesting…

    It shouldn’t have been erroring at all, I tossed an @ before it which should have been silencing any error output.

    However, even doing as you suggested will not correct the underlying issue. We need that method to ensure opcache is actually being utilized in order to clear it. It has a flag: opcache_enabled

    I’m not sure that I will correct this… maybe the error from popping, but I can’t correct anything beyond that… but even correcting that will not fulfill the purpose of the plugin, in that… opcache needs to be cleared…

    I’ll think on this and see if I can come up with some other way…

Viewing 4 replies - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.