Example #1
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;
    }
}
Example #2
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 #3
0
 /**
  * Set WP_CACHE constant in wp-config.php to false
  *
  * ## EXAMPLES
  *
  *     wp rocket deactivate
  *
  * @subcommand deactivate
  */
 public function deactivate()
 {
     if (defined('WP_CACHE') && WP_CACHE) {
         if (is_writable(rocket_find_wpconfig_path())) {
             set_rocket_wp_cache_define(false);
             WP_CLI::success('WP Rocket is disable, WP_CACHE is set to false.');
         } else {
             WP_CLI::error('It seems we don\'t have writing permissions on wp-config.php file.');
         }
     } else {
         WP_CLI::error('WP Rocket is already disable.');
     }
 }
Example #4
0
function rocket_activation()
{
    // Last constants
    define('WP_ROCKET_PLUGIN_NAME', 'WP Rocket');
    define('WP_ROCKET_PLUGIN_SLUG', sanitize_key(WP_ROCKET_PLUGIN_NAME));
    if (defined('SUNRISE') && SUNRISE == 'on' && function_exists('domain_mapping_siteurl')) {
        require WP_ROCKET_INC_PATH . 'domain-mapping.php';
    }
    require WP_ROCKET_FUNCTIONS_PATH . 'options.php';
    require WP_ROCKET_FUNCTIONS_PATH . 'files.php';
    require WP_ROCKET_FUNCTIONS_PATH . 'formatting.php';
    require WP_ROCKET_FUNCTIONS_PATH . 'plugins.php';
    require WP_ROCKET_FUNCTIONS_PATH . 'i18n.php';
    require WP_ROCKET_FUNCTIONS_PATH . 'htaccess.php';
    if (rocket_valid_key()) {
        // Add All WP Rocket rules of the .htaccess file
        flush_rocket_htaccess();
        // Add WP_CACHE constant in wp-config.php
        set_rocket_wp_cache_define(true);
    }
    // Create the cache folders (wp-rocket & min)
    rocket_init_cache_dir();
    // Create the config folder (wp-rocket-config)
    rocket_init_config_dir();
    // Create advanced-cache.php file
    rocket_generate_advanced_cache_file();
    // Create config file
    rocket_generate_config_file();
    // Update customer key & licence.
    wp_remote_get(WP_ROCKET_WEB_API . 'activate-licence.php', array('blocking' => false));
}
Example #5
0
function __rocket_maybe_set_wp_cache_define()
{
    if (defined('WP_CACHE') && !WP_CACHE) {
        set_rocket_wp_cache_define(true);
    }
}