/** * Flush All CloudFront Cache * * ## OPTIONS * <post_id> * post_id * * [--force] * Activate Force Clear Mode * * ## EXAMPLES * * wp c3 flush <post_id> : Flush <post_id>'s CloudFront Cache. * wp c3 flush all : Flush All CloudFront Cache. * wp c3 flush all --force : Flush All CloudFront Cache.( Force ) * * @param string $args: WP-CLI Command Name * @param string $assoc_args: WP-CLI Command Option * @since 2.3.0 */ function flush($args, $assoc_args) { WP_CLI::line('Start to Clear CloudFront Cache...'); if (empty($args)) { WP_CLI::error('Please input parameter:post_id(numeric) or all'); exit; } list($type) = $args; $c3 = CloudFront_Clear_Cache::get_instance(); if (array_search('force', $assoc_args)) { WP_CLI::line('Force Clear Mode'); add_filter('c3_invalidation_flag', '__return_false'); } if ('all' == $type) { WP_CLI::line('Clear Item = All'); $result = $c3->c3_invalidation(); } elseif (is_numeric($type)) { WP_CLI::line("Clear Item = (post_id={$type})"); $result = $c3->c3_invalidation($type); } else { WP_CLI::error('Please input parameter:post_id(numeric) or all'); exit; } if (!is_wp_error($result)) { WP_CLI::success("Create Invalidation Request. Please wait few minutes to finished clear CloudFront Cache."); } }
public static function get_instance() { if (!isset(self::$instance)) { $c = __CLASS__; self::$instance = new $c(); } return self::$instance; }
public function c3_admin_init() { $option_name = CloudFront_Clear_Cache::OPTION_NAME; $nonce_key = CloudFront_Clear_Cache::OPTION_NAME; if (isset($_POST[self::MENU_ID]) && $_POST[self::MENU_ID]) { if (check_admin_referer($nonce_key, self::MENU_ID)) { $e = new WP_Error(); update_option(CloudFront_Clear_Cache::OPTION_NAME, $_POST[$option_name]); } else { update_option(CloudFront_Clear_Cache::OPTION_NAME, ''); } wp_safe_redirect(menu_page_url(self::MENU_ID, false)); } if (isset($_POST[self::FLUSH_CACHE]) && $_POST[self::FLUSH_CACHE]) { $c3 = CloudFront_Clear_Cache::get_instance(); $c3->c3_invalidation(); } }
function __construct() { $this->C3 = CloudFront_Clear_Cache::get_instance(); $this->C3->add_hook(); }