line() public static method

Message is written to STDOUT. WP_CLI::log() is typically recommended; WP_CLI::line() is included for historical compat.
public static line ( string $message = '' ) : null
$message string Message to display to the end user.
return null
 /**
  * Bulk import redirects from a CSV file matching the following structure:
  *
  * redirect_from_path,(redirect_to_post_id|redirect_to_path|redirect_to_url)
  *
  * @subcommand import-from-csv
  * @synopsis --csv=<path-to-csv>
  */
 function import_from_csv($args, $assoc_args)
 {
     define('WP_IMPORTING', true);
     if (empty($assoc_args['csv']) || !file_exists($assoc_args['csv'])) {
         WP_CLI::error("Invalid 'csv' file");
     }
     global $wpdb;
     if (($handle = fopen($assoc_args['csv'], "r")) !== FALSE) {
         while (($data = fgetcsv($handle, 2000, ",")) !== FALSE) {
             $row++;
             $redirect_from = $data[0];
             $redirect_to = $data[1];
             WP_CLI::line("Adding (CSV) redirect for {$redirect_from} to {$redirect_to}");
             WP_CLI::line("-- at {$row}");
             WPCOM_Legacy_Redirector::insert_legacy_redirect($redirect_from, $redirect_to);
             if (0 == $row % 100) {
                 if (function_exists('stop_the_insanity')) {
                     stop_the_insanity();
                 }
                 sleep(1);
             }
         }
         fclose($handle);
     }
 }
 /**
  * ## OPTIONS
  *
  * [--name=<name>]
  * : Consumer name
  *
  * [--description=<description>]
  * : Consumer description
  */
 public function add($_, $args)
 {
     $consumer = WP_REST_OAuth1_Client::create($args);
     WP_CLI::line(sprintf('ID: %d', $consumer->ID));
     WP_CLI::line(sprintf('Key: %s', $consumer->key));
     WP_CLI::line(sprintf('Secret: %s', $consumer->secret));
 }
 /**
  * Retrieve the current event queue
  *
  * @subcommand get-queue
  */
 public function get_queue($args, $assoc_args)
 {
     // Build and make request
     $queue_request = new \WP_REST_Request('POST', '/' . \Automattic\WP\Cron_Control\REST_API::API_NAMESPACE . '/' . \Automattic\WP\Cron_Control\REST_API::ENDPOINT_LIST);
     $queue_request->add_header('Content-Type', 'application/json');
     $queue_request->set_body(wp_json_encode(array('secret' => \WP_CRON_CONTROL_SECRET)));
     $queue_request = rest_do_request($queue_request);
     // Oh well
     if ($queue_request->is_error()) {
         \WP_CLI::error($queue_request->as_error()->get_error_message());
     }
     // Get the decoded JSON object returned by the API
     $queue_response = $queue_request->get_data();
     // No events, nothing more to do
     if (empty($queue_response['events'])) {
         \WP_CLI::warning(__('No events in the current queue', 'automattic-cron-control'));
         return;
     }
     // Prepare items for display
     $events_for_display = $this->format_events($queue_response['events']);
     $total_events_to_display = count($events_for_display);
     \WP_CLI::line(sprintf(_n('Displaying one event', 'Displaying %s events', $total_events_to_display, 'automattic-cron-control'), number_format_i18n($total_events_to_display)));
     // And reformat
     $format = 'table';
     if (isset($assoc_args['format'])) {
         if ('ids' === $assoc_args['format']) {
             \WP_CLI::error(__('Invalid output format requested', 'automattic-cron-control'));
         } else {
             $format = $assoc_args['format'];
         }
     }
     \WP_CLI\Utils\format_items($format, $events_for_display, array('timestamp', 'action', 'instance', 'scheduled_for', 'internal_event', 'schedule_name', 'event_args'));
 }
Beispiel #4
0
    private function general_help()
    {
        WP_CLI::line('Available commands:');
        foreach (WP_CLI::load_all_commands() as $command => $class) {
            if ('help' == $command) {
                continue;
            }
            $out = "    wp {$command}";
            $methods = WP_CLI_Command::get_subcommands($class);
            if (!empty($methods)) {
                $out .= ' [' . implode('|', $methods) . ']';
            }
            WP_CLI::line($out);
        }
        WP_CLI::line(<<<EOB

See 'wp help <command>' for more information on a specific command.

Global parameters:
    --user=<id|login>   set the current user
    --url=<url>         set the current URL
    --path=<path>       set the current path to the WP install
    --require=<path>    load a certain file before running the command
    --quiet             suppress informational messages
    --version           print wp-cli version
EOB
);
    }
