Clear Cache Everywhere

The Clear Cache Everywhere plugin has some useful hooks for developers to use to further enhance its functionality.

cceverywhere_before_clear_cache

TYPE ⇢ Action

This hook is triggered before the plugin starts clearing any cache. It allows developers to perform custom actions, such as logging cache clearing attempts, notifying external systems, or executing any pre-clearance tasks.

Example Usage

PHP
/**
 * Log the start of the cache clearing process.
 */
add_action( 'cceverywhere_before_clear_cache', function () {
    // Check if WordPress debug mode is enabled
    if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
        // Log the cache clearing start with the current timestamp
        error_log( 'CCE: Starting cache clear at ' . current_time( 'mysql' ) );
    }
} );

cceverywhere_after_clear_cache

TYPE ⇢ Action

This hook is triggered after the cache clearing process is completed. It allows developers to perform custom actions following the cache clear event, such as clearing additional caches, notifying external systems, or performing any post-clearance tasks.

Example Usage

PHP
/**
 * Purge a custom cache directory after clearing all caches.
 *
 * This example checks if the "Purge Custom Cache Directory" option is enabled,
 * and if so, it purges files from a custom cache directory used by a specific plugin.
 */
add_action( 'cceverywhere_after_clear_cache', function() {
    // Define the prefix for settings
    $prefix = 'clear_cache_everywhere_';
    
    // Check if the option to purge the custom cache directory is enabled
    if ( get_option( $prefix . 'purge_custom_cache_directory', false ) ) {
        // Set the custom cache directory path
        $cache_dir = WP_CONTENT_DIR . '/cache/myplugin/';
        
        // Purge the directory if it exists
        if ( file_exists( $cache_dir ) ) {
            // Remove all files in the directory
            array_map( 'unlink', glob( $cache_dir . '*' ) );
        }
    }
} );

cceverywhere_custom_settings

TYPE ⇢ Filter

This filter allows developers to modify the settings fields for the plugin. It is particularly useful for adding custom configuration options in the plugin’s settings UI, such as adding a checkbox to control custom cache behavior.

Example Usage

PHP
/**
 * Add a custom settings field for purging a custom cache directory.
 *
 * This example adds a checkbox field in the plugin's settings page to enable or disable
 * the purging of a custom cache directory after clearing the main caches.
 * 
 * @param array $fields → An array of existing settings fields.
 *
 * @return array → The modified settings fields array, including any new custom fields.
 */
add_filter( 'cceverywhere_custom_settings', function( $fields ) {
    // Add a custom checkbox field to the settings page
    $fields[] = [
        'key'       => 'purge_custom_cache_directory', // Field key
        'title'     => __( 'Purge Custom Cache Directory', 'clear-cache-everywhere' ), // Field title
        'type'      => 'checkbox', // Field type
        'sanitize'  => 'sanitize_checkbox', // Sanitize callback
        'section'   => 'custom', // Section name in the settings
        'default'   => false, // Default value (unchecked)
        'comments'  => __( 'Enable this option to automatically purge a custom cache directory (e.g., for your plugin\'s cache). The cache will be cleared after the global cache is cleared.', 'clear-cache-everywhere' ), // Description
    ];
    
    return $fields; // Return the modified settings fields
} );

cceeverywhere_show_skipped_notice

TYPE ⇢ Filter

This filter controls whether or not to show the notice for cache clearing items that were skipped during the clearing process. Default is FALSE.

Example Usage

PHP
/**
 * Filter to always show the skipped cache clearing items notice.
 *
 */
add_filter( 'cceeverywhere_show_skipped_notice', '__return_true' );

Sign In

Register

Reset Password

Please enter your username or email address, you will receive a link to create a new password via email.