/** * Remove cache files of all langs * * @since 2.0 * @deprecated 2.2 * @deprecated Use rocket_clean_domain() * */ function rocket_clean_domain_for_all_langs() { _deprecated_function(__FUNCTION__, '2.2', 'rocket_clean_domain()'); return rocket_clean_domain(); }
function __rocket_clear_cache_after_pressidium() { if (isset($_POST['purge-all']) && current_user_can('manage_options') && defined('WP_NINUKIS_WP_NAME') && check_admin_referer(WP_NINUKIS_WP_NAME . '-caching')) { // Clear all caching files rocket_clean_domain(); // Preload cache run_rocket_bot('cache-preload'); } }
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'); } }
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 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(); } }
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; } }
function siw_rebuild_cache() { //WP rocket cache legen en opnieuw aanmaken if (defined('WP_ROCKET_VERSION')) { rocket_clean_domain(); run_rocket_sitemap_preload(); } }
function do_rocket_purge_cron() { // Purge domain cache files rocket_clean_domain(); // Purge minify cache files rocket_clean_minify(); // Run WP Rocket Bot for preload cache files run_rocket_bot('cache-preload'); }
/** * Purge cache files * * ## OPTIONS * * [--post_id=<post_id>] * : List posts to purge cache files. * * [--permalink=<permalink>] * : List permalinks to purge cache files. Trumps --post_id. * * [--lang=<lang>] * : List langs to purge cache files. Trumps --post_id & --permalink. * * [--blog_id=<blog_id>] * : List blogs to purge cache files. Trumps --post_id & --permalink & lang. * * ## EXAMPLES * * wp rocket clean * wp rocket clean --post_id=2 * wp rocket clean --post_id=2,4,6,8 * wp rocket clean --permalink=http://example.com * wp rocket clean --permalink=http://example.com, http://example.com/category/(.*) * wp rocket clean --lang=fr * wp rocket clean --lang=fr,de,en,it * wp rocket clean --blog_id=2 * wp rocket clean --blog_id=2,4,6,8 * * @subcommand clean */ public function clean($args = array(), $assoc_args = array()) { if (!empty($assoc_args['blog_id'])) { if (!defined('MULTISITE') || !MULTISITE) { WP_CLI::error('This installation doesn\'t multisite support.'); } $blog_ids = explode(',', $assoc_args['blog_id']); $blog_ids = array_map('trim', $blog_ids); $total = 0; $notify = \WP_CLI\Utils\make_progress_bar('Delete cache files', count($blog_ids)); foreach ($blog_ids as $blog_id) { if ($bloginfo = get_blog_details((int) $blog_id, false)) { switch_to_blog($blog_id); rocket_clean_domain(); WP_CLI::line('Cache cleared for "' . esc_url('http://' . $bloginfo->domain . $bloginfo->path) . '".'); restore_current_blog(); $total++; } else { WP_CLI::line('This blog ID "' . $blog_id . '" doesn\'t exist.'); } $notify->tick(); } $notify->finish(); WP_CLI::success('Cache cleared for ' . $total . ' blog(s).'); } else { if (!empty($assoc_args['lang'])) { if (!rocket_has_translation_plugin_active()) { WP_CLI::error('No WPML or qTranslate in this website.'); } $langs = explode(',', $assoc_args['lang']); $langs = array_map('trim', $langs); $total = count($langs); $notify = \WP_CLI\Utils\make_progress_bar('Delete cache files', $total); foreach ($langs as $lang) { rocket_clean_domain_for_selected_lang($lang); $notify->tick(); } $notify->finish(); WP_CLI::success('Cache files cleared for ' . $total . ' lang(s).'); } else { if (!empty($assoc_args['permalink'])) { $permalinks = explode(',', $assoc_args['permalink']); $permalinks = array_map('trim', $permalinks); $total = count($permalinks); $notify = \WP_CLI\Utils\make_progress_bar('Delete cache files', $total); foreach ($permalinks as $permalink) { rocket_clean_files($permalink); WP_CLI::line('Cache cleared for "' . $permalink . '".'); $notify->tick(); } $notify->finish(); WP_CLI::success('Cache files cleared for ' . $total . ' permalink(s).'); } else { if (!empty($assoc_args['post_id'])) { $total = 0; $post_ids = explode(',', $assoc_args['post_id']); $post_ids = array_map('trim', $post_ids); $notify = \WP_CLI\Utils\make_progress_bar('Delete cache files', count($post_ids)); foreach ($post_ids as $post_id) { global $wpdb; $post_exists = $wpdb->get_row("SELECT ID FROM {$wpdb->posts} WHERE id = '" . (int) $post_id . "'"); if ($post_exists) { if (get_post_type($post_id) == 'attachment') { WP_CLI::line('This post ID "' . $post_id . '" is an attachment.'); } else { rocket_clean_post($post_id); WP_CLI::line('Cache cleared for post ID "' . $post_id . '".'); $total++; } } else { WP_CLI::line('This post ID "' . $post_id . '" doesn\'t exist.'); } $notify->tick(); } if ($total) { $notify->finish(); if ($total == 1) { WP_CLI::success('1 post is cleared.'); } else { WP_CLI::success($total . ' posts are cleared.'); } } else { WP_CLI::error('No cache files are cleared.'); } } else { WP_CLI::confirm('Delete all cache files ?'); if (rocket_has_translation_plugin_active()) { rocket_clean_domain_for_all_langs(); } else { rocket_clean_domain(); } WP_CLI::success('All cache files cleared.'); } } } } }