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; } }
/** * 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.'); } } } } }
function __rocket_clear_cache_on_kksr_rate($post_id) { rocket_clean_post($post_id); }
function yasr_wp_rocket_support($post_id) { if (function_exists('rocket_clean_post')) { rocket_clean_post($post_id); } }