本文整理汇总了PHP中WP_CLI::confirm方法的典型用法代码示例。如果您正苦于以下问题:PHP WP_CLI::confirm方法的具体用法?PHP WP_CLI::confirm怎么用?PHP WP_CLI::confirm使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WP_CLI
的用法示例。
在下文中一共展示了WP_CLI::confirm方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: purge
/**
* Deletes all users excepts administrators.
*
* ## EXAMPLES
*
* wp usergen purge
*
* @access public
* @param array $args
* @param array $assoc_args
* @return void
*/
public function purge($args, $assoc_args)
{
WP_CLI::line('');
WP_CLI::confirm('Are you sure you want to remove all users? This will NOT delete administrators.');
$roles_to_delete = $this->get_roles();
foreach ($roles_to_delete as $role => $name) {
$query_args = array('role' => $role, 'number' => 99999999);
$user_query = new WP_User_Query($query_args);
$results = $user_query->get_results();
$total = $user_query->get_total();
if (!empty($results)) {
WP_CLI::line('');
$notify = \WP_CLI\Utils\make_progress_bar("Deleting {$total} {$name}(s)", $total);
for ($i = 0; $i < count($results); $i++) {
$notify->tick();
wp_delete_user($results[$i]->data->ID, null);
}
$notify->finish();
}
}
WP_CLI::line('');
WP_CLI::success('Done.');
WP_CLI::line('');
}
示例2: regenerate
/**
* Regenerate thumbnails for one or more attachments.
*
* ## OPTIONS
*
* [<attachment-id>...]
* : One or more IDs of the attachments to regenerate.
*
* [--skip-delete]
* : Skip deletion of the original thumbnails. If your thumbnails are linked from sources outside your control, it's likely best to leave them around. Defaults to false.
*
* [--only-missing]
* : Only generate thumbnails for images missing image sizes.
*
* [--yes]
* : Answer yes to the confirmation message. Confirmation only shows when no IDs passed as arguments.
*
* ## EXAMPLES
*
* # Regenerate thumbnails for given attachment IDs.
* $ wp media regenerate 123 124 125
* Found 3 images to regenerate.
* 1/3 Regenerated thumbnails for "Vertical Image" (ID 123).
* 2/3 Regenerated thumbnails for "Horizontal Image" (ID 124).
* 3/3 Regenerated thumbnails for "Beautiful Picture" (ID 125).
* Success: Regenerated 3 of 3 images.
*
* # Regenerate all thumbnails, without confirmation.
* $ wp media regenerate --yes
* Found 3 images to regenerate.
* 1/3 Regenerated thumbnails for "Sydney Harbor Bridge" (ID 760).
* 2/3 Regenerated thumbnails for "Boardwalk" (ID 757).
* 3/3 Regenerated thumbnails for "Sunburst Over River" (ID 756).
* Success: Regenerated 3 of 3 images.
*
* # Re-generate all thumbnails that have IDs between 1000 and 2000.
* $ seq 1000 2000 | xargs wp media regenerate
* Found 4 images to regenerate.
* 1/4 Regenerated thumbnails for "Vertical Featured Image" (ID 1027).
* 2/4 Regenerated thumbnails for "Horizontal Featured Image" (ID 1022).
* 3/4 Regenerated thumbnails for "Unicorn Wallpaper" (ID 1045).
* 4/4 Regenerated thumbnails for "I Am Worth Loving Wallpaper" (ID 1023).
* Success: Regenerated 4 of 4 images.
*/
function regenerate($args, $assoc_args = array())
{
if (empty($args)) {
WP_CLI::confirm('Do you really want to regenerate all images?', $assoc_args);
}
$skip_delete = \WP_CLI\Utils\get_flag_value($assoc_args, 'skip-delete');
$only_missing = \WP_CLI\Utils\get_flag_value($assoc_args, 'only-missing');
if ($only_missing) {
$skip_delete = true;
}
$query_args = array('post_type' => 'attachment', 'post__in' => $args, 'post_mime_type' => 'image', 'post_status' => 'any', 'posts_per_page' => -1, 'fields' => 'ids');
$images = new WP_Query($query_args);
$count = $images->post_count;
if (!$count) {
WP_CLI::warning('No images found.');
return;
}
WP_CLI::log(sprintf('Found %1$d %2$s to regenerate.', $count, _n('image', 'images', $count)));
$errored = false;
$successes = $errors = 0;
foreach ($images->posts as $number => $id) {
if ($this->process_regeneration($id, $skip_delete, $only_missing, $number + 1 . '/' . $count)) {
$successes++;
} else {
$errors++;
}
}
Utils\report_batch_operation_results('image', 'regenerate', count($images->posts), $successes, $errors);
}
示例3: reset
/**
* Remove all tables from the database.
*
* Runs `DROP_DATABASE` and `CREATE_DATABASE` SQL statements using
* `DB_HOST`, `DB_NAME`, `DB_USER` and `DB_PASSWORD` database credentials
* specified in wp-config.php.
*
* ## OPTIONS
*
* [--yes]
* : Answer yes to the confirmation message.
*
* ## EXAMPLES
*
* $ wp db reset --yes
* Success: Database reset.
*/
public function reset($_, $assoc_args)
{
WP_CLI::confirm("Are you sure you want to reset the database?", $assoc_args);
self::run_query(sprintf('DROP DATABASE IF EXISTS `%s`', DB_NAME));
self::run_query(self::get_create_query());
WP_CLI::success("Database reset.");
}
示例4: regenerate
/**
* Regenerate thumbnail(s).
*
* ## OPTIONS
*
* [<attachment-id>...]
* : One or more IDs of the attachments to regenerate.
*
* [--skip-delete]
* : Skip deletion of the original thumbnails. If your thumbnails are linked from sources outside your control, it's likely best to leave them around. Defaults to false.
*
* [--only-missing]
* : Only generate thumbnails for images missing image sizes.
*
* [--yes]
* : Answer yes to the confirmation message.
*
* ## EXAMPLES
*
* # re-generate all thumbnails, without confirmation
* wp media regenerate --yes
*
* # re-generate all thumbnails that have IDs between 1000 and 2000
* seq 1000 2000 | xargs wp media regenerate
*/
function regenerate($args, $assoc_args = array())
{
if (empty($args)) {
WP_CLI::confirm('Do you really want to regenerate all images?', $assoc_args);
}
$skip_delete = \WP_CLI\Utils\get_flag_value($assoc_args, 'skip-delete');
$only_missing = \WP_CLI\Utils\get_flag_value($assoc_args, 'only-missing');
if ($only_missing) {
$skip_delete = true;
}
$query_args = array('post_type' => 'attachment', 'post__in' => $args, 'post_mime_type' => 'image', 'post_status' => 'any', 'posts_per_page' => -1, 'fields' => 'ids');
$images = new WP_Query($query_args);
$count = $images->post_count;
if (!$count) {
WP_CLI::warning('No images found.');
return;
}
WP_CLI::log(sprintf('Found %1$d %2$s to regenerate.', $count, _n('image', 'images', $count)));
$errored = false;
foreach ($images->posts as $id) {
if (!$this->_process_regeneration($id, $skip_delete, $only_missing)) {
$errored = true;
}
}
if ($errored) {
WP_CLI::log(_n('An error occurred with image regeneration.', 'An error occurred regenerating one or more images.', $count));
} else {
WP_CLI::success(sprintf('Finished regenerating %1$s.', _n('the image', 'all images', $count)));
}
}
示例5: reset
/**
* Remove all tables from the database.
*
* @synopsis [--yes]
*/
function reset($args, $assoc_args)
{
WP_CLI::confirm("Are you sure you want to reset the database?", $assoc_args);
WP_CLI::launch(self::create_cmd('mysql --host=%s --user=%s --password=%s --execute=%s', DB_HOST, DB_USER, DB_PASSWORD, 'DROP DATABASE IF EXISTS ' . DB_NAME));
WP_CLI::launch(self::create_cmd('mysql --host=%s --user=%s --password=%s --execute=%s', DB_HOST, DB_USER, DB_PASSWORD, 'CREATE DATABASE ' . DB_NAME));
WP_CLI::success("Database reset.");
}
示例6: __invoke
public function __invoke()
{
WP_CLI::confirm("This will erase all current permissions!\nAre you sure you want to delete them?");
if (!GP::$permission->delete_all()) {
WP_CLI::error(__('Error in deleting permissions.', 'glotpress'));
}
WP_CLI::success(__('Permissions were deleted. Now you can use `wp glotpress add-admin` to add a new administrator.', 'glotpress'));
}
示例7: regenerate
/**
* Regenerate thumbnail(s).
*
* ## OPTIONS
*
* [<attachment-id>...]
* : One or more IDs of the attachments to regenerate.
*
* [--yes]
* : Answer yes to the confirmation message.
*
* ## EXAMPLES
*
* # re-generate all thumbnails, without confirmation
* wp media regenerate --yes
*
* # re-generate all thumbnails that have IDs between 1000 and 2000
* seq 1000 2000 | xargs wp media regenerate
*/
function regenerate($args, $assoc_args = array())
{
if (empty($args)) {
WP_CLI::confirm('Do you realy want to regenerate all images?', $assoc_args);
}
$query_args = array('post_type' => 'attachment', 'post__in' => $args, 'post_mime_type' => 'image', 'post_status' => 'any', 'posts_per_page' => -1, 'fields' => 'ids');
$images = new WP_Query($query_args);
$count = $images->post_count;
if (!$count) {
WP_CLI::warning('No images found.');
return;
}
WP_CLI::log(sprintf('Found %1$d %2$s to regenerate.', $count, _n('image', 'images', $count)));
foreach ($images->posts as $id) {
$this->_process_regeneration($id);
}
WP_CLI::success(sprintf('Finished regenerating %1$s.', _n('the image', 'all images', $count)));
}
示例8: export
/**
* Export the State of WordPress to a state file.
*
* ## OPTIONS
*
* <state>
* : State to export
*
* <file>
* : Where the state should be exported to
*
* [--regions=<regions>]
* : Limit the export to one or more regions.
*
* [--force]
* : Forcefully overwrite an existing state file if one exists.
*
* @subcommand export
*/
public function export($args, $assoc_args)
{
list($state, $file) = $args;
if (file_exists($file) && !isset($assoc_args['force'])) {
WP_CLI::confirm("Are you sure you want to overwrite the existing state file?");
}
$state_obj = Dictator::get_state_obj($state);
if (!$state_obj) {
WP_CLI::error("Invalid state supplied.");
}
$limited_regions = !empty($assoc_args['regions']) ? explode(',', $assoc_args['regions']) : array();
// Build the state's data
$state_data = array('state' => $state);
foreach ($state_obj->get_regions() as $region_obj) {
$region_name = $state_obj->get_region_name($region_obj);
if ($limited_regions && !in_array($region_name, $limited_regions)) {
continue;
}
$state_data[$region_name] = $region_obj->get_current_data();
}
$this->write_state_file($state_data, $file);
WP_CLI::success("State written to file.");
}
示例9: get_reset_lock
/**
* Retrieve a lock's current value, or reset it
*/
private function get_reset_lock($args, $assoc_args, $lock_name, $lock_limit, $lock_description)
{
// Output information about the lock
\WP_CLI::line($lock_description . "\n");
\WP_CLI::line(sprintf(__('Maximum: %s', 'automattic-cron-control'), number_format_i18n($lock_limit)) . "\n");
// Reset requested
if (isset($assoc_args['reset'])) {
\WP_CLI::warning(__('Resetting lock...', 'automattic-cron-control') . "\n");
$lock = \Automattic\WP\Cron_Control\Lock::get_lock_value($lock_name);
$timestamp = \Automattic\WP\Cron_Control\Lock::get_lock_timestamp($lock_name);
\WP_CLI::line(sprintf(__('Previous value: %s', 'automattic-cron-control'), number_format_i18n($lock)));
\WP_CLI::line(sprintf(__('Previously modified: %s GMT', 'automattic-cron-control'), date(TIME_FORMAT, $timestamp)) . "\n");
\WP_CLI::confirm(sprintf(__('Are you sure you want to reset this lock?', 'automattic-cron-control')));
\WP_CLI::line('');
\Automattic\WP\Cron_Control\Lock::reset_lock($lock_name);
\WP_CLI::success(__('Lock reset', 'automattic-cron-control') . "\n");
\WP_CLI::line(__('New lock values:', 'automattic-cron-control'));
}
// Output lock state
$lock = \Automattic\WP\Cron_Control\Lock::get_lock_value($lock_name);
$timestamp = \Automattic\WP\Cron_Control\Lock::get_lock_timestamp($lock_name);
\WP_CLI::line(sprintf(__('Current value: %s', 'automattic-cron-control'), number_format_i18n($lock)));
\WP_CLI::line(sprintf(__('Last modified: %s GMT', 'automattic-cron-control'), date(TIME_FORMAT, $timestamp)));
}
示例10: update
/**
* Update WP-CLI to the latest release.
*
* Default behavior is to check the releases API for the newest stable
* version, and prompt if one is available.
*
* Use `--stable` to install or reinstall the latest stable version.
*
* Use `--nightly` to install the latest built version of the master branch.
* While not recommended for production, nightly contains the latest and
* greatest, and should be stable enough for development and staging
* environments.
*
* Only works for the Phar installation mechanism.
*
* ## OPTIONS
*
* [--patch]
* : Only perform patch updates.
*
* [--minor]
* : Only perform minor updates.
*
* [--major]
* : Only perform major updates.
*
* [--stable]
* : Update to the latest stable release. Skips update check.
*
* [--nightly]
* : Update to the latest built version of the master branch. Potentially unstable.
*
* [--yes]
* : Do not prompt for confirmation.
*
* ## EXAMPLES
*
* # Update CLI.
* $ wp cli update
* You have version 0.24.0. Would you like to update to 0.24.1? [y/n] y
* Downloading from https://github.com/wp-cli/wp-cli/releases/download/v0.24.1/wp-cli-0.24.1.phar...
* New version works. Proceeding to replace.
* Success: Updated WP-CLI to 0.24.1.
*/
public function update($_, $assoc_args)
{
if (!Utils\inside_phar()) {
WP_CLI::error("You can only self-update Phar files.");
}
$old_phar = realpath($_SERVER['argv'][0]);
if (!is_writable($old_phar)) {
WP_CLI::error(sprintf("%s is not writable by current user.", $old_phar));
} else {
if (!is_writeable(dirname($old_phar))) {
WP_CLI::error(sprintf("%s is not writable by current user.", dirname($old_phar)));
}
}
if (Utils\get_flag_value($assoc_args, 'nightly')) {
WP_CLI::confirm(sprintf('You have version %s. Would you like to update to the latest nightly?', WP_CLI_VERSION), $assoc_args);
$download_url = 'https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli-nightly.phar';
$md5_url = 'https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli-nightly.phar.md5';
} else {
if (Utils\get_flag_value($assoc_args, 'stable')) {
WP_CLI::confirm(sprintf('You have version %s. Would you like to update to the latest stable release?', WP_CLI_VERSION), $assoc_args);
$download_url = 'https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar';
$md5_url = 'https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar.md5';
} else {
$updates = $this->get_updates($assoc_args);
if (empty($updates)) {
$update_type = $this->get_update_type_str($assoc_args);
WP_CLI::success("WP-CLI is at the latest{$update_type}version.");
return;
}
$newest = $updates[0];
WP_CLI::confirm(sprintf('You have version %s. Would you like to update to %s?', WP_CLI_VERSION, $newest['version']), $assoc_args);
$download_url = $newest['package_url'];
$md5_url = str_replace('.phar', '.phar.md5', $download_url);
}
}
WP_CLI::log(sprintf('Downloading from %s...', $download_url));
$temp = \WP_CLI\Utils\get_temp_dir() . uniqid('wp_') . '.phar';
$headers = array();
$options = array('timeout' => 600, 'filename' => $temp);
Utils\http_request('GET', $download_url, null, $headers, $options);
$md5_response = Utils\http_request('GET', $md5_url);
if (20 != substr($md5_response->status_code, 0, 2)) {
WP_CLI::error("Couldn't access md5 hash for release (HTTP code {$md5_response->status_code}).");
}
$md5_file = md5_file($temp);
$release_hash = trim($md5_response->body);
if ($md5_file === $release_hash) {
WP_CLI::log('md5 hash verified: ' . $release_hash);
} else {
WP_CLI::error("md5 hash for download ({$md5_file}) is different than the release hash ({$release_hash}).");
}
$allow_root = WP_CLI::get_runner()->config['allow-root'] ? '--allow-root' : '';
$php_binary = WP_CLI::get_php_binary();
$process = WP_CLI\Process::create("{$php_binary} {$temp} --info {$allow_root}");
$result = $process->run();
if (0 !== $result->return_code || false === stripos($result->stdout, 'WP-CLI version:')) {
//.........这里部分代码省略.........
示例11: inspect
/**
* Performs a full inspection and outputs the inspection log.
*
* ## OPTIONS
*
* [<routine>]
* : The inspection routine to perform.
*
* ## EXAMPLES
*
* wp angry-inspector inspect file-permissions
*
* @synopsis [--force] [<routine>] [<other-routine>]
*/
function inspect($routines = array(), $assoc_args)
{
$all_routines = ACI_Routine_Handler::get_inspection_routines();
$all_routine_slugs = array();
$routine_repair_methods = array();
$force_inspect = true;
foreach ($all_routines as $key => $routine) {
$all_routine_slugs[$key] = str_replace('_', '-', str_replace('aci_routine_', '', str_replace('aci_routine_check_', '', strtolower($routine))));
}
if (empty($routines) || !is_array($routines) || 0 == count($routines)) {
$force_inspect = false;
$routines = $all_routine_slugs;
}
if (array_key_exists('force', $assoc_args) && !empty($assoc_args['force'])) {
$force_inspect = true;
}
foreach ($routines as $routine) {
if (in_array($routine, $all_routine_slugs)) {
$total_log_count = AC_Inspector::$log_count;
$routine_key = array_search($routine, $all_routine_slugs);
$routine_options = ACI_Routine_Handler::get_options($all_routines[$routine_key]);
$inspection_method = ACI_Routine_Handler::get_inspection_method($all_routines[$routine_key], $routine_options);
$enabled_routine = false;
if ($force_inspect) {
$enabled_routine = true;
ACI_Routine_Handler::force_enable($all_routines[$routine_key]);
} else {
if (!empty($routine_options['site_specific_settings']) && is_multisite() && is_plugin_active_for_network(ACI_PLUGIN_BASENAME)) {
$current_site_id = get_current_blog_id();
if ($routine_options[$current_site_id]['log_level'] != 'ignore') {
$enabled_routine = true;
}
} else {
if ($routine_options['log_level'] != 'ignore') {
$enabled_routine = true;
}
}
}
if (!$enabled_routine) {
echo "Skipping disabled routine {$routine}...\n\n";
continue;
}
if (empty($inspection_method)) {
WP_CLI::error("Failed to determine the inspection method for {$routine}.");
}
if (is_array($inspection_method)) {
if (class_exists($inspection_method[0]) && method_exists($inspection_method[0], $inspection_method[1])) {
echo "Calling inspection method {$routine}...\n";
call_user_func($inspection_method);
} else {
WP_CLI::error("Failed to load the inspection method for {$routine}.");
}
} else {
if (function_exists($inspection_method)) {
echo "Calling inspection method {$routine}...\n";
call_user_func($inspection_method);
} else {
WP_CLI::error("Failed to load the inspection method for {$routine}.");
break;
}
}
if (AC_Inspector::$error_count) {
AC_Inspector::$error_count = 0;
continue;
}
$routine_log_count = AC_Inspector::$log_count - $total_log_count;
WP_CLI::success("Inspected {$routine} with {$routine_log_count} remark(s).\n");
if ($routine_log_count > 0) {
$repair_method = ACI_Routine_Handler::get_repair_method($all_routines[$routine_key], $routine_options);
if (!empty($repair_method)) {
$routine_repair_methods[$routine] = $repair_method;
}
}
} else {
WP_CLI::error("Unrecognized inspection routine '{$routine}'.");
}
}
if (count($routine_repair_methods) > 0) {
WP_CLI::confirm("One or more of your inspection routines has a repair method that may or may not fix the problem(s) for you.\n" . "Have you made a backup of your website's entire source code, uploaded files and database and want me to\n" . "try and repair with the risk of me messing everything up?");
foreach ($routine_repair_methods as $routine => $repair_method) {
$total_log_count = AC_Inspector::$log_count;
$total_error_count = AC_Inspector::$error_count;
$total_success_count = AC_Inspector::$success_count;
call_user_func($repair_method);
$routine_log_count = AC_Inspector::$log_count - $total_log_count;
$routine_error_count = AC_Inspector::$error_count - $total_error_count;
//.........这里部分代码省略.........
示例12: migrate_term_meta
/**
* Migrate all FM term meta to core term meta
*
* ## OPTIONS
*
* [--destructive]
* : If present, FM term meta will be deleted after it is migrated, and
* each FM term meta post will be deleted once its meta is migrated.
*
* [--dry-run]
* : If present, no updates will be made.
*
* [--verbose]
* : If present, script will output additional details.
*
* ## EXAMPLES
*
* wp fm-term-meta migrate_term_meta
*
* @synopsis [--destructive] [--dry-run] [--verbose]
*/
public function migrate_term_meta($args, $assoc_args)
{
$dry_run = !empty($assoc_args['dry-run']);
$verbose = !empty($assoc_args['verbose']);
$destructive = !empty($assoc_args['destructive']);
WP_CLI::line("Starting term meta migration");
if ($dry_run) {
WP_CLI::warning('THIS IS A DRY RUN');
} elseif ($destructive) {
WP_CLI::warning('With the --destructive flag set, this will delete all FM term meta after it is successfully migrated. There is no undo for this.');
WP_CLI::confirm('Do you want to continue?');
}
if (get_option('db_version') < 34370) {
WP_CLI::error('This WordPress installation is not ready for term meta! You must be running WordPress 4.4 and the database update must be complete.');
}
WP_CLI::warning("Muting user-generated PHP notices for this command in order to hide deprecation notices");
error_reporting(error_reporting() & ~E_USER_NOTICE);
$terms = $this->get_terms_with_fm_term_meta();
foreach ($terms as $term) {
if ($verbose) {
WP_CLI::line("Processing {$term->taxonomy} `{$term->name}' ({$term->slug}, {$term->term_id})");
}
$term_meta = fm_get_term_meta($term->term_id, $term->taxonomy);
if ($verbose) {
WP_CLI::line(sprintf("\tFound %d meta entries", count($term_meta)));
}
foreach ($term_meta as $meta_key => $meta_values) {
if ($verbose) {
WP_CLI::line(sprintf("\tMigrating %d meta values for meta key %s", count($meta_values), $meta_key));
}
$result = true;
foreach ($meta_values as $meta_value) {
if ($dry_run || $verbose) {
WP_CLI::line(sprintf("\tadd_term_meta( %d, '%s', '%s' );", $term->term_id, $meta_key, strlen($meta_value) < 50 ? $meta_value : '[too long to output]'));
}
if (!$dry_run) {
$this_result = add_term_meta($term->term_id, $meta_key, $meta_value);
if (!is_int($this_result)) {
$result = false;
WP_CLI::warning(sprintf("\tError running add_term_meta( %d, '%s', '%s' );", $term->term_id, $meta_key, $meta_value));
if (is_wp_error($this_result)) {
WP_CLI::warning(sprintf("\t\t%s: %s", $this_result->get_error_code(), $this_result->get_error_message()));
} else {
WP_CLI::warning(sprintf("\t\t%s", var_export($this_result, 1)));
}
}
}
}
if ($destructive) {
if (!$result) {
WP_CLI::warning("\tSkipping FM term meta deletion for {$meta_key} because an error was encountered while adding data");
} else {
if ($dry_run || $verbose) {
WP_CLI::line("\tDeleting this term's FM term meta for {$meta_key}");
}
if (!$dry_run) {
fm_delete_term_meta($term->term_id, $term->taxonomy, $meta_key);
}
}
}
}
if (empty($term_meta)) {
WP_CLI::line("\tNo FM term meta remaining for this term.");
if ($destructive && get_post($term->post_id)) {
if ($verbose || $dry_run) {
WP_CLI::line("\tDeleting post ID {$term->post_id}");
}
if (!$dry_run) {
wp_delete_post($term->post_id, true);
}
}
}
}
// Print a success message
WP_CLI::success("Process complete!");
if (!$dry_run) {
WP_CLI::line("\n");
WP_CLI::line("You're almost done! To use the new term meta, you need to update Fieldmanager, then update your code accordingly:");
WP_CLI::line("- Replace any call to Fieldmanager_Field::add_term_form() with Fieldmanager_Field::add_term_meta_box().");
//.........这里部分代码省略.........
开发者ID:martarf,项目名称:fieldmanager-term-meta-migration,代码行数:101,代码来源:class-fieldmanager-term-meta-migration-cli.php
示例13: update
/**
* Fetch most recent update matching the requirements. Returns the available versions if there are updates, or empty if no update available.
*
* ## OPTIONS
*
* [--patch]
* : Only perform patch updates
*
* [--minor]
* : Only perform minor updates
*
* [--major]
* : Only perform major updates
*
* [--nightly]
* : Update to the latest built version of the master branch. Potentially unstable.
*
* [--yes]
* : Do not prompt for confirmation
*/
public function update($_, $assoc_args)
{
if (!Utils\inside_phar()) {
WP_CLI::error("You can only self-update Phar files.");
}
$old_phar = realpath($_SERVER['argv'][0]);
if (!is_writable($old_phar)) {
WP_CLI::error(sprintf("%s is not writable by current user", $old_phar));
} else {
if (!is_writeable(dirname($old_phar))) {
WP_CLI::error(sprintf("%s is not writable by current user", dirname($old_phar)));
}
}
if (isset($assoc_args['nightly'])) {
WP_CLI::confirm(sprintf('You have version %s. Would you like to update to the latest nightly?', WP_CLI_VERSION), $assoc_args);
$download_url = 'https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli-nightly.phar';
} else {
$updates = $this->get_updates($assoc_args);
if (empty($updates)) {
$update_type = $this->get_update_type_str($assoc_args);
WP_CLI::success("WP-CLI is at the latest{$update_type}version.");
exit(0);
}
$newest = $updates[0];
WP_CLI::confirm(sprintf('You have version %s. Would you like to update to %s?', WP_CLI_VERSION, $newest['version']), $assoc_args);
$download_url = $newest['package_url'];
}
WP_CLI::log(sprintf('Downloading from %s...', $download_url));
$temp = \WP_CLI\Utils\get_temp_dir() . uniqid('wp_') . '.phar';
$headers = array();
$options = array('timeout' => 600, 'filename' => $temp);
Utils\http_request('GET', $download_url, null, $headers, $options);
$allow_root = WP_CLI::get_runner()->config['allow-root'] ? '--allow-root' : '';
$php_binary = WP_CLI::get_php_binary();
$process = WP_CLI\Process::create("{$php_binary} {$temp} --version {$allow_root}");
$result = $process->run();
if (0 !== $result->return_code) {
$multi_line = explode(PHP_EOL, $result->stderr);
WP_CLI::error_multi_line($multi_line);
WP_CLI::error('The downloaded PHAR is broken, try running wp cli update again.');
}
WP_CLI::log('New version works. Proceeding to replace.');
$mode = fileperms($old_phar) & 511;
if (false === @chmod($temp, $mode)) {
WP_CLI::error(sprintf("Cannot chmod %s", $temp));
}
class_exists('\\cli\\Colors');
// this autoloads \cli\Colors - after we move the file we no longer have access to this class
if (false === @rename($temp, $old_phar)) {
WP_CLI::error(sprintf("Cannot move %s to %s", $temp, $old_phar));
}
if (isset($assoc_args['nightly'])) {
$updated_version = 'the latest nightly release';
} else {
$updated_version = $newest['version'];
}
WP_CLI::success(sprintf('Updated WP-CLI to %s', $updated_version));
}
示例14: purge
/**
* Remove corrupt Cron Control data resulting from initial plugin deployment
*
* @subcommand remove-all-plugin-data
* @synopsis [--batch-size=<batch-size>] [--dry-run=<dry-run>]
*/
public function purge($args, $assoc_args)
{
global $wpdb;
// Are we actually destroying any data?
$dry_run = true;
if (isset($assoc_args['dry-run']) && 'false' === $assoc_args['dry-run']) {
$dry_run = false;
}
// Provide some idea of what's going on
\WP_CLI::line(__('CRON CONTROL', 'automattic-cron-control') . "\n");
$count = $wpdb->get_var($wpdb->prepare("SELECT COUNT(ID) FROM {$wpdb->posts} WHERE post_type = %s;", 'a8c_cron_ctrl_event'));
if (is_numeric($count)) {
$count = (int) $count;
\WP_CLI::line(sprintf(__('Found %s total items', 'automattic-cron-control'), number_format_i18n($count)) . "\n\n");
\WP_CLI::confirm(__('Proceed?', 'automattic-cron-control'));
} else {
\WP_CLI::error(__('Something went wrong...aborting!', 'automattic-cron-control'));
}
// Should we really destroy all this data?
if (!$dry_run) {
\WP_CLI::line(__('This process will remove all CPT data for the Cron Control plugin', 'automattic-cron-control'));
\WP_CLI::confirm(__('Proceed?', 'automattic-cron-control'));
\WP_CLI::line("\n" . __('Starting...', 'automattic-cron-control') . "\n");
}
// Determine how many batches this will take
if (isset($assoc_args['batch-size'])) {
$page_size = max(1, min(absint($assoc_args['batch-size']), 500));
} else {
$page_size = 250;
}
\WP_CLI::line(sprintf(__('Processing in batches of %s', 'automattic-cron-control'), number_format_i18n($page_size)) . "\n\n");
$pages = 1;
$page = 1;
if ($count > $page_size) {
$pages = ceil($count / $page_size);
}
// Let's get on with it
do {
\WP_CLI::line("\n\n" . sprintf(__('Processing page %1$s of %2$s', 'automattic-cron-control'), number_format_i18n($page), number_format_i18n($pages)) . "\n");
$items = $wpdb->get_results($wpdb->prepare("SELECT ID, post_title FROM {$wpdb->posts} WHERE post_type = %s LIMIT %d,%d", 'a8c_cron_ctrl_event', absint(($page - 1) * $page_size), $page_size));
// Nothing more to do
if (!is_array($items) || empty($items)) {
\WP_CLI::line(__('No more items found!', 'automattic-cron-control'));
break;
}
\WP_CLI::line(sprintf(__('Found %s items in this batch'), number_format_i18n(count($items))));
foreach ($items as $item) {
\WP_CLI::line("{$item->ID}, `{$item->post_title}`");
if (!$dry_run) {
wp_delete_post($item->ID, true);
}
}
// Some cleanup
unset($items);
stop_the_insanity();
// Prepare for the next batch
$page++;
if ($page > $pages) {
break;
}
// Don't rush into the next batch, unless we haven't done anything
if (!$dry_run) {
sleep(5);
}
} while (true);
// Remove the now-stale cache when actively run
if (!$dry_run) {
wp_cache_delete('a8c_cron_ctrl_option');
\WP_CLI::line("\n" . sprintf(__('Cleared the %s cache', 'automattic-cron-control'), 'Cron Control'));
}
// Fin
\WP_CLI::success(__('All done.', 'automattic-cron-control'));
}
示例15: _headers
/**
* parse headers
* @access private
* @return bool true on success
*/
private function _headers()
{
$this->_read();
foreach ($this->csv as $raw_header) {
$header = explode('-', $raw_header);
if (in_array($header[0], array('blank', ''))) {
$this->headers[] = array('type' => 'blank', 'sanitize' => 'esc_attr', 'name' => 'blank');
continue;
}
if (!isset($header[0]) || !in_array($header[0], array('post', 'meta', 'taxonomy', 'thumbnail', 'blank'))) {
WP_CLI::warning($raw_header . ' - ' . $header[0] . ' is an unsupported field type. Possible types are meta, post, taxonomy, thumbnail!');
}
if ($header[1] != 'blank' && (!isset($header[1]) || !function_exists($header[1]))) {
WP_CLI::error($raw_header . ' - ' . $header[1] . ' is an undefined function. ensure your sanitization function exists!');
continue;
}
// Rebuild $header[ 2 ] so it supports keys and taxonomies with dashes
$header[2] = implode('-', array_slice($header, 2));
if (!isset($header[0]) || $header[0] == 'taxonomy' && !taxonomy_exists($header[2])) {
WP_CLI::error($raw_header . ' - ' . $header[2] . ' is an not a registered taxonomy!');
continue;
}
$validated_header = array('type' => $header[0], 'sanitize' => $header[1], 'name' => $header[2]);
$this->headers[] = $validated_header;
WP_CLI::line('header ' . $validated_header['type'] . ' ' . $validated_header['name'] . ' value will be sanitized with ' . $validated_header['sanitize']);
}
if (count($this->csv) !== count($this->headers)) {
return WP_CLI::error('headers are incorrectly formatted, try again!');
}
WP_CLI::confirm('Is this what you had in mind? ', '');
WP_CLI::success('headers are correctly formatted, great job!');
return true;
}