本文整理汇总了PHP中WP_CLI::error_to_string方法的典型用法代码示例。如果您正苦于以下问题:PHP WP_CLI::error_to_string方法的具体用法?PHP WP_CLI::error_to_string怎么用?PHP WP_CLI::error_to_string使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WP_CLI
的用法示例。
在下文中一共展示了WP_CLI::error_to_string方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: update
/**
* Update WordPress.
*
* ## OPTIONS
*
* [<zip>]
* : Path to zip file to use, instead of downloading from wordpress.org.
*
* [--version=<version>]
* : Update to this version, instead of to the latest version.
*
* [--force]
* : Update even when installed WP version is greater than the requested version.
*
* [--locale=<locale>]
* : Select which language you want to download.
*
* ## EXAMPLES
*
* wp core update
*
* wp core update --version=3.8 ../latest.zip
*
* wp core update --version=3.1 --force
*
* @alias upgrade
*/
function update($args, $assoc_args)
{
global $wp_version;
$update = $from_api = null;
$upgrader = 'WP_CLI\\CoreUpgrader';
if (!empty($args[0])) {
$upgrader = 'WP_CLI\\NonDestructiveCoreUpgrader';
$version = !empty($assoc_args['version']) ? $assoc_args['version'] : null;
$update = (object) array('response' => 'upgrade', 'current' => $version, 'download' => $args[0], 'packages' => (object) array('partial' => null, 'new_bundled' => null, 'no_content' => null, 'full' => $args[0]), 'version' => $version, 'locale' => null);
} else {
if (empty($assoc_args['version'])) {
wp_version_check();
$from_api = get_site_transient('update_core');
if (empty($from_api->updates)) {
$update = false;
} else {
list($update) = $from_api->updates;
}
} else {
if (version_compare($wp_version, $assoc_args['version'], '<') || isset($assoc_args['force'])) {
$version = $assoc_args['version'];
$locale = isset($assoc_args['locale']) ? $assoc_args['locale'] : get_locale();
$new_package = $this->get_download_url($version, $locale);
$update = (object) array('response' => 'upgrade', 'current' => $assoc_args['version'], 'download' => $new_package, 'packages' => (object) array('partial' => null, 'new_bundled' => null, 'no_content' => null, 'full' => $new_package), 'version' => $version, 'locale' => $locale);
} else {
WP_CLI::success('WordPress is up to date.');
return;
}
}
}
require_once ABSPATH . 'wp-admin/includes/upgrade.php';
if ($update->version) {
WP_CLI::log("Updating to version {$update->version} ({$update->locale})...");
} else {
WP_CLI::log("Starting update...");
}
$GLOBALS['wp_cli_update_obj'] = $update;
$result = Utils\get_upgrader($upgrader)->upgrade($update);
unset($GLOBALS['wp_cli_update_obj']);
if (is_wp_error($result)) {
$msg = WP_CLI::error_to_string($result);
if ('up_to_date' != $result->get_error_code()) {
WP_CLI::error($msg);
} else {
WP_CLI::success($msg);
}
} else {
WP_CLI::success('WordPress updated successfully.');
}
}
示例2: update
/**
* Update WordPress.
*
* ## OPTIONS
*
* [<zip>]
* : Path to zip file to use, instead of downloading from wordpress.org.
*
* [--minor]
* : Only perform updates for minor releases (e.g. update from WP 4.3 to 4.3.3 instead of 4.4.2).
*
* [--version=<version>]
* : Update to a specific version, instead of to the latest version.
*
* [--force]
* : Update even when installed WP version is greater than the requested version.
*
* [--locale=<locale>]
* : Select which language you want to download.
*
* ## EXAMPLES
*
* wp core update
*
* wp core update --version=3.8 ../latest.zip
*
* wp core update --version=3.1 --force
*
* @alias upgrade
*/
function update($args, $assoc_args)
{
global $wp_version;
$update = $from_api = null;
$upgrader = 'WP_CLI\\CoreUpgrader';
if (empty($args[0]) && empty($assoc_args['version']) && \WP_CLI\Utils\get_flag_value($assoc_args, 'minor')) {
$updates = $this->get_updates(array('minor' => true));
if (!empty($updates)) {
$assoc_args['version'] = $updates[0]['version'];
} else {
WP_CLI::success('WordPress is at the latest minor release.');
return;
}
}
if (!empty($args[0])) {
$upgrader = 'WP_CLI\\NonDestructiveCoreUpgrader';
$version = \WP_CLI\Utils\get_flag_value($assoc_args, 'version');
$update = (object) array('response' => 'upgrade', 'current' => $version, 'download' => $args[0], 'packages' => (object) array('partial' => null, 'new_bundled' => null, 'no_content' => null, 'full' => $args[0]), 'version' => $version, 'locale' => null);
} else {
if (empty($assoc_args['version'])) {
wp_version_check();
$from_api = get_site_transient('update_core');
if (!empty($from_api->updates)) {
list($update) = $from_api->updates;
}
} else {
if (\WP_CLI\Utils\wp_version_compare($assoc_args['version'], '<') || \WP_CLI\Utils\get_flag_value($assoc_args, 'force')) {
$version = $assoc_args['version'];
$locale = \WP_CLI\Utils\get_flag_value($assoc_args, 'locale', get_locale());
$new_package = $this->get_download_url($version, $locale);
$update = (object) array('response' => 'upgrade', 'current' => $assoc_args['version'], 'download' => $new_package, 'packages' => (object) array('partial' => null, 'new_bundled' => null, 'no_content' => null, 'full' => $new_package), 'version' => $version, 'locale' => $locale);
}
}
}
if (!empty($update) && ($update->version != $wp_version || \WP_CLI\Utils\get_flag_value($assoc_args, 'force'))) {
require_once ABSPATH . 'wp-admin/includes/upgrade.php';
if ($update->version) {
WP_CLI::log("Updating to version {$update->version} ({$update->locale})...");
} else {
WP_CLI::log("Starting update...");
}
$from_version = $wp_version;
$GLOBALS['wp_cli_update_obj'] = $update;
$result = Utils\get_upgrader($upgrader)->upgrade($update);
unset($GLOBALS['wp_cli_update_obj']);
if (is_wp_error($result)) {
$msg = WP_CLI::error_to_string($result);
if ('up_to_date' != $result->get_error_code()) {
WP_CLI::error($msg);
} else {
WP_CLI::success($msg);
}
} else {
if (file_exists(ABSPATH . 'wp-includes/version.php')) {
include ABSPATH . 'wp-includes/version.php';
$to_version = $wp_version;
}
$locale = \WP_CLI\Utils\get_flag_value($assoc_args, 'locale', get_locale());
$this->cleanup_extra_files($from_version, $to_version, $locale);
WP_CLI::success('WordPress updated successfully.');
}
} else {
WP_CLI::success('WordPress is up to date.');
}
}
示例3: update
/**
* Update WordPress.
*
* ## OPTIONS
*
* [<zip>]
* : Path to zip file to use, instead of downloading from wordpress.org.
*
* [--version=<version>]
* : Update to this version, instead of to the latest version.
*
* [--force]
* : Will update even when current WP version < passed version. Use with
* caution.
*
* ## EXAMPLES
*
* wp core update
*
* wp core update --version=3.4 ../latest.zip
*
* wp core update --version=3.1 --force
*
* @alias upgrade
*/
function update($args, $assoc_args)
{
global $wp_version;
$update = $from_api = null;
$upgrader = 'Core_Upgrader';
if (empty($assoc_args['version'])) {
wp_version_check();
$from_api = get_site_transient('update_core');
if (empty($from_api->updates)) {
$update = false;
} else {
list($update) = $from_api->updates;
}
} else {
if (version_compare($wp_version, $assoc_args['version'], '<') || isset($assoc_args['force'])) {
$new_package = null;
if (empty($args[0])) {
$new_package = 'https://wordpress.org/wordpress-' . $assoc_args['version'] . '.zip';
WP_CLI::log(sprintf('Downloading WordPress %s (%s)...', $assoc_args['version'], 'en_US'));
} else {
$new_package = $args[0];
$upgrader = 'WP_CLI\\NonDestructiveCoreUpgrader';
}
$update = (object) array('response' => 'upgrade', 'current' => $assoc_args['version'], 'download' => $new_package, 'packages' => (object) array('partial' => null, 'new_bundled' => null, 'no_content' => null, 'full' => $new_package));
} else {
WP_CLI::success('WordPress is up to date.');
return;
}
}
require_once ABSPATH . 'wp-admin/includes/upgrade.php';
$result = Utils\get_upgrader($upgrader)->upgrade($update);
if (is_wp_error($result)) {
$msg = WP_CLI::error_to_string($result);
if ('up_to_date' != $result->get_error_code()) {
WP_CLI::error($msg);
} else {
WP_CLI::success($msg);
}
} else {
WP_CLI::success('WordPress updated successfully.');
}
}
示例4: list_events
/**
* List scheduled cron events.
*
* @since 1.2
*
* @alias list
* @subcommand list-events
* @synopsis [--format=<format>]
*/
public function list_events($args, $assoc_args)
{
$defaults = array('format' => 'table');
$values = wp_parse_args($assoc_args, $defaults);
$events = $this->crontrol->get_cron_events();
if (is_wp_error($events)) {
WP_CLI::line(WP_CLI::error_to_string($events));
die;
}
$events = array_map(array($this, '_map_event'), $events);
$fields = array('hook', 'next_run', 'recurrence');
\WP_CLI\Utils\format_items($values['format'], $events, $fields);
}