Example #1
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;
    }
}
 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');
     }
 }
Example #3
1
function rocket_new_upgrade($wp_rocket_version, $actual_version)
{
    if (version_compare($actual_version, '1.0.1', '<')) {
        wp_clear_scheduled_hook('rocket_check_event');
    }
    if (version_compare($actual_version, '1.2.0', '<')) {
        // Delete old WP Rocket cache dir
        rocket_rrmdir(WP_ROCKET_PATH . 'cache');
        // Create new WP Rocket cache dir
        if (!is_dir(WP_ROCKET_CACHE_PATH)) {
            mkdir(WP_ROCKET_CACHE_PATH);
        }
    }
    if (version_compare($actual_version, '1.3.0', '<')) {
        rocket_dismiss_box('rocket_warning_plugin_modification');
    }
    if (version_compare($actual_version, '1.3.3', '<')) {
        // Clean cache
        rocket_clean_domain();
        // Create cache files
        run_rocket_bot('cache-preload');
    }
    if (version_compare($actual_version, '2.0', '<')) {
        // Add secret cache key
        $options = get_option(WP_ROCKET_SLUG);
        $options['secret_cache_key'] = create_rocket_uniqid();
        update_option(WP_ROCKET_SLUG, $options);
        global $wp_filesystem;
        if (!$wp_filesystem) {
            require_once ABSPATH . 'wp-admin/includes/class-wp-filesystem-base.php';
            require_once ABSPATH . 'wp-admin/includes/class-wp-filesystem-direct.php';
            $wp_filesystem = new WP_Filesystem_Direct(new StdClass());
        }
        // Get chmod of old folder cache
        $chmod = is_dir(WP_CONTENT_DIR . '/wp-rocket-cache') ? substr(sprintf('%o', fileperms(WP_CONTENT_DIR . '/wp-rocket-cache')), -4) : CHMOD_WP_ROCKET_CACHE_DIRS;
        // Check and create cache folder in wp-content if not already exist
        if (!$wp_filesystem->is_dir(WP_CONTENT_DIR . '/cache')) {
            $wp_filesystem->mkdir(WP_CONTENT_DIR . '/cache', octdec($chmod));
        }
        $wp_filesystem->mkdir(WP_CONTENT_DIR . '/cache/wp-rocket', octdec($chmod));
        // Move old cache folder in new path
        @rename(WP_CONTENT_DIR . '/wp-rocket-cache', WP_CONTENT_DIR . '/cache/wp-rocket');
        // Add WP_CACHE constant in wp-config.php
        set_rocket_wp_cache_define(true);
        // Create advanced-cache.php file
        rocket_generate_advanced_cache_file();
        // Create config file
        rocket_generate_config_file();
    }
    if (version_compare($actual_version, '2.1', '<')) {
        rocket_reset_white_label_values(false);
        // Create minify cache folder if not exist
        if (!is_dir(WP_ROCKET_MINIFY_CACHE_PATH)) {
            rocket_mkdir_p(WP_ROCKET_MINIFY_CACHE_PATH);
        }
        // Create config domain folder if not exist
        if (!is_dir(WP_ROCKET_CONFIG_PATH)) {
            rocket_mkdir_p(WP_ROCKET_CONFIG_PATH);
        }
        // Create advanced-cache.php file
        rocket_generate_advanced_cache_file();
        // Create config file
        rocket_generate_config_file();
    }
    if (version_compare($actual_version, '2.3.3', '<')) {
        // Clean cache
        rocket_clean_domain();
        // Create cache files
        run_rocket_bot('cache-preload');
    }
    if (version_compare($actual_version, '2.3.9', '<')) {
        // Regenerate config file
        rocket_generate_config_file();
    }
    if (version_compare($actual_version, '2.4.1', '<')) {
        // Regenerate advanced-cache.php file
        rocket_generate_advanced_cache_file();
        delete_transient('rocket_ask_for_update');
    }
    if (version_compare($actual_version, '2.6', '<')) {
        // Activate Inline CSS & JS minification if HTML minification is activated
        $options = get_option(WP_ROCKET_SLUG);
        if (!empty($options['minify_html'])) {
            $options['minify_html_inline_css'] = 1;
            $options['minify_html_inline_js'] = 1;
        }
        update_option(WP_ROCKET_SLUG, $options);
        // Regenerate advanced-cache.php file
        rocket_generate_advanced_cache_file();
    }
}
Example #4
0
/**
 * Renew all boxes for everyone if $uid is missing
 *
 * @since 1.1.10
 * @modified 2.1 :
 *	- Better usage of delete_user_meta into delete_metadata
 *
 * @param (int|null)$uid : a User id, can be null, null = all users
 * @param (string|array)$keep_this : which box have to be kept
 * @return void
 */
function rocket_renew_all_boxes($uid = null, $keep_this = array())
{
    // Delete a user meta for 1 user or all at a time
    delete_metadata('user', $uid, 'rocket_boxes', null == $uid);
    // $keep_this works only for the current user
    if (!empty($keep_this) && null != $uid) {
        if (is_array($keep_this)) {
            foreach ($keep_this as $kt) {
                rocket_dismiss_box($kt);
            }
        } else {
            rocket_dismiss_box($keep_this);
        }
    }
}