Ejemplo n.º 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;
    }
}
Ejemplo n.º 2
0
function rocket_upgrader()
{
    // Grab some infos
    $actual_version = get_rocket_option('version');
    // You can hook the upgrader to trigger any action when WP Rocket is upgraded
    // first install
    if (!$actual_version) {
        do_action('wp_rocket_first_install');
    } elseif (WP_ROCKET_VERSION != $actual_version) {
        do_action('wp_rocket_upgrade', WP_ROCKET_VERSION, $actual_version);
    }
    // If any upgrade has been done, we flush and update version #
    if (did_action('wp_rocket_first_install') || did_action('wp_rocket_upgrade')) {
        flush_rocket_htaccess();
        rocket_renew_all_boxes(0, array('rocket_warning_plugin_modification'));
        $options = get_option(WP_ROCKET_SLUG);
        // do not use get_rocket_option() here
        $options['version'] = WP_ROCKET_VERSION;
        $keys = rocket_check_key('live');
        if (is_array($keys)) {
            $options = array_merge($keys, $options);
        }
        update_option(WP_ROCKET_SLUG, $options);
    } else {
        if (empty($_POST) && rocket_valid_key()) {
            rocket_check_key('transient_30');
        }
    }
    /** This filter is documented in inc/admin-bar.php */
    if (!rocket_valid_key() && current_user_can(apply_filters('rocket_capacity', 'manage_options')) && (!isset($_GET['page']) || 'wprocket' != $_GET['page'])) {
        add_action('admin_notices', 'rocket_need_api_key');
    }
}
function __rocket_after_update_edd_options($old_value, $value)
{
    if ($old_value['purchase_page'] != $value['purchase_page'] || $old_value['jigoshop_cart_page_id'] != $value['jigoshop_cart_page_id'] || $old_value['jigoshop_checkout_page_id'] != $value['jigoshop_checkout_page_id']) {
        // Update .htaccess file rules
        flush_rocket_htaccess();
        // Update config file
        rocket_generate_config_file();
    }
}
Ejemplo n.º 4
0
 /**
  * Regenerate file 
  *
  * ## OPTIONS
  *
  * [--file=<file>]
  * : The file to regenerate. It could be: 
  *	- htaccess 
  *	- advanced-cache
  *	- config (It's the config file stored in the wp-rocket-config folder)
  *
  * ## EXAMPLES
  *
  *	   wp rocket regenerate --file=htaccess
  *
  * @subcommand regenerate
  */
 public function regenerate($args = array(), $assoc_args = array())
 {
     if (!empty($assoc_args['file'])) {
         switch ($assoc_args['file']) {
             case 'advanced-cache':
                 rocket_generate_advanced_cache_file();
                 WP_CLI::success('The advanced-cache.php file has just been regenerated.');
                 break;
             case 'config':
                 rocket_generate_config_file();
                 WP_CLI::success('The config file has just been regenerated.');
                 break;
             case 'htaccess':
                 $GLOBALS['is_apache'] = true;
                 flush_rocket_htaccess();
                 WP_CLI::success('The .htaccess file has just been regenerated.');
                 break;
             default:
                 WP_CLI::error('You don\'t specify a good value for the "file" argument. It should be: advanced-cache, config or htaccess.');
                 break;
         }
     } else {
         WP_CLI::error('You don\'t specify the "file" argument.');
     }
 }
Ejemplo n.º 5
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));
}