Beispiel #5
0
Datei: cli.php Projekt: nb/wp-cli
 /**
  * Generate tab completion strings.
  */
 function completions()
 {
     foreach (WP_CLI::get_root_command()->get_subcommands() as $name => $command) {
         $subcommands = $command->get_subcommands();
         WP_CLI::line($name . ' ' . implode(' ', array_keys($subcommands)));
     }
 }
 public function sync($args, $assoc_args)
 {
     $websites = MainWP_DB::Instance()->query(MainWP_DB::Instance()->getSQLWebsitesForCurrentUser());
     WP_CLI::line('Syncing ' . MainWP_DB::num_rows($websites) . ' sites');
     $warnings = 0;
     $errors = 0;
     while ($websites && ($website = @MainWP_DB::fetch_object($websites))) {
         WP_CLI::line('  -> ' . $website->name . ' (' . $website->url . ')');
         try {
             if (MainWP_Sync::syncSite($website)) {
                 WP_CLI::success('  Sync succeeded');
             } else {
                 WP_CLI::warning('  Sync failed');
                 $warnings++;
             }
         } catch (Exception $e) {
             WP_CLI::error('  Sync failed');
             $errors++;
         }
     }
     @MainWP_DB::free_result($websites);
     if ($errors > 0) {
         WP_CLI::error('Sync completed with errors');
     } else {
         if ($warnings > 0) {
             WP_CLI::warning('Sync completed with warnings');
         } else {
             WP_CLI::success('Sync completed');
         }
     }
 }
Beispiel #7
0
 public function test($args = array(), $assoc_args = array())
 {
     WP_CLI::line('Processing ... ');
     WP_CLI::line(print_r($args, true));
     WP_CLI::line(print_r($assoc_args, true));
     WP_CLI::success('Success!');
 }
 /**
  * Reset the post_date field on your posts.
  * A sadly necessary step after you change your timezone in WordPress
  * 
  * @synopsis --post_type=<post-type>
  */
 public function __invoke($args, $assoc_args)
 {
     global $wpdb;
     $query_args = array('post_type' => $assoc_args['post_type'], 'posts_per_page' => -1, 'post_status' => 'publish');
     $query = new WP_Query($query_args);
     if (empty($query->posts)) {
         WP_CLI::error("No posts found");
     }
     WP_CLI::line(sprintf("Updating post_date on %d posts.", count($query->posts)));
     foreach ($query->posts as $key => $post) {
         if (empty($post->post_date_gmt) || "0000-00-00 00:00:00" == $post->post_date_gmt) {
             WP_CLI::line(sprintf("Error: Post %d is missing a publish date.", $post->ID));
             continue;
         }
         $original = $post->post_date;
         $new = get_date_from_gmt($post->post_date_gmt);
         if ($new == $original) {
             WP_CLI::line(sprintf("No Change: Post %d has the correct post_date of %s", $post->ID, $original));
             continue;
         }
         $wpdb->update($wpdb->posts, array('post_date' => $new), array('ID' => $post->ID));
         clean_post_cache($post->ID);
         WP_CLI::line(sprintf("Updated: Post %d changed from %s to %s", $post->ID, $original, $new));
         if ($key && $key % 10 == 0) {
             sleep(1);
         }
     }
     WP_CLI::success("Posts were updated with the correct post_date.");
 }
