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');
     }
 }
Exemplo n.º 2
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;
    }
}
Exemplo n.º 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();
    }
}
Exemplo n.º 4
0
/**
 * Get tag of a group of files or JS minified CSS
 *
 * @since 2.1
 *
 * @param array  $files List of files to minify (CSS or JS)
 * @param bool   $force_pretty_url (default: true)
 * @param string $pretty_filename (default: null) The new filename if $force_pretty_url set to true
 * @return string $tags
 */
function get_rocket_minify_files($files, $force_pretty_url = true, $pretty_filename = null)
{
    // Get the internal CSS Files
    // To avoid conflicts with file URLs are too long for browsers,
    // cut into several parts concatenated files
    $tags = '';
    $data_attr = 'data-minify="1"';
    $urls = array(0 => '');
    $base_url = WP_ROCKET_URL . 'min/?f=';
    $files = is_array($files) ? $files : (array) $files;
    if (count($files)) {
        $i = 0;
        foreach ($files as $file) {
            $file = parse_url($file, PHP_URL_PATH);
            // Replace "//" by "/" because it cause an issue with Google Code Minify!
            $file = str_replace('//', '/', $file);
            /**
             * Filter the total number of files generated by the minification
             *
             * @since 2.1
             *
             * @param string The maximum number of characters in a URL
             * @param string The file's extension
             */
            $filename_length = apply_filters('rocket_minify_filename_length', 255, pathinfo($file, PATHINFO_EXTENSION));
            // +1 : we count the extra comma
            if (strlen($urls[$i] . $base_url . $file) + 1 >= $filename_length) {
                $i++;
            }
            /**
             * Filter file to add in minification process
             *
             * @since 2.4
             *
             * @param string $file The file path
             */
            $file = apply_filters('rocket_pre_minify_path', $file);
            $urls[$i] .= $file . ',';
        }
        foreach ($urls as $url) {
            $url = $base_url . rtrim($url, ',');
            $ext = pathinfo($url, PATHINFO_EXTENSION);
            if ($force_pretty_url && (defined('SCRIPT_DEBUG') && !SCRIPT_DEBUG)) {
                /**
                 * Filter the minify URL
                 *
                 * If true returns,
                 * the minify URL like example.com/wp-content/plugins/wp-rocket/min/?f=...
                 *
                 * @since 2.1
                 *
                 * @param bool
                 */
                if (!apply_filters('rocket_minify_debug', false)) {
                    $blog_id = get_current_blog_id();
                    $pretty_url = !$pretty_filename ? WP_ROCKET_MINIFY_CACHE_URL . $blog_id . '/' . md5($url . get_rocket_option('minify_' . $ext . '_key', create_rocket_uniqid())) . '.' . $ext : WP_ROCKET_MINIFY_CACHE_URL . $blog_id . '/' . $pretty_filename . '.' . $ext;
                    /**
                     * Filter the pretty minify URL
                     *
                     * @since 2.1
                     *
                     * @param string $pretty_url
                     * @param string $pretty_filename
                     */
                    $pretty_url = apply_filters('rocket_minify_pretty_url', $pretty_url, $pretty_filename);
                    $url = rocket_fetch_and_cache_minify($url, $pretty_url) ? $pretty_url : $url;
                }
            }
            // If CSS & JS use a CDN
            $url = get_rocket_cdn_url($url, array('all', 'css_and_js', $ext));
            if ($ext == 'css') {
                /**
                 * Filter CSS file URL with CDN hostname
                 *
                 * @since 2.1
                 *
                 * @param string $url
                 */
                $url = apply_filters('rocket_css_url', $url);
                $tags .= sprintf('<link rel="stylesheet" href="%s" %s/>', esc_attr($url), $data_attr);
            } elseif ($ext == 'js') {
                /**
                 * Filter JavaScript file URL with CDN hostname
                 *
                 * @since 2.1
                 *
                 * @param string $url
                 */
                $url = apply_filters('rocket_js_url', $url);
                $tags .= sprintf('<script src="%s" %s></script>', esc_attr($url), $data_attr);
            }
        }
    }
    return $tags;
}
Exemplo n.º 5
0
function rocket_pre_main_option($newvalue, $oldvalue)
{
    if (isset($newvalue['purge_cron_interval'], $oldvalue['purge_cron_interval']) && $newvalue['purge_cron_interval'] != $oldvalue['purge_cron_interval'] || isset($newvalue['purge_cron_unit'], $oldvalue['purge_cron_unit']) && $newvalue['purge_cron_unit'] != $oldvalue['purge_cron_unit']) {
        // Clear WP Rocket cron
        if (wp_next_scheduled('rocket_purge_time_event')) {
            wp_clear_scheduled_hook('rocket_purge_time_event');
        }
    }
    // Regenerate the minify key if CSS files have been modified
    if (isset($newvalue['minify_css'], $oldvalue['minify_css']) && $newvalue['minify_css'] != $oldvalue['minify_css'] || isset($newvalue['exclude_css'], $oldvalue['exclude_css']) && $newvalue['exclude_css'] != $oldvalue['exclude_css'] || (isset($oldvalue['cdn']) && !isset($newvalue['cdn']) || !isset($oldvalue['cdn']) && isset($newvalue['cdn']))) {
        $newvalue['minify_css_key'] = create_rocket_uniqid();
    }
    // Regenerate the minify key if JS files have been modified
    if (isset($newvalue['minify_js'], $oldvalue['minify_js']) && $newvalue['minify_js'] != $oldvalue['minify_js'] || isset($newvalue['exclude_js'], $oldvalue['exclude_js']) && $newvalue['exclude_js'] != $oldvalue['exclude_js'] || isset($newvalue['minify_js_in_footer'], $oldvalue['minify_js_in_footer']) && $newvalue['minify_js_in_footer'] != $oldvalue['minify_js_in_footer'] || (isset($oldvalue['cdn']) && !isset($newvalue['cdn']) || !isset($oldvalue['cdn']) && isset($newvalue['cdn']))) {
        $newvalue['minify_js_key'] = create_rocket_uniqid();
    }
    // Save old CloudFlare settings
    if (isset($newvalue['cloudflare_auto_settings'], $oldvalue['cloudflare_auto_settings']) && $newvalue['cloudflare_auto_settings'] != $oldvalue['cloudflare_auto_settings'] && $newvalue['cloudflare_auto_settings'] == 1) {
        $cf_settings = get_rocket_cloudflare_settings();
        $cf_settings = array($cf_settings->cache_lvl, (int) $cf_settings->minify, !is_string($cf_settings->async) ? (int) $cf_settings->async : $cf_settings->async);
        $cf_settings = array_filter($cf_settings);
        $newvalue['cloudflare_old_settings'] = isset($cf_settings) ? implode(',', $cf_settings) : '';
    }
    if (!defined('WP_ROCKET_ADVANCED_CACHE')) {
        rocket_generate_advanced_cache_file();
    }
    if ($keys = get_transient(WP_ROCKET_SLUG)) {
        delete_transient(WP_ROCKET_SLUG);
        $newvalue = array_merge($newvalue, $keys);
    }
    return $newvalue;
}