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'); } }
/** * Used to clean and sanitize the settings fields * * @since 1.0 */ function rocket_settings_callback($inputs) { if (isset($_GET['action']) && 'purge_cache' == $_GET['action']) { return $inputs; } /* * Option : Minification CSS & JS */ $inputs['minify_css'] = !empty($inputs['minify_css']) ? 1 : 0; $inputs['minify_js'] = !empty($inputs['minify_js']) ? 1 : 0; /* * Option : Purge delay */ $inputs['purge_cron_interval'] = isset($inputs['purge_cron_interval']) ? (int) $inputs['purge_cron_interval'] : get_rocket_option('purge_cron_interval'); $inputs['purge_cron_unit'] = isset($inputs['purge_cron_unit']) ? $inputs['purge_cron_unit'] : get_rocket_option('purge_cron_unit'); /* * Option : Prefetch DNS requests */ if (!empty($inputs['dns_prefetch'])) { if (!is_array($inputs['dns_prefetch'])) { $inputs['dns_prefetch'] = explode("\n", $inputs['dns_prefetch']); } $inputs['dns_prefetch'] = array_map('trim', $inputs['dns_prefetch']); $inputs['dns_prefetch'] = array_map('esc_url', $inputs['dns_prefetch']); $inputs['dns_prefetch'] = (array) array_filter($inputs['dns_prefetch']); $inputs['dns_prefetch'] = array_unique($inputs['dns_prefetch']); } else { $inputs['dns_prefetch'] = array(); } /* * Option : Empty the cache of the following pages when updating an article */ if (!empty($inputs['cache_purge_pages'])) { if (!is_array($inputs['cache_purge_pages'])) { $inputs['cache_purge_pages'] = explode("\n", $inputs['cache_purge_pages']); } $inputs['cache_purge_pages'] = array_map('trim', $inputs['cache_purge_pages']); $inputs['cache_purge_pages'] = array_map('esc_url', $inputs['cache_purge_pages']); $inputs['cache_purge_pages'] = array_map('rocket_clean_exclude_file', $inputs['cache_purge_pages']); $inputs['cache_purge_pages'] = (array) array_filter($inputs['cache_purge_pages']); $inputs['cache_purge_pages'] = array_unique($inputs['cache_purge_pages']); } else { $inputs['cache_purge_pages'] = array(); } /* * Option : Never cache the following pages */ if (!empty($inputs['cache_reject_uri'])) { if (!is_array($inputs['cache_reject_uri'])) { $inputs['cache_reject_uri'] = explode("\n", $inputs['cache_reject_uri']); } $inputs['cache_reject_uri'] = array_map('trim', $inputs['cache_reject_uri']); $inputs['cache_reject_uri'] = array_map('esc_url', $inputs['cache_reject_uri']); $inputs['cache_reject_uri'] = array_map('rocket_clean_exclude_file', $inputs['cache_reject_uri']); $inputs['cache_reject_uri'] = (array) array_filter($inputs['cache_reject_uri']); $inputs['cache_reject_uri'] = array_unique($inputs['cache_reject_uri']); } else { $inputs['cache_reject_uri'] = array(); } /* * Option : Don't cache pages that use the following cookies */ if (!empty($inputs['cache_reject_cookies'])) { if (!is_array($inputs['cache_reject_cookies'])) { $inputs['cache_reject_cookies'] = explode("\n", $inputs['cache_reject_cookies']); } $inputs['cache_reject_cookies'] = array_map('trim', $inputs['cache_reject_cookies']); $inputs['cache_reject_cookies'] = array_map('rocket_sanitize_cookie', $inputs['cache_reject_cookies']); $inputs['cache_reject_cookies'] = (array) array_filter($inputs['cache_reject_cookies']); $inputs['cache_reject_cookies'] = array_unique($inputs['cache_reject_cookies']); } else { $inputs['cache_reject_cookies'] = array(); } /* * Option : Cache pages that use the following query strings (GET parameters) */ if (!empty($inputs['cache_query_strings'])) { if (!is_array($inputs['cache_query_strings'])) { $inputs['cache_query_strings'] = explode("\n", $inputs['cache_query_strings']); } $inputs['cache_query_strings'] = array_map('trim', $inputs['cache_query_strings']); $inputs['cache_query_strings'] = array_map('sanitize_key', $inputs['cache_query_strings']); $inputs['cache_query_strings'] = (array) array_filter($inputs['cache_query_strings']); $inputs['cache_query_strings'] = array_unique($inputs['cache_query_strings']); } else { $inputs['cache_query_strings'] = array(); } /* * Option : Never send cache pages for these user agents */ if (!empty($inputs['cache_reject_ua'])) { if (!is_array($inputs['cache_reject_ua'])) { $inputs['cache_reject_ua'] = explode("\n", $inputs['cache_reject_ua']); } $inputs['cache_reject_ua'] = array_map('trim', $inputs['cache_reject_ua']); $inputs['cache_reject_ua'] = array_map('rocket_sanitize_ua', $inputs['cache_reject_ua']); $inputs['cache_reject_ua'] = (array) array_filter($inputs['cache_reject_ua']); $inputs['cache_reject_ua'] = array_unique($inputs['cache_reject_ua']); } else { $inputs['cache_reject_ua'] = array(); } /* * Option : CSS files to exclude of the minification */ if (!empty($inputs['exclude_css'])) { if (!is_array($inputs['exclude_css'])) { $inputs['exclude_css'] = explode("\n", $inputs['exclude_css']); } $inputs['exclude_css'] = array_map('trim', $inputs['exclude_css']); $inputs['exclude_css'] = array_map('rocket_clean_exclude_file', $inputs['exclude_css']); $inputs['exclude_css'] = array_map('rocket_sanitize_css', $inputs['exclude_css']); $inputs['exclude_css'] = (array) array_filter($inputs['exclude_css']); $inputs['exclude_css'] = array_unique($inputs['exclude_css']); } else { $inputs['exclude_css'] = array(); } /* * Option : JS files to exclude of the minification */ if (!empty($inputs['exclude_js'])) { if (!is_array($inputs['exclude_js'])) { $inputs['exclude_js'] = explode("\n", $inputs['exclude_js']); } $inputs['exclude_js'] = array_map('trim', $inputs['exclude_js']); $inputs['exclude_js'] = array_map('rocket_clean_exclude_file', $inputs['exclude_js']); $inputs['exclude_js'] = array_map('rocket_sanitize_js', $inputs['exclude_js']); $inputs['exclude_js'] = (array) array_filter($inputs['exclude_js']); $inputs['exclude_js'] = array_unique($inputs['exclude_js']); } else { $inputs['exclude_js'] = array(); } /* * Option : JS files with deferred loading */ if (!empty($inputs['deferred_js_files'])) { $inputs['deferred_js_files'] = array_unique($inputs['deferred_js_files']); $inputs['deferred_js_files'] = array_map('rocket_sanitize_js', $inputs['deferred_js_files']); $inputs['deferred_js_files'] = array_filter($inputs['deferred_js_files']); } else { $inputs['deferred_js_files'] = array(); } if (!$inputs['deferred_js_files']) { $inputs['deferred_js_wait'] = array(); } else { for ($i = 0; $i <= max(array_keys($inputs['deferred_js_files'])); $i++) { if (!isset($inputs['deferred_js_files'][$i])) { unset($inputs['deferred_js_wait'][$i]); } else { $inputs['deferred_js_wait'][$i] = isset($inputs['deferred_js_wait'][$i]) ? '1' : '0'; } } $inputs['deferred_js_files'] = array_values($inputs['deferred_js_files']); ksort($inputs['deferred_js_wait']); $inputs['deferred_js_wait'] = array_values($inputs['deferred_js_wait']); } /* * Option : JS files of the minification to insert in footer */ if (!empty($inputs['minify_js_in_footer'])) { foreach ($inputs['minify_js_in_footer'] as $k => $url) { if (in_array($url, $inputs['deferred_js_files'])) { unset($inputs['minify_js_in_footer'][$k]); } } $inputs['minify_js_in_footer'] = array_filter(array_map('rocket_sanitize_js', array_unique($inputs['minify_js_in_footer']))); } else { $inputs['minify_js_in_footer'] = array(); } /* * Option : WL */ $inputs['wl_plugin_name'] = isset($inputs['wl_plugin_name']) ? wp_strip_all_tags($inputs['wl_plugin_name']) : get_rocket_option('wl_plugin_name'); $inputs['wl_plugin_URI'] = isset($inputs['wl_plugin_URI']) ? esc_url($inputs['wl_plugin_URI']) : get_rocket_option('wl_plugin_URI'); $inputs['wl_author'] = isset($inputs['wl_author']) ? wp_strip_all_tags($inputs['wl_author']) : get_rocket_option('wl_author'); $inputs['wl_author_URI'] = isset($inputs['wl_author_URI']) ? esc_url($inputs['wl_author_URI']) : get_rocket_option('wl_author_URI'); $inputs['wl_description'] = isset($inputs['wl_description']) ? (array) $inputs['wl_description'] : get_rocket_option('wl_description'); $inputs['wl_plugin_slug'] = sanitize_key($inputs['wl_plugin_name']); /* * Option : CDN */ $inputs['cdn_cnames'] = isset($inputs['cdn_cnames']) ? array_unique(array_filter($inputs['cdn_cnames'])) : array(); if (!$inputs['cdn_cnames']) { $inputs['cdn_zone'] = array(); } else { for ($i = 0; $i <= max(array_keys($inputs['cdn_cnames'])); $i++) { if (!isset($inputs['cdn_cnames'][$i])) { unset($inputs['cdn_zone'][$i]); } else { $inputs['cdn_zone'][$i] = isset($inputs['cdn_zone'][$i]) ? $inputs['cdn_zone'][$i] : 'all'; } } $inputs['cdn_cnames'] = array_values($inputs['cdn_cnames']); ksort($inputs['cdn_zone']); $inputs['cdn_zone'] = array_values($inputs['cdn_zone']); } /* * Option : Files to exclude of the CDN process */ if (!empty($inputs['cdn_reject_files'])) { if (!is_array($inputs['cdn_reject_files'])) { $inputs['cdn_reject_files'] = explode("\n", $inputs['cdn_reject_files']); } $inputs['cdn_reject_files'] = array_map('trim', $inputs['cdn_reject_files']); $inputs['cdn_reject_files'] = array_map('rocket_clean_exclude_file', $inputs['cdn_reject_files']); $inputs['cdn_reject_files'] = (array) array_filter($inputs['cdn_reject_files']); $inputs['cdn_reject_files'] = array_unique($inputs['cdn_reject_files']); } else { $inputs['cdn_reject_files'] = array(); } /* * Option: Support */ $fake_options = array('support_summary', 'support_description', 'support_documentation_validation'); foreach ($fake_options as $option) { if (isset($inputs[$option])) { unset($inputs[$option]); } } if (isset($_FILES['import']) && preg_match('/wp-rocket-settings-20\\d{2}-\\d{2}-\\d{2}-[a-f0-9]{13}\\.txt/', $_FILES['import']['name']) && 'text/plain' == $_FILES['import']['type']) { $file_name = $_FILES['import']['name']; $_POST_action = $_POST['action']; $_POST['action'] = 'wp_handle_sideload'; $file = wp_handle_sideload($_FILES['import'], array('mimes' => array('txt' => 'text/plain'))); $_POST['action'] = $_POST_action; $gz = 'gz' . strrev('etalfni'); $settings = @file_get_contents($file['file']); $settings = $gz($settings); $settings = unserialize($settings); file_put_contents($file['file'], ''); @unlink($file['file']); if (is_array($settings)) { $settings['consumer_key'] = $inputs['consumer_key']; $settings['consumer_email'] = $inputs['consumer_email']; $settings['secret_key'] = $inputs['secret_key']; $settings['secret_cache_key'] = $inputs['secret_cache_key']; $settings['minify_css_key'] = $inputs['minify_css_key']; $settings['minify_js_key'] = $inputs['minify_js_key']; $settings['version'] = $inputs['version']; $inputs = $settings; add_settings_error('general', 'settings_updated', __('Settings imported and saved.', 'rocket'), 'updated'); } } if (!rocket_valid_key()) { $checked = rocket_check_key('live'); } else { $checked = rocket_check_key('transient_1'); } if (is_array($checked)) { $inputs['consumer_key'] = $checked['consumer_key']; $inputs['consumer_email'] = $checked['consumer_email']; $inputs['secret_key'] = $checked['secret_key']; } if (rocket_valid_key() && !empty($inputs['secret_key']) && !isset($inputs['ignore'])) { unset($inputs['ignore']); add_settings_error('general', 'settings_updated', __('Settings saved.', 'rocket'), 'updated'); } return $inputs; }