function purge_cache_all()
 {
     if (function_exists('rocket_clean_domain') || function_exists('rocket_clean_minify') || function_exists('create_rocket_uniqid')) {
         // Remove all cache files
         rocket_clean_domain();
         // Remove all minify cache files
         rocket_clean_minify();
         // Generate a new random key for minify cache file
         $options = get_option(WP_ROCKET_SLUG);
         $options['minify_css_key'] = create_rocket_uniqid();
         $options['minify_js_key'] = create_rocket_uniqid();
         remove_all_filters('update_option_' . WP_ROCKET_SLUG);
         update_option(WP_ROCKET_SLUG, $options);
         rocket_dismiss_box('rocket_warning_plugin_modification');
         return array('result' => 'SUCCESS');
     } else {
         return array('error' => 'function_not_exist');
     }
 }
Exemple #2
1
function rocket_after_save_options($oldvalue, $value)
{
    if (!(is_array($oldvalue) && is_array($value))) {
        return;
    }
    // This values do not need to clean the cache domain
    $removed = array('purge_cron_interval' => true, 'purge_cron_unit' => true, 'wl_plugin_name' => true, 'wl_plugin_URI' => true, 'wl_author' => true, 'wl_author_URI' => true, 'wl_description' => true, 'wl_plugin_slug' => true);
    // Create 2 arrays to compare
    $oldvalue_diff = array_diff_key($oldvalue, $removed);
    $value_diff = array_diff_key($value, $removed);
    // If it's different, clean the domain
    if (md5(serialize($oldvalue_diff)) !== md5(serialize($value_diff))) {
        // Purge all cache files
        rocket_clean_domain();
    }
    // Purge all minify cache files
    if (!empty($_POST) && ($oldvalue['minify_css'] != $value['minify_css'] || $oldvalue['exclude_css'] != $value['exclude_css']) || (isset($oldvalue['cdn']) && !isset($value['cdn']) || !isset($oldvalue['cdn']) && isset($value['cdn']))) {
        rocket_clean_minify('css');
    }
    if (!empty($_POST) && ($oldvalue['minify_js'] != $value['minify_js'] || $oldvalue['exclude_js'] != $value['exclude_js']) || (isset($oldvalue['cdn']) && !isset($value['cdn']) || !isset($oldvalue['cdn']) && isset($value['cdn']))) {
        rocket_clean_minify('js');
    }
    // Update CloudFlare Development Mode
    if (!empty($_POST) && $oldvalue['cloudflare_devmode'] != $value['cloudflare_devmode']) {
        set_rocket_cloudflare_devmode((bool) $value['cloudflare_devmode']);
    }
    // Update CloudFlare settings
    if (!empty($_POST) && $oldvalue['cloudflare_auto_settings'] != $value['cloudflare_auto_settings']) {
        $cf_old_settings = explode(',', $value['cloudflare_old_settings']);
        // Set Cache Level to Aggressive
        $cf_cache_lvl = isset($cf_old_settings[0]) && $value['cloudflare_auto_settings'] == 0 ? $cf_old_settings[0] : 'agg';
        set_rocket_cloudflare_cache_lvl($cf_cache_lvl);
        // Active Minification for HTML, CSS & JS
        $cf_minify = isset($cf_old_settings[1]) && $value['cloudflare_auto_settings'] == 0 ? $cf_old_settings[1] : 7;
        set_rocket_cloudflare_minify($cf_minify);
        // Deactive Rocket Loader to prevent conflicts
        $cf_async = isset($cf_old_settings[2]) && $value['cloudflare_auto_settings'] == 0 ? $cf_old_settings[2] : false;
        set_rocket_cloudflare_async($cf_async);
    }
    // Update .htaccess file rules
    flush_rocket_htaccess(!rocket_valid_key());
    // Update config file
    rocket_generate_config_file();
    // Set WP_CACHE constant in wp-config.php
    if (!defined('WP_CACHE') || !WP_CACHE) {
        set_rocket_wp_cache_define(true);
    }
    // Redirect on the correct page slug name to avoid false negative error message
    if (!empty($_POST) && $oldvalue['wl_plugin_name'] != $value['wl_plugin_name'] && isset($_POST['option_page'], $_POST['action']) && 'wp_rocket' == $_POST['option_page'] && 'update' == $_POST['action']) {
        add_settings_error('general', 'settings_updated', __('Settings saved.', 'rocket'), 'updated');
        set_transient('settings_errors', get_settings_errors(), 30);
        wp_redirect(admin_url('options-general.php?page=' . sanitize_key($value['wl_plugin_name']) . '&settings-updated=true'));
        die;
    }
}
Exemple #3
1
function rocket_purge_cache()
{
    if (isset($_GET['type'], $_GET['_wpnonce'])) {
        $_type = explode('-', $_GET['type']);
        $_type = reset($_type);
        $_id = explode('-', $_GET['type']);
        $_id = end($_id);
        if (!wp_verify_nonce($_GET['_wpnonce'], 'purge_cache_' . $_GET['type'])) {
            wp_nonce_ays('');
        }
        switch ($_type) {
            // Clear all cache domain
            case 'all':
                // Remove all cache files
                $lang = isset($_GET['lang']) && $_GET['lang'] != 'all' ? sanitize_key($_GET['lang']) : '';
                // Remove all cache files
                rocket_clean_domain($lang);
                // Remove all minify cache files
                rocket_clean_minify();
                // Generate a new random key for minify cache file
                $options = get_option(WP_ROCKET_SLUG);
                $options['minify_css_key'] = create_rocket_uniqid();
                $options['minify_js_key'] = create_rocket_uniqid();
                remove_all_filters('update_option_' . WP_ROCKET_SLUG);
                update_option(WP_ROCKET_SLUG, $options);
                rocket_dismiss_box('rocket_warning_plugin_modification');
                break;
                // Clear terms, homepage and other files associated at current post in back-end
            // Clear terms, homepage and other files associated at current post in back-end
            case 'post':
                rocket_clean_post($_id);
                break;
                // Clear cache file of the current page in front-end
            // Clear cache file of the current page in front-end
            case 'url':
                rocket_clean_files(wp_get_referer());
                break;
            default:
                wp_nonce_ays('');
                break;
        }
        wp_redirect(wp_get_referer());
        die;
    }
}
Exemple #4
0
function do_rocket_purge_cron()
{
    // Purge domain cache files
    rocket_clean_domain();
    // Purge minify cache files
    rocket_clean_minify();
    // Run WP Rocket Bot for preload cache files
    run_rocket_bot('cache-preload');
}