Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include SpinupWP #9

Open
jordantrizz opened this issue Aug 30, 2024 · 0 comments
Open

Include SpinupWP #9

jordantrizz opened this issue Aug 30, 2024 · 0 comments

Comments

@jordantrizz
Copy link
Collaborator

<?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}");
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant