本文整理汇总了PHP中WP_CLI::success方法的典型用法代码示例。如果您正苦于以下问题:PHP WP_CLI::success方法的具体用法?PHP WP_CLI::success怎么用?PHP WP_CLI::success使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WP_CLI
的用法示例。
在下文中一共展示了WP_CLI::success方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: test
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!');
}
示例2: 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));
}
示例3: create_test_menus
/**
* create optional test nav menu
*
* At least two custom menus should be created in order to test a theme
* The standard Theme data file now ships with optimal menus built-in
* This method actually makes sense with custom WXR files only
*
* @since 0.2
*/
private function create_test_menus()
{
$pages = get_all_page_ids();
$items = array();
foreach ($pages as $page_ID) {
$info = get_page($page_ID);
$items[$info->post_title] = get_permalink($page_ID);
}
# pick three random entries
$random = array_rand($items, 3);
# build menus
$menus = array('Full Menu' => array('slug' => 'full-menu', 'menu_items' => $items), 'Short Menu' => array('slug' => 'short-menu', 'menu_items' => array($items[$random[0]], $items[$random[1]], $items[$random[2]])));
# register menus
foreach ($menus as $title => $data) {
register_nav_menu($data['slug'], $title);
if (false == is_nav_menu($title)) {
$menu_ID = wp_create_nav_menu($title);
foreach ($data['menu_items'] as $name => $url) {
$add_item = array('menu-item-type' => 'custom', 'menu-item-url' => $url, 'menu-item-title' => $name);
wp_update_nav_menu_item($menu_ID, 0, $add_item);
}
WP_CLI::success('Created menu ' . $title);
}
}
}
示例4: db
public function db($command = '', $args = '')
{
if (count($command) == 1 && reset($command) == 'help') {
return $this->db_help();
}
$defaults = array('host' => defined('IMPORT_DB_HOST') ? IMPORT_DB_HOST : DB_HOST, 'user' => defined('IMPORT_DB_USER') ? IMPORT_DB_USER : DB_USER, 'password' => defined('IMPORT_DB_PASSWORD') ? IMPORT_DB_PASSWORD : '', 'name' => defined('IMPORT_DB_NAME') ? IMPORT_DB_NAME : '', 'port' => '3306', 'ssh_host' => defined('IMPORT_DB_SSH_HOST') ? IMPORT_DB_SSH_HOST : '', 'ssh_user' => defined('IMPORT_DB_SSH_USER') ? IMPORT_DB_SSH_USER : '', 'table' => '');
$args = wp_parse_args($args, $defaults);
$start_time = time();
if ($args['ssh_host']) {
shell_exec(sprintf("ssh -f -L 3308:%s:%s %s@%s sleep 600 >> logfile", $args['host'], $args['port'], $args['ssh_user'], $args['ssh_host']));
$args['host'] = '127.0.0.1';
$args['port'] = '3308';
}
WP_CLI::line('Importing database from ' . $args['host'] . '...' . ($args['ssh_host'] ? ' via ssh tunnel: ' . $args['ssh_host'] : ''));
$password = $args['password'] ? '--password=' . escapeshellarg($args['password']) : '';
// TODO pipe through sed or interconnectIT's search replace script
if (defined('IMPORT_DB_REMOTE_ABSPATH')) {
$sed = " | sed s," . trailingslashit(IMPORT_DB_REMOTE_ABSPATH) . "," . ABSPATH . ",g";
} else {
$sed = '';
}
if ($args['site']) {
$args['table'] = "wp_{$args['site']}_commentmeta wp_{$args['site']}_comments wp_{$args['site']}_links wp_{$args['site']}_options wp_{$args['site']}_postmeta wp_{$args['site']}_posts wp_{$args['site']}_term_relationships wp_{$args['site']}_term_taxonomy wp_{$args['site']}_terms";
}
$exec = sprintf('mysqldump --verbose --host=%s --user=%s %s -P %s %s %s %s | mysql --host=%s --user=%s --password=%s %s', $args['host'], $args['user'], $password, $args['port'], $args['name'], $args['table'], $sed, DB_HOST, DB_USER, escapeshellarg(DB_PASSWORD), DB_NAME);
WP_CLI::line('Running: ' . $exec);
WP_CLI::launch($exec);
WP_CLI::success(sprintf('Finished. Took %d seconds', time() - $start_time));
wp_cache_flush();
}
示例5: __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.");
}
}
示例6: 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.');
}
示例7: phonehome
/**
* Calls back to ProudCity API to get initial config settings
*
* ## OPTIONS
*
* ## EXAMPLES
*
* wp proudpack phonehome
*
* @synopsis
*/
function phonehome($args, $assoc_args)
{
//list( $name ) = $args;
$request = wp_remote_get(PROUD_URL . '/sites/' . PROUD_ID . '/launched');
$response = json_decode(wp_remote_retrieve_body($request));
// Set options
update_option('blogname', $response->location->city);
update_option('lat', $response->location->lat);
update_option('lng', $response->location->lng);
update_option('city', $response->location->city);
update_option('state', $response->location->stateFull);
// Set theme settings
$mods = get_option('theme_mods_wp-proud-theme', array());
if (!empty($response->settings->colors->main)) {
$mods['color_main'] = $response->settings->colors->main;
}
if (!empty($response->settings->colors->secondary)) {
$mods['color_secondary'] = $response->settings->colors->secondary;
}
if (!empty($response->settings->colors->highlight)) {
$mods['color_highlight'] = $response->settings->colors->highlight;
}
update_option('theme_mods_wp-proud-theme', $mods);
// Print a success message
WP_CLI::success(print_r($response, 1));
WP_CLI::success(PROUD_URL . '/sites/' . PROUD_ID . '/launched' . $response->color->highlight . print_r(get_option('theme_mods_wp-proud-theme', array()), 1));
}
示例8: purge_all
/**
* Subcommand to purge all cache from Nginx
*
* Examples:
* wp nginx-helper purge-all
*
* @subcommand purge-all
*/
public function purge_all($args, $assoc_args)
{
global $rt_wp_nginx_purger;
$rt_wp_nginx_purger->true_purge_all();
$message = __('Purged Everything!');
WP_CLI::success($message);
}
示例9: sync
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');
}
}
}
示例10: clear_transients
/**
* Clear the product/shop transients cache.
*
* ## EXAMPLES
*
* wp wc tool clear_transients
*
* @since 2.5.0
*/
public function clear_transients($args, $assoc_args)
{
wc_delete_product_transients();
wc_delete_shop_order_transients();
WC_Cache_Helper::get_transient_version('shipping', true);
WP_CLI::success('Product transients and shop order transients were cleared.');
}
示例11: __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.");
}
}
}
示例12: setup
/**
* Setup Elasticsearch.
*
* ## OPTIONS
*
* [--host=<url>]
* : The name of the person to greet.
*
* [--port=<number>]
* : Accepted values: csv, json. Default: csv
*
* ## EXAMPLES
*
* wp elasticsearch setup --host=example.com --port=9200
*
* @subcommand setup
*/
function setup($args, $assoc_args)
{
$param = array();
$param['endpoint'] = preg_replace('/(^https:\\/\\/|^http:\\/\\/)/is', '', $assoc_args['host']);
$param['port'] = $assoc_args['port'];
$tries = 5;
$sleep = 3;
do {
$response = wp_remote_get(esc_url($assoc_args['host']) . ':' . $assoc_args['port']);
if (200 == wp_remote_retrieve_response_code($response)) {
// Looks good!
break;
} else {
WP_CLI::log("\nInvalid response from ES, sleeping {$sleep} seconds and trying again...\n");
sleep($sleep);
}
} while (--$tries);
if (200 != wp_remote_retrieve_response_code($response)) {
WP_CLI::error('Could not connect to Elasticsearch server.');
exit;
}
update_option('wpels_settings', $param);
try {
if (!\MegumiTeam\WooCommerceElasticsearch\Loader::get_instance()->data_sync()) {
WP_CLI::error('Elasticsearch built index failed.');
}
} catch (Exception $e) {
WP_CLI::error($e->getMessage());
exit;
}
WP_CLI::success("Elasticsearch built index completed.");
}
示例13: token
/**
* Set auth token.
*
* ## OPTIONS
*
* <token>
* : Enter your Piwik auth token here. It is an alphanumerical code like 0a1b2c34d56e78901fa2bc3d45678efa (see WP-Piwik faq for more info)
*
* ## EXAMPLES
*
* wp piwik token 0a1b2c34d56e78901fa2bc3d45678efa
*
* @synopsis <token>
*/
function token($args, $assoc_args)
{
list($token) = $args;
update_site_option('wp-piwik_global-piwik_token', $token);
// Print a success message
WP_CLI::success("Auth token set to: {$token}");
}
示例14: 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;
}
}
示例15: update_attachments
/**
* Run the converter now
*
* @since 1.0
*
* @param array $args can be extension
* @param array $vars
*/
function update_attachments($args = array(), $vars = array())
{
$images = Tiff_Converter::get_images();
$mime_type = 'image/jpg';
// Maybe $args[0] for changing it
if ($images) {
$succeed = $failed = 0;
foreach ($images as $image) {
$file = get_attached_file($image->ID);
$result = Tiff_Converter_Handle::convert_image($file, $mime_type);
if (!is_wp_error($result)) {
$update_args = array('ID' => $image->ID, 'post_mime_type' => $result['mime-type']);
$result2 = wp_update_post($update_args, true);
if ($result2 && !is_wp_error($result2)) {
unlink($file);
update_attached_file($image->ID, $result['path']);
wp_update_attachment_metadata($image->ID, wp_generate_attachment_metadata($image->ID, $result['path']));
$succeed++;
} else {
unlink($result['path']);
$failed++;
}
} else {
$failed++;
}
}
WP_CLI::success(sprintf('%d images are converted and %s failed', $succeed, $failed));
} else {
WP_CLI::success('No images to convert');
}
}