Beispiel #9
0
 /**
  * Create a user.
  *
  * @synopsis <user-login> <user-email> [--role=<role>] [--porcelain]
  */
 public function create($args, $assoc_args)
 {
     global $blog_id;
     list($user_login, $user_email) = $args;
     $defaults = array('role' => get_option('default_role'), 'user_pass' => wp_generate_password(), 'user_registered' => strftime("%F %T", time()), 'display_name' => false);
     extract(wp_parse_args($assoc_args, $defaults), EXTR_SKIP);
     if ('none' == $role) {
         $role = false;
     } elseif (is_null(get_role($role))) {
         WP_CLI::error("Invalid role.");
     }
     $user_id = wp_insert_user(array('user_email' => $user_email, 'user_login' => $user_login, 'user_pass' => $user_pass, 'user_registered' => $user_registered, 'display_name' => $display_name, 'role' => $role));
     if (is_wp_error($user_id)) {
         WP_CLI::error($user_id);
     } else {
         if (false === $role) {
             delete_user_option($user_id, 'capabilities');
             delete_user_option($user_id, 'user_level');
         }
     }
     if (isset($assoc_args['porcelain'])) {
         WP_CLI::line($user_id);
     } else {
         WP_CLI::success("Created user {$user_id}.");
     }
 }
 /**
  * Recheck all comments in the Pending queue.
  *
  * ## EXAMPLES
  *
  *     wp akismet recheck_queue
  *
  * @alias recheck-queue
  */
 public function recheck_queue()
 {
     $batch_size = 100;
     $start = 0;
     $total_counts = array();
     do {
         $result_counts = Akismet_Admin::recheck_queue_portion($start, $batch_size);
         if ($result_counts['processed'] > 0) {
             foreach ($result_counts as $key => $count) {
                 if (!isset($total_counts[$key])) {
                     $total_counts[$key] = $count;
                 } else {
                     $total_counts[$key] += $count;
                 }
             }
             $start += $batch_size;
             $start -= $result_counts['spam'];
             // These comments will have been removed from the queue.
         }
     } while ($result_counts['processed'] > 0);
     WP_CLI::line(sprintf(_n("Processed %d comment.", "Processed %d comments.", $total_counts['processed'], 'akismet'), number_format($total_counts['processed'])));
     WP_CLI::line(sprintf(_n("%d comment moved to Spam.", "%d comments moved to Spam.", $total_counts['spam'], 'akismet'), number_format($total_counts['spam'])));
     if ($total_counts['error']) {
         WP_CLI::line(sprintf(_n("%d comment could not be checked.", "%d comments could not be checked.", $total_counts['error'], 'akismet'), number_format($total_counts['error'])));
     }
 }
Beispiel #11
0
 /**
  * Import originals for a project from a file
  *
  * ## OPTIONS
  *
  * <project>
  * : Project name
  *
  * <file>
  * : File to import from
  *
  * [--format=<format>]
  * : Accepted values: po, mo, android, resx, strings. Default: po
  */
 public function __invoke($args, $assoc_args)
 {
     // Double-check for compatibility
     if ($args[0] === '-p' || $args[1] === '-f') {
         WP_CLI::error(__('-p and -f are no longer required and should be removed.', 'glotpress'));
     }
     $project = GP::$project->by_path($args[0]);
     if (!$project) {
         WP_CLI::error(__('Project not found!', 'glotpress'));
     }
     $format = isset($assoc_args['format']) ? $assoc_args['format'] : 'po';
     $format = gp_array_get(GP::$formats, $format, null);
     if (!$format) {
         WP_CLI::error(__('No such format.', 'glotpress'));
     }
     $translations = $format->read_originals_from_file($args[1], $project);
     if (!$translations) {
         WP_CLI::error(__("Couldn't load translations from file!", 'glotpress'));
     }
     list($originals_added, $originals_existing, $originals_fuzzied, $originals_obsoleted, $originals_error) = GP::$original->import_for_project($project, $translations);
     $notice = sprintf(__('%1$s new strings added, %2$s updated, %3$s fuzzied, and %4$s obsoleted.', 'glotpress'), $originals_added, $originals_existing, $originals_fuzzied, $originals_obsoleted);
     if ($originals_error) {
         $notice = ' ' . sprintf(_n('%s new string was not imported due to an error.', '%s new strings were not imported due to an error.', $originals_error, 'glotpress'), $originals_error);
     }
     WP_CLI::line($notice);
 }
 /**
  * get status of settings
  *
  * ## EXAMPLES
  *
  *     wp multi-device status
  *
  */
 public function status($args, $assoc_args)
 {
     $options = get_option($this->options);
     $rows = array();
     $slug_table = array('None' => '');
     $themes = wp_get_themes();
     foreach ($themes as $theme_slug => $header) {
         $slug_table[$header->get('Name')] = $theme_slug;
     }
     $rows[] = array('Device' => 'smartphone (Smart Phone)', 'Theme' => $options['theme_smartphone'], 'Slug' => $slug_table[$options['theme_smartphone']], 'UserAgent' => $options['userAgent_smart']);
     $rows[] = array('Device' => 'tablet (Tablet PC)', 'Theme' => $options['theme_tablet'], 'Slug' => $slug_table[$options['theme_tablet']], 'UserAgent' => $options['userAgent_tablet']);
     $rows[] = array('Device' => 'mobile (Mobile Phone)', 'Theme' => $options['theme_mobile'], 'Slug' => $slug_table[$options['theme_mobile']], 'UserAgent' => $options['userAgent_mobile']);
     $rows[] = array('Device' => 'game (Game Platforms)', 'Theme' => $options['theme_game'], 'Slug' => $slug_table[$options['theme_game']], 'UserAgent' => $options['userAgent_game']);
     foreach ($options as $custom_switcher_option => $custom_switcher_theme) {
         if (!preg_match('/^custom_switcher_theme_/', $custom_switcher_option)) {
             continue;
         }
         $custom_switcher_name = preg_replace('/^custom_switcher_theme_/', '', $custom_switcher_option);
         $rows[] = array('Device' => $custom_switcher_name, 'Theme' => $options['custom_switcher_theme_' . $custom_switcher_name], 'Slug' => $slug_table[$options['custom_switcher_theme_' . $custom_switcher_name]], 'UserAgent' => $options['custom_switcher_userAgent_' . $custom_switcher_name]);
     }
     $default_theme = wp_get_theme()->get('Name');
     $default_theme .= ' | ';
     $default_theme .= get_stylesheet();
     WP_CLI::line('Active Theme: ' . $default_theme);
     WP_CLI\Utils\format_items('table', $rows, array('Device', 'Theme', 'Slug', 'UserAgent'));
     $line = '';
     $line .= 'PC Switcher: ';
     $line .= $options['pc_switcher'] ? 'on' : 'off';
     $line .= "\n";
     $line .= 'default CSS: ';
     $line .= $options['default_css'] ? 'on' : 'off';
     WP_CLI::line($line);
 }
Beispiel #13
0
 /**
  * Show a list of users with super-admin capabilities.
  *
  * @subcommand list
  */
 public function _list($_, $assoc_args)
 {
     $super_admins = self::get_admins();
     foreach ($super_admins as $user_login) {
         WP_CLI::line($user_login);
     }
 }
 /**
  * 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.");
     }
 }
Beispiel #15
0
 /**
  * List capabilities for a given role.
  *
  * <role>
  * : Key for the role.
  *
  * ## EXAMPLES
  *
  *     # Display alphabetical list of bbPress moderator capabilities
  *     wp cap list 'bbp_moderator' | sort
  *
  * @subcommand list
  */
 public function list_($args)
 {
     $role_obj = self::get_role($args[0]);
     foreach (array_keys($role_obj->capabilities) as $cap) {
         WP_CLI::line($cap);
     }
 }
 /**
  * Initial player sync
  *
  * Retrieve all player and create/update when necessary.
  *
  * @since 1.0.0
  *
  * @param bool $is_cli whether the call is coming via WP_CLI
  *
  * @return bool True on success or false
  */
 public function handle_initial_sync($is_cli = false)
 {
     if (true === $is_cli) {
         WP_CLI::line(esc_html__('Starting Player Sync', 'brightcove'));
     }
     $players = $this->players_api->player_list();
     $players = $this->sort_api_response($players);
     if (!is_array($players)) {
         return false;
     }
     if (true === $is_cli) {
         WP_CLI::line(esc_html__(sprintf('There are %d players to sync for this account. Please be patient.', sizeof($players)), 'brightcove'));
     }
     $player_ids_to_keep = array();
     // for deleting outdated players
     /* process all players */
     foreach ($players as $player) {
         $this->add_or_update_wp_player($player);
         $player_ids_to_keep[] = BC_Utility::sanitize_subscription_id($player['id']);
     }
     BC_Utility::remove_deleted_players($player_ids_to_keep);
     BC_Utility::store_hash('players', $players, $this->cms_api->account_id);
     if (true === $is_cli) {
         WP_CLI::line(esc_html__('Player Sync Complete', 'brightcove'));
     }
     return true;
 }
Beispiel #17
0
 protected function _url($args, $callback)
 {
     foreach ($args as $obj_id) {
         $object = $this->fetcher->get_check($obj_id);
         \WP_CLI::line($callback($object->{$this->obj_id_key}));
     }
 }
