/** * Verify a domain in SES to send mail from. * * @subcommand verify-sending-domain * @synopsis [--domain=<domain>] */ public function verify_sending_domain($args, $args_assoc) { // Get the site domain and get rid of www. $domain = strtolower(parse_url(site_url(), PHP_URL_HOST)); if ('www.' === substr($domain, 0, 4)) { $domain = substr($domain, 4); } if ($args_assoc['domain']) { $domain = $args_assoc['domain']; } $dns_records = $this->get_sending_domain_dns_records($domain); WP_CLI::line('Submitted for verification. Make sure you have the following DNS records added to the domain:'); \WP_CLI\Utils\format_items('table', $dns_records, array('Domain', 'Type', 'Value')); }
/** * Evaluates publishing checklist for one or more posts. * * ## OPTIONS * * <id>... * : The ID of one or more posts * * [--fields=<fields>] * : Limit the output to specific row fields. Defaults to task_id, post_id, status, label, explanation. * * [--format=<format>] * : Accepted values: table, json, csv, summary. Default: table * * ## EXAMPLES * * wp checklist evaluate 1 * */ public function evaluate($args = array(), $assoc_args = array()) { $defaults = array('format' => 'table', 'fields' => array('task_id', 'post_id', 'post_title', 'status', 'label', 'explanation')); $values = wp_parse_args($assoc_args, $defaults); $cli_evaluation = array(); foreach ($args as $post_id) { $checklist_data = Publishing_Checklist()->evaluate_checklist($post_id); if (empty($checklist_data) && 'summary' === $values['format']) { WP_CLI::warning(sprintf(__('No checklist found for %d.', 'publishing-checklist'), $post_id)); break; } if ('summary' === $values['format']) { WP_CLI::success(sprintf(__('%d of %d tasks complete for %d', 'publishing-checklist'), count($checklist_data['completed']), count($checklist_data['tasks']), $post_id)); } else { foreach ($checklist_data['tasks'] as $id => $task) { $cli_evaluation[] = array('task_id' => $id, 'post_id' => $post_id, 'post_title' => htmlspecialchars_decode(html_entity_decode(get_the_title($post_id)), ENT_QUOTES), 'status' => in_array($id, $checklist_data['completed'], true) ? 'complete' : 'incomplete', 'label' => $task['label'], 'explanation' => $task['explanation']); } } } if ('summary' !== $values['format']) { \WP_CLI\Utils\format_items($values['format'], $cli_evaluation, $values['fields']); } }
/** * List callbacks registered to a given action or filter. * * ``` * wp hook wp_enqueue_scripts --fields=callback,location * +------------------------------------------------+---------------------------------------------+ * | callback | location | * +------------------------------------------------+---------------------------------------------+ * | wp_localize_jquery_ui_datepicker() | wp-includes/script-loader.php:928 | * | rest_register_scripts() | runcommand-theme/lib/rest-api/extras.php:22 | * | runcommand\Assets->action_wp_enqueue_scripts() | runcommand-theme/inc/class-assets.php:21 | * +------------------------------------------------+---------------------------------------------+ * ``` * ## OPTIONS * * <hook> * : The name of the action or filter. * * [--fields=<fields>] * : Limit the output to specific fields. Defaults to all fields. * * [--format=<format>] * : List callbacks as a table, JSON, CSV, or YAML. * --- * default: table * options: * - table * - json * - csv * - yaml * --- * * ## AVAILABLE FIELDS * * These fields are displayed by default for each callback: * * * callback - a human-friendly name for the callback * * location - where the callback is defined in the codebase * * priority - order in which the callback will be executed * * accepted_args - number of arguments to be passed to the callback */ public function __invoke($args, $assoc_args) { global $wp_filter; $assoc_args = array_merge(array('format' => 'table', 'fields' => 'callback,location,priority,accepted_args'), $assoc_args); $assoc_args['fields'] = explode(',', $assoc_args['fields']); $hook = $args[0]; if (!isset($wp_filter[$hook])) { WP_CLI::error("No callbacks specified for '{$hook}'."); } $callbacks_output = array(); if (is_a($wp_filter[$hook], 'WP_Hook')) { $filters = $wp_filter[$hook]->callbacks; } else { $filters = $wp_filter[$hook]; } ksort($filters); foreach ($filters as $priority => $callbacks) { foreach ($callbacks as $callback) { list($name, $location) = self::get_name_location_from_callback($callback['function']); $callbacks_output[] = array('callback' => $name, 'location' => $location, 'priority' => $priority, 'accepted_args' => $callback['accepted_args']); } } Utils\format_items($assoc_args['format'], $callbacks_output, $assoc_args['fields']); }
/** * Show logs on completed jobs * * @synopsis [--format=<format>] [--fields=<fields>] [--job=<job-id>] [--hook=<hook>] */ public function log($args, $assoc_args) { global $wpdb; $log_table = $wpdb->prefix . 'cavalcade_logs'; $job_table = $wpdb->prefix . 'cavalcade_jobs'; $assoc_args = wp_parse_args($assoc_args, array('format' => 'table', 'fields' => 'job,hook,timestamp,status', 'hook' => null, 'job' => null)); $where = array(); $data = array(); if ($assoc_args['job']) { $where[] = "job = %d"; $data[] = $assoc_args['job']; } if ($assoc_args['hook']) { $where[] = "hook = %s"; $data[] = $assoc_args['hook']; } $where = $where ? 'WHERE ' . implode(' AND ', $where) : ''; $query = "SELECT {$log_table}.*, {$job_table}.hook,{$job_table}.args FROM {$wpdb->prefix}cavalcade_logs INNER JOIN {$job_table} ON {$log_table}.job = {$job_table}.id {$where}"; if ($data) { $query = $wpdb->prepare($query, $data); } $logs = $wpdb->get_results($query); \WP_CLI\Utils\format_items($assoc_args['format'], $logs, explode(',', $assoc_args['fields'])); }
protected function update_many($args, $assoc_args) { call_user_func($this->upgrade_refresh); if (!empty($assoc_args['format']) && in_array($assoc_args['format'], array('json', 'csv'))) { $logger = new \WP_CLI\Loggers\Quiet(); \WP_CLI::set_logger($logger); } if (!\WP_CLI\Utils\get_flag_value($assoc_args, 'all') && empty($args)) { \WP_CLI::error("Please specify one or more {$this->item_type}s, or use --all."); } $items = $this->get_item_list(); if (!\WP_CLI\Utils\get_flag_value($assoc_args, 'all')) { $items = $this->filter_item_list($items, $args); } $items_to_update = wp_list_filter($items, array('update' => true)); if (\WP_CLI\Utils\get_flag_value($assoc_args, 'dry-run')) { if (empty($items_to_update)) { \WP_CLI::line("No {$this->item_type} updates available."); return; } if (!empty($assoc_args['format']) && in_array($assoc_args['format'], array('json', 'csv'))) { \WP_CLI\Utils\format_items($assoc_args['format'], $items_to_update, array('name', 'status', 'version', 'update_version')); } else { if (!empty($assoc_args['format']) && 'summary' === $assoc_args['format']) { \WP_CLI::line("Available {$this->item_type} updates:"); foreach ($items_to_update as $item_to_update => $info) { \WP_CLI::log("{$info['title']} update from version {$info['version']} to version {$info['update_version']}"); } } else { \WP_CLI::line("Available {$this->item_type} updates:"); \WP_CLI\Utils\format_items('table', $items_to_update, array('name', 'status', 'version', 'update_version')); } } return; } $result = array(); // Only attempt to update if there is something to update if (!empty($items_to_update)) { $cache_manager = \WP_CLI::get_http_cache_manager(); foreach ($items_to_update as $item) { $cache_manager->whitelist_package($item['update_package'], $this->item_type, $item['name'], $item['update_version']); } $upgrader = $this->get_upgrader($assoc_args); $result = $upgrader->bulk_upgrade(wp_list_pluck($items_to_update, 'update_id')); } // Let the user know the results. $num_to_update = count($items_to_update); $num_updated = count(array_filter($result)); if ($num_to_update > 0) { if (!empty($assoc_args['format']) && 'summary' === $assoc_args['format']) { foreach ($items_to_update as $item_to_update => $info) { $message = $result[$info['update_id']] !== null ? 'updated successfully' : 'did not update'; \WP_CLI::log("{$info['title']} {$message} from version {$info['version']} to version {$info['update_version']}"); } } else { $status = array(); foreach ($items_to_update as $item_to_update => $info) { $status[$item_to_update] = array('name' => $info['name'], 'old_version' => $info['version'], 'new_version' => $info['update_version'], 'status' => $result[$info['update_id']] !== null ? 'Updated' : 'Error'); } $format = 'table'; if (!empty($assoc_args['format']) && in_array($assoc_args['format'], array('json', 'csv'))) { $format = $assoc_args['format']; } \WP_CLI\Utils\format_items($format, $status, array('name', 'old_version', 'new_version', 'status')); } } Utils\report_batch_operation_results($this->item_type, 'update', $num_to_update, $num_updated, $num_to_update - $num_updated); }
/** * Display importing log. * * @param array $inserted_posts An array of the post ids * @return none */ private function get_imported_data($inserted_posts, $format = 'table') { $posts = History::post_ids_to_posts($inserted_posts); WP_CLI\Utils\format_items($format, $posts, array('ID', 'Title', 'Type', 'Status', 'Author', 'Date')); $fail = History::get_num_fail($inserted_posts); if ($fail) { WP_CLI::warning('Failed to import: ' . $fail); } }