Skip to content

Include SpinupWP #9

@jordantrizz

Description

@jordantrizz
<?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}");
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions