当前位置: 首页>>代码示例>>PHP>>正文


PHP WP_CLI::error方法代码示例

本文整理汇总了PHP中WP_CLI::error方法的典型用法代码示例。如果您正苦于以下问题:PHP WP_CLI::error方法的具体用法?PHP WP_CLI::error怎么用?PHP WP_CLI::error使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在WP_CLI的用法示例。


在下文中一共展示了WP_CLI::error方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: __invoke

 /**
  * Loop through all posts, setting the first attached image as the featured images
  * 
  * ## OPTIONS
  * 
  * ## EXAMPLES
  *
  * wp auto-thumbnail
  *
  */
 public function __invoke($args, $assoc_args)
 {
     set_time_limit(0);
     // Get all public post types
     $get_post_types = get_post_types(array('public' => true));
     // Post types array that will be used by default
     $post_types = array();
     foreach ($get_post_types as $post_type) {
         // Only add post types that support
         if (post_type_supports($post_type, 'thumbnail')) {
             $post_types[] = $post_type;
         }
     }
     // Default values for wp query
     $defaults = array('post_type' => $post_types, 'posts_per_page' => -1, 'post_status' => 'any');
     // Merge user args with defaults
     $assoc_args = wp_parse_args($assoc_args, $defaults);
     // The Query
     $the_query = new WP_Query($assoc_args);
     // Number of posts returned by query
     $found_posts = $the_query->found_posts;
     // Generate progess bar
     $progress = new \cli\progress\Bar('Progress', $found_posts);
     // Counter for number of post successfully processed
     $counter_success = 0;
     // Counter for number of post processed
     $counter_processed = 0;
     // The Loop
     while ($the_query->have_posts()) {
         $the_query->the_post();
         // Move the processbar on
         $progress->tick();
         $has_thumb = has_post_thumbnail(get_the_ID());
         if (!$has_thumb) {
             $attached_image = get_children("post_parent=" . get_the_ID() . "&post_type=attachment&post_mime_type=image&numberposts=1");
             if ($attached_image) {
                 foreach ($attached_image as $attachment_id => $attachment) {
                     set_post_thumbnail(get_the_ID(), $attachment_id);
                     $counter_success++;
                 }
             }
             $counter_processed++;
         }
     }
     $progress->finish();
     /* Restore original Post Data
      * NB: Because we are using new WP_Query we aren't stomping on the
      * original $wp_query and it does not need to be reset.
      */
     wp_reset_postdata();
     if ($found_posts == 0) {
         WP_CLI::error("No posts found");
     } elseif ($counter_processed == 0) {
         WP_CLI::error("No posts processed");
     } elseif ($counter_success == 0) {
         WP_CLI::success("Unable to processed any posts");
     } else {
         WP_CLI::success("Processing compelete. {$counter_success} of {$counter_processed} where processed successfully.");
     }
 }
开发者ID:ipcmedia,项目名称:auto-thumbnail-wp-cli,代码行数:70,代码来源:wp-cli.php

示例2: purge

 /**
  * Forces a full Varnish Purge of the entire site (provided
  * regex is supported).
  * 
  * ## EXAMPLES
  * 
  *		wp varnish purge
  *
  *		wp varnish purge http://example.com/wp-content/themes/twentyeleventy/style.css
  *
  *		wp vanrish purge "/wp-content/themes/twentysixty/style.css"
  *
  *		wp varnish purge http://example.com/wp-content/themes/ --wildcard
  *
  *		wp varnish purge "/wp-content/themes/" --wildcard
  *
  */
 function purge($args, $assoc_args)
 {
     $wp_version = get_bloginfo('version');
     $cli_version = WP_CLI_VERSION;
     // Set the URL/path
     list($url) = $args;
     // If wildcard is set, or the URL argument is empty
     // then treat this as a full purge
     if (isset($assoc_args['wildcard']) || empty($url)) {
         $pregex = '/?vhp-regex';
         $wild = ".*";
     } else {
         $pregex = $wild = '';
     }
     wp_create_nonce('vhp-flush-cli');
     // Make sure the URL is a URL:
     if (!empty($url)) {
         // If the URL isn't a URL, make it a URL
         if (empty(esc_url($url))) {
             $url = $this->varnish_purge->the_home_url() . $url;
         }
     } else {
         $url = $this->varnish_purge->the_home_url();
     }
     if (version_compare($wp_version, '4.6', '>=') && (version_compare($cli_version, '0.25.0', '<') || version_compare($cli_version, '0.25.0-alpha', 'eq'))) {
         WP_CLI::log(sprintf('This plugin does not work on WP 4.6 and up, unless WP-CLI is version 0.25.0 or greater. You\'re using WP-CLI %s and WordPress %s.', $cli_version, $wp_version));
         WP_CLI::log('To flush your cache, please run the following command:');
         WP_CLI::log(sprintf('$ curl -X PURGE "%s"', $url . $wild));
         WP_CLI::error('Varnish Cache must be purged manually.');
     }
     $this->varnish_purge->purgeUrl($url . $pregex);
     WP_CLI::success('The Varnish cache was purged.');
 }
开发者ID:uwmadisoncals,项目名称:Cluster-Plugins,代码行数:50,代码来源:wp-cli.php

示例3: _list

 /**
  * Lists one-time logins
  *
  * ## EXAMPLES
  *
  *     wp one-time-login list
  *
  * @subcommand list
  */
 function _list($args, $assoc_args)
 {
     // Get all one-time logins
     $otl_posts = get_posts(array('posts_per_page' => -1, 'post_type' => 'onetimelogin', 'order' => ASC));
     // Error if no logins found
     if (empty($otl_posts)) {
         WP_CLI::error(__('No one time logins found.', 'one-time-login'));
     }
     // Set table headers
     $headers = array(__('ID', 'one-time-login'), __('Password', 'one-time-login'), __('User ID', 'one-time-login'), __('Date Generated', 'one-time-login'), __('Status', 'one-time-login'), __('Date Used', 'one-time-login'));
     $data = array();
     // loop through logins and format
     foreach ($otl_posts as $otl) {
         $id = $otl->ID;
         $password = $otl->post_title;
         $user_id = get_post_meta($otl->ID, 'otl_user', true);
         $generated = $otl->post_date;
         $status = '0' === get_post_meta($otl->ID, 'otl_times_used', true) ? __('Available', 'one-time-login') : __('Expired', 'one-time-login');
         $used = get_post_meta($otl->ID, 'otl_datetime_used', true);
         $data[] = array($id, $password, $user_id, $generated, $status, $used);
     }
     // Output table
     $table = new \cli\Table();
     $table->setHeaders($headers);
     $table->setRows($data);
     $table->display();
 }
开发者ID:ryanduff,项目名称:one-time-login,代码行数:36,代码来源:one-time-login-command.php

示例4: __invoke

 /**
  * Import content from a WXR file.
  *
  * ## OPTIONS
  *
  * <file>...
  * : Path to one or more valid WXR files for importing.
  *
  * --authors=<authors>
  * : How the author mapping should be handled. Options are 'create', 'mapping.csv', or 'skip'. The first will create any non-existent users from the WXR file. The second will read author mapping associations from a CSV, or create a CSV for editing if the file path doesn't exist. The CSV requires two columns, and a header row like "old_user_login,new_user_login". The last option will skip any author mapping.
  *
  * [--skip=<data-type>]
  * : Skip importing specific data. Supported options are: 'attachment' and 'image_resize' (skip time-consuming thumbnail generation).
  */
 public function __invoke($args, $assoc_args)
 {
     $defaults = array('authors' => null, 'skip' => array());
     $assoc_args = wp_parse_args($assoc_args, $defaults);
     if (!is_array($assoc_args['skip'])) {
         $assoc_args['skip'] = explode(',', $assoc_args['skip']);
     }
     $importer = $this->is_importer_available();
     if (is_wp_error($importer)) {
         WP_CLI::error($importer);
     }
     $this->add_wxr_filters();
     WP_CLI::log('Starting the import process...');
     foreach ($args as $file) {
         if (!is_readable($file)) {
             WP_CLI::warning("Can't read {$file} file.");
         }
         $ret = $this->import_wxr($file, $assoc_args);
         if (is_wp_error($ret)) {
             WP_CLI::warning($ret);
         } else {
             WP_CLI::line();
             // WXR import ends with HTML, so make sure message is on next line
             WP_CLI::success("Finished importing from {$file} file.");
         }
     }
 }
开发者ID:nb,项目名称:wp-cli,代码行数:41,代码来源:import.php

示例5: exercise

 /**
  * "exercise" one or more URLs
  *
  * This is just a dispatcher and iterator, the real work is done in other methods.
  *
  * Args:
  * A URL or filename containing a list of URLs
  * 	...A list of URLs should be a text file with one URL per line
  * --count: the integer number of times to test the named URL(s)
  * --rand: if present will cause the exerciser to insert random get vars that (maybe) will prevent page caching
  * --redirection: the number of redirects to follow, 0 is default
  * --user_id: if present, will cause the request to be made with the specified user's authentication tokens
  *
  * Examples:
  * wp --url=wpsite.example.org go-newrelic exercise "http://wpsite.example.org/" --count=13 --rand
  * wp --url=wpsite.example.org go-newrelic exercise url-list.txt --count=13 --rand
  * while true; do wp --url=wpsite.example.org go-newrelic exercise url-list.txt --count=7 --rand; sleep 100; done
  *
  * TODO:
  * Metrics are collected for summation, but none is done.
  * Summation by URL and among a group of URLs would be great
  * Output in CSV form, maybe...
  */
 public function exercise($args, $assoc_args)
 {
     // don't this in New Relic
     if (function_exists('newrelic_ignore_transaction')) {
         newrelic_ignore_transaction();
     }
     //end if
     if (empty($args)) {
         WP_CLI::error('Please specify a URL (or file with URLs) to test.');
         return;
     }
     //end if
     if (!is_array($assoc_args)) {
         $assoc_args = array();
     }
     //end if
     if (file_exists($args[0]) && ($lines = file($args[0], FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES))) {
         shuffle($lines);
         foreach ($lines as $url) {
             $assoc_args['url'] = $this->find_url($url);
             self::test_url($assoc_args);
         }
     } else {
         $assoc_args['url'] = $this->find_url($args[0]);
         self::test_url($assoc_args);
     }
     //end else
 }
开发者ID:rolandinsh,项目名称:smc_newrelic,代码行数:51,代码来源:class-go-newrelic-wpcli.php

示例6: generate

 /**
  * Generate random users.
  *
  * ## OPTIONS
  *
  * <count>
  * : Number of users to generate
  *
  * ## EXAMPLES
  *
  *     wp usergen generate 10
  *
  * @access		public
  * @param		  array $args
  * @param		  array $assoc_args
  * @return		void
  */
 public function generate($args, $assoc_args)
 {
     list($count) = $args;
     // Verify the number is integer and greater than 0
     if (filter_var($count, FILTER_VALIDATE_INT) == false || $count < 0) {
         WP_CLI::error('You must specify the amount of users you wish to generate.');
         return;
     }
     $mock_data = $this->retrieve_mock_data();
     $total = count($mock_data);
     // Verify the requested amount is available within the mock data.
     if ($count > $total) {
         WP_CLI::error(sprintf('You must specify an amount less than %s or generate your custom json data.', $total));
         return;
     }
     $mock_data = array_slice($mock_data, 0, $count);
     // Get the selected amount from the array.
     $notify = \WP_CLI\Utils\make_progress_bar("Generating {$count} users(s)", $count);
     for ($i = 0; $i < count($mock_data); $i++) {
         $notify->tick();
         $this->register_user($mock_data[$i]);
     }
     $notify->finish();
     WP_CLI::success('Done.');
 }
开发者ID:alessandrotesoro,项目名称:wp-usergen-cli,代码行数:42,代码来源:cli.php

示例7: perform_option_action

 /**
  * Perform an option action on a remote site
  */
 private function perform_option_action($action, $args, $assoc_args)
 {
     $site_id = $assoc_args['site-id'];
     unset($assoc_args['site-id']);
     list($option_name) = $args;
     $this->set_account();
     $method = strtoupper($action);
     if ('update' == $action) {
         $method = 'POST';
         $api_args = array('option_value' => WP_CLI::read_value($args[1], $assoc_args));
     } else {
         $api_args = array();
     }
     $args = array('endpoint' => 'site/' . (int) $site_id . '/option/' . $option_name, 'method' => $method, 'body' => $api_args);
     $response = $this->api_request($args);
     if (is_wp_error($response)) {
         WP_CLI::error($response->get_error_message());
     }
     switch ($action) {
         case 'get':
             if (empty($response)) {
                 die(1);
             }
             WP_CLI::print_value($response, $assoc_args);
             break;
         case 'update':
             WP_CLI::success("Updated '{$option_name}' option.");
             break;
         case 'delete':
             WP_CLI::success("Deleted '{$option_name}' option.");
             break;
     }
 }
开发者ID:gokuale,项目名称:wp-remote-cli,代码行数:36,代码来源:class-wp-remote-option-command.php

示例8: __invoke

 /**
  * 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);
 }
开发者ID:ramiy,项目名称:GlotPress-WP,代码行数:40,代码来源:import-originals.php

示例9: delete

 /**
  * Delete orphaned tables
  *
  * @synopsis [--force]
  */
 function delete($args, $assoc_args)
 {
     if (!isset($assoc_args['force'])) {
         WP_CLI::error('Use the --force');
         return;
     }
     $orphanTables = $this->get_orphan_tables();
     if (count($orphanTables) == 0) {
         WP_CLI::success('No orphan tables were found');
         return;
     }
     global $wpdb;
     $i = 0;
     foreach ($orphanTables as $tableName) {
         $tableName = $tableName['Orphaned Table Name'];
         $result = $wpdb->query('DROP TABLE ' . $tableName);
         if ($result === false) {
             WP_CLI::error('Could not drop table ' . $tableName . ' - ' . $wpdb->last_error);
             continue;
         }
         WP_CLI::success('Dropped Table ' . $tableName);
         $i++;
     }
     WP_CLI::success('Dropped ' . $i . ' orphaned tables.');
 }
开发者ID:shawnhooper,项目名称:delete-orphaned-multisite-tables,代码行数:30,代码来源:wp-cli.php

示例10: log

 private function log($msg, $error = false)
 {
     if ($error) {
         WP_CLI::error($msg);
     }
     WP_CLI::warning($msg);
 }
开发者ID:JayWood,项目名称:eve-profit,代码行数:7,代码来源:import.php

示例11: get_queue

 /**
  * 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'));
 }
开发者ID:Automattic,项目名称:vip-mu-plugins-public,代码行数:38,代码来源:class-rest-api.php

示例12: import

 /**
  * Import content from a WXR file.
  *
  * ## OPTIONS
  *
  * <file>...
  * : Path to one or more valid WXR files for importing. Directories are also accepted.
  *
  * [--verbose[=<level>]]
  * : Should we print verbose statements?
  *   (No value for 'info'; or one of 'emergency', 'alert', 'critical',
  *   'error', 'warning', 'notice', 'info', 'debug')
  *
  * [--default-author=<id>]
  * : Default author ID to use if invalid user is found in the import data.
  */
 public function import($args, $assoc_args)
 {
     $logger = new WP_Importer_Logger_CLI();
     if (!empty($assoc_args['verbose'])) {
         if ($assoc_args['verbose'] === true) {
             $logger->min_level = 'info';
         } else {
             $valid = $logger->level_to_numeric($assoc_args['verbose']);
             if (!$valid) {
                 WP_CLI::error('Invalid verbosity level');
                 return;
             }
             $logger->min_level = $assoc_args['verbose'];
         }
     }
     $options = array('fetch_attachments' => true);
     if (isset($assoc_args['default-author'])) {
         $options['default_author'] = absint($assoc_args['default-author']);
         if (!get_user_by('ID', $options['default_author'])) {
             WP_CLI::error('Invalid default author ID specified.');
         }
     }
     $importer = new WXR_Importer($options);
     $importer->set_logger($logger);
     $importer->import(realpath($args[0]));
 }
开发者ID:humanmade,项目名称:WordPress-Importer,代码行数:42,代码来源:class-command.php

示例13: get_arg_or_error

 protected function get_arg_or_error($args, $index, $name)
 {
     if (!isset($args[$index])) {
         WP_CLI::error("{$name} required");
     }
     return $args[$index];
 }
开发者ID:roelven,项目名称:wp-cli,代码行数:7,代码来源:class-wp-cli-command-with-meta.php