Beispiel #18
0
    /**
     * Help function for this command
     */
    public static function help()
    {
        WP_CLI::line(<<<EOB
usage: wp core update
   or: wp core version [--extra]
EOB
);
    }
    static function help()
    {
        WP_CLI::line(<<<HELP
usage: wp liveblog readme_for_github
\tConverts the readme.txt to real markdown to be used as a README.md
HELP
);
    }
Beispiel #20
0
    /**
     * Help function for this command
     */
    public static function help()
    {
        WP_CLI::line(<<<EOB
usage: wp generate posts [--count=100] [--type=post] [--status=publish]
   or: wp generate users [--count=100] [--role=<role>]
EOB
);
    }
 /**
  * ## OPTIONS
  *
  * [--name=<name>]
  * : Consumer name
  *
  * [--description=<description>]
  * : Consumer description
  */
 public function add($_, $args)
 {
     $authenticator = new WP_JSON_Authentication_OAuth1();
     $consumer = $authenticator->add_consumer($args);
     WP_CLI::line(sprintf('ID: %d', $consumer->ID));
     WP_CLI::line(sprintf('Key: %s', $consumer->key));
     WP_CLI::line(sprintf('Secret: %s', $consumer->secret));
 }
Beispiel #22
0
    /**
     * Help function for this command
     */
    public static function help()
    {
        WP_CLI::line(<<<EOB
example: wp eval 'echo WP_CONTENT_DIR;'

Executes arbitrary PHP code after bootstrapping WordPress.
EOB
);
    }
Beispiel #23
0
 private function single_command_help($name, $command)
 {
     WP_CLI::out('    wp ' . $name);
     $methods = WP_CLI_Command::get_subcommands($command);
     if (!empty($methods)) {
         WP_CLI::out(' [' . implode('|', $methods) . ']');
     }
     WP_CLI::line(' ...');
 }
Beispiel #24
0
function call_ronn($markdown, $dest)
{
    if (!$markdown) {
        return;
    }
    $descriptorspec = array(0 => $markdown, 1 => array('file', $dest, 'w'), 2 => STDERR);
    $r = proc_close(proc_open("ronn --roff --manual='WP-CLI'", $descriptorspec, $pipes));
    \WP_CLI::line("generated " . basename($dest));
}
Beispiel #25
0
    /**
     * Help function for this command
     */
    public static function help()
    {
        WP_CLI::line(<<<EOB
usage: wp home

Opens the wp-cli homepage in your browser.
EOB
);
    }
    /**
     * Help function for this command
     *
     * @since 1.0
     */
    public static function help()
    {
        WP_CLI::line(<<<EOB
usage: wp tiff-converter [update_attachments]

\tupdate_attachments    run a backup now
EOB
);
    }
Beispiel #27
0
    /**
     * Help function for this command
     */
    public static function help()
    {
        WP_CLI::line(<<<EOB
example: wp eval-file some-file.php

Loads and executes a PHP file after bootstrapping WordPress.
EOB
);
    }
Beispiel #28
0
 /**
  * Imports the post in your GitHub repo
  * into your WordPress blog
  *
  * ## OPTIONS
  *
  * <user_id>
  * : The user ID you'd like to save the commit as
  *
  * ## EXAMPLES
  *
  *     wp wpghs import 1
  *
  * @synopsis <user_id>
  */
 public function import($args, $assoc_args)
 {
     list($user_id) = $args;
     if (!is_numeric($user_id)) {
         WP_CLI::error(__('Invalid user ID', 'wordpress-github-sync'));
     }
     update_option('_wpghs_export_user_id', (int) $user_id);
     WP_CLI::line(__('Starting import from GitHub.', 'wordpress-github-sync'));
     $this->controller->import_master();
 }
Beispiel #29
0
 /**
  * See whether the transients API is using an object cache or the options table.
  */
 public function type()
 {
     global $_wp_using_ext_object_cache, $wpdb;
     if ($_wp_using_ext_object_cache) {
         $message = 'Transients are saved to the object cache.';
     } else {
         $message = 'Transients are saved to the ' . $wpdb->prefix . 'options table.';
     }
     WP_CLI::line($message);
 }
    /**
     * Help function for this command
     */
    public static function help()
    {
        WP_CLI::line(<<<EOB
usage: wp google-sitemap [rebuild]

Available sub-commands:
\trebuild    rebuild Google sitemap
EOB
);
    }