/**
 * deprecated
 * Shortcut for page post cache flush
 *
 * @param integer $post_id
 * @return boolean
 */
function w3tc_pgcache_flush_post($post_id)
{
    return w3tc_flush_post($post_id);
}
Ejemplo n.º 2
0
 /**
  * Clear something from the cache
  *
  * @param array   $args
  * @param array   $vars
  */
 function flush($args = array(), $vars = array())
 {
     $args = array_unique($args);
     do {
         $cache_type = array_shift($args);
         switch ($cache_type) {
             case 'db':
             case 'database':
                 try {
                     $w3_db = Dispatcher::component('CacheFlush');
                     $w3_db->dbcache_flush();
                 } catch (\Exception $e) {
                     \WP_CLI::error(__('Flushing the DB cache failed.', 'w3-total-cache'));
                 }
                 \WP_CLI::success(__('The DB cache is flushed successfully.', 'w3-total-cache'));
                 break;
             case 'minify':
                 try {
                     $w3_minify = Dispatcher::component('CacheFlush');
                     $w3_minify->minifycache_flush();
                 } catch (\Exception $e) {
                     \WP_CLI::error(__('Flushing the minify cache failed.', 'w3-total-cache'));
                 }
                 \WP_CLI::success(__('The minify cache is flushed successfully.', 'w3-total-cache'));
                 break;
             case 'object':
                 try {
                     $w3_objectcache = Dispatcher::component('CacheFlush');
                     $w3_objectcache->objectcache_flush();
                 } catch (\Exception $e) {
                     \WP_CLI::error(__('Flushing the object cache failed.', 'w3-total-cache'));
                 }
                 \WP_CLI::success(__('The object cache is flushed successfully.', 'w3-total-cache'));
                 break;
             case 'post':
             default:
                 if (isset($vars['post_id'])) {
                     if (is_numeric($vars['post_id'])) {
                         try {
                             $w3_cacheflush = Dispatcher::component('CacheFlush');
                             $w3_cacheflush->flush_post($vars['post_id']);
                         } catch (\Exception $e) {
                             \WP_CLI::error(__('Flushing the page from cache failed.', 'w3-total-cache'));
                         }
                         \WP_CLI::success(__('The page is flushed from cache successfully.', 'w3-total-cache'));
                     } else {
                         \WP_CLI::error(__('This is not a valid post id.', 'w3-total-cache'));
                     }
                     w3tc_flush_post($vars['post_id']);
                 } elseif (isset($vars['permalink'])) {
                     $id = url_to_postid($vars['permalink']);
                     if (is_numeric($id)) {
                         try {
                             $w3_cacheflush = Dispatcher::component('CacheFlush');
                             $w3_cacheflush->flush_post($id);
                         } catch (\Exception $e) {
                             \WP_CLI::error(__('Flushing the page from cache failed.', 'w3-total-cache'));
                         }
                         \WP_CLI::success(__('The page is flushed from cache successfully.', 'w3-total-cache'));
                     } else {
                         \WP_CLI::error(__('There is no post with this permalink.', 'w3-total-cache'));
                     }
                 } else {
                     if (isset($flushed_page_cache) && $flushed_page_cache) {
                         break;
                     }
                     $flushed_page_cache = true;
                     try {
                         $w3_cacheflush = Dispatcher::component('CacheFlush');
                         $w3_cacheflush->flush_posts();
                     } catch (\Exception $e) {
                         \WP_CLI::error(__('Flushing the page cache failed.', 'w3-total-cache'));
                     }
                     \WP_CLI::success(__('The page cache is flushed successfully.', 'w3-total-cache'));
                 }
         }
     } while (!empty($args));
 }