示例14: destroy

 /**
  * Destroy a session for the given user.
  *
  * ## OPTIONS
  *
  * <user>
  * : User ID, user email, or user login.
  *
  * [<token>]
  * : The token of the session to destroy. Defaults to the most recently created session.
  *
  * [--all]
  * : Destroy all of the user's sessions.
  *
  * ## EXAMPLES
  *
  *     # Destroy the most recent session of the given user.
  *     $ wp user session destroy admin
  *     Success: Destroyed session. 3 sessions remaining.
  *
  *     # Destroy a specific session of the given user.
  *     $ wp user session destroy admin e073ad8540a9c2...
  *     Success: Destroyed session. 2 sessions remaining.
  *
  *     # Destroy all the sessions of the given user.
  *     $ wp user session destroy admin --all
  *     Success: Destroyed all sessions.
  *
  *     # Destroy all sessions for all users.
  *     $ wp user list --field=ID | xargs wp user session destroy --all
  *     Success: Destroyed all sessions.
  *     Success: Destroyed all sessions.
  */
 public function destroy($args, $assoc_args)
 {
     $user = $this->fetcher->get_check($args[0]);
     $token = \WP_CLI\Utils\get_flag_value($args, 1, null);
     $all = \WP_CLI\Utils\get_flag_value($assoc_args, 'all', false);
     $manager = WP_Session_Tokens::get_instance($user->ID);
     if ($token && $all) {
         WP_CLI::error('The --all flag cannot be specified along with a session token.');
     }
     if ($all) {
         $manager->destroy_all();
         WP_CLI::success('Destroyed all sessions.');
         return;
     }
     $sessions = $this->get_all_sessions($manager);
     if (!$token) {
         if (empty($sessions)) {
             WP_CLI::success('No sessions to destroy.');
         }
         $last = end($sessions);
         $token = $last['token'];
     }
     if (!isset($sessions[$token])) {
         WP_CLI::error('Session not found.');
     }
     $this->destroy_session($manager, $token);
     $remaining = count($manager->get_all());
     WP_CLI::success(sprintf('Destroyed session. %s remaining.', $remaining));
 }
开发者ID:wp-cli,项目名称:wp-cli,代码行数:62,代码来源:user-session.php

示例15: migrate

 /**
  * Migrate meta values to taxonomy terms. Delete meta after import
  *
  * ## OPTIONS
  *
  * <meta-key>
  * : Meta key to convert
  *
  * <taxonomy-slug>
  * : Taxonomy to move values into
  *
  * [--<field>=<value>]
  * : One or more args to pass to WP_Query.
  *
  * ## EXAMPLES
  *
  *     wp mtt migrate meta_key taxonomy_slug
  *     wp mtt migrate meta_key taxonomy_slug --posts_per_page=200 --paged=2
  *
  */
 function migrate($args, $assoc_args)
 {
     list($meta_key, $taxonomy) = $args;
     if (!($taxonomy_object = get_taxonomy($taxonomy))) {
         WP_CLI::error(sprintf("The taxonomy '%s' doesn't exist", $taxonomy));
     }
     $defaults = array('post_type' => $taxonomy_object->object_type, 'posts_per_page' => -1, 'post_status' => 'any');
     $query_args = array_merge($defaults, $assoc_args);
     $query = new WP_Query($query_args);
     // summary
     WP_CLI::log(sprintf("---\nPer page: %d \nPage: %d \nTotal pages: %d\n---", $query_args['posts_per_page'], isset($query_args['paged']) ? $query_args['paged'] : 1, $query->max_num_pages));
     while ($query->have_posts()) {
         $query->the_post();
         $id = get_the_id();
         // get meta
         $metas = get_post_meta($id, $meta_key);
         // create term
         if (!$metas) {
             WP_CLI::log(WP_CLI::colorize("%c[{$id}]%n No meta, skipped"));
         } else {
             if (!is_wp_error(wp_set_object_terms($id, $metas, $taxonomy, true))) {
                 WP_CLI::log(WP_CLI::colorize("%g[{$id}]%n Migrated: " . implode(', ', $metas)));
                 // clean meta
                 delete_post_meta($id, $meta_key);
             } else {
                 WP_CLI::log(WP_CLI::colorize("%r[{$id}]%n Error: Could not set terms for post"));
             }
         }
     }
 }
开发者ID:trepmal,项目名称:wp-cli-meta-to-term,代码行数:50,代码来源:meta-to-term-cli.php


注:本文中的WP_CLI::error方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。