本文整理汇总了PHP中WP_CLI::get_http_cache_manager方法的典型用法代码示例。如果您正苦于以下问题:PHP WP_CLI::get_http_cache_manager方法的具体用法?PHP WP_CLI::get_http_cache_manager怎么用?PHP WP_CLI::get_http_cache_manager使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WP_CLI
的用法示例。
在下文中一共展示了WP_CLI::get_http_cache_manager方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: install_from_repo
protected function install_from_repo($slug, $assoc_args)
{
$api = themes_api('theme_information', array('slug' => $slug));
if (is_wp_error($api)) {
return $api;
}
if (isset($assoc_args['version'])) {
self::alter_api_response($api, $assoc_args['version']);
}
if (!isset($assoc_args['force']) && wp_get_theme($slug)->exists()) {
// We know this will fail, so avoid a needless download of the package.
return new WP_Error('already_installed', 'Theme already installed.');
}
WP_CLI::log(sprintf('Installing %s (%s)', $api->name, $api->version));
if (!isset($assoc_args['version']) || 'dev' !== $assoc_args['version']) {
WP_CLI::get_http_cache_manager()->whitelist_package($api->download_link, $this->item_type, $api->slug, $api->version);
}
$result = $this->get_upgrader($assoc_args)->install($api->download_link);
return $result;
}
示例2: update_many
protected function update_many($args, $assoc_args)
{
call_user_func($this->upgrade_refresh);
if (!empty($assoc_args['format']) && in_array($assoc_args['format'], array('json', 'csv'))) {
$logger = new \WP_CLI\Loggers\Quiet();
\WP_CLI::set_logger($logger);
}
if (!\WP_CLI\Utils\get_flag_value($assoc_args, 'all') && empty($args)) {
\WP_CLI::error("Please specify one or more {$this->item_type}s, or use --all.");
}
$items = $this->get_item_list();
if (!\WP_CLI\Utils\get_flag_value($assoc_args, 'all')) {
$items = $this->filter_item_list($items, $args);
}
$items_to_update = wp_list_filter($items, array('update' => true));
if (\WP_CLI\Utils\get_flag_value($assoc_args, 'dry-run')) {
if (empty($items_to_update)) {
\WP_CLI::line("No {$this->item_type} updates available.");
return;
}
if (!empty($assoc_args['format']) && in_array($assoc_args['format'], array('json', 'csv'))) {
\WP_CLI\Utils\format_items($assoc_args['format'], $items_to_update, array('name', 'status', 'version', 'update_version'));
} else {
if (!empty($assoc_args['format']) && 'summary' === $assoc_args['format']) {
\WP_CLI::line("Available {$this->item_type} updates:");
foreach ($items_to_update as $item_to_update => $info) {
\WP_CLI::log("{$info['title']} update from version {$info['version']} to version {$info['update_version']}");
}
} else {
\WP_CLI::line("Available {$this->item_type} updates:");
\WP_CLI\Utils\format_items('table', $items_to_update, array('name', 'status', 'version', 'update_version'));
}
}
return;
}
$result = array();
// Only attempt to update if there is something to update
if (!empty($items_to_update)) {
$cache_manager = \WP_CLI::get_http_cache_manager();
foreach ($items_to_update as $item) {
$cache_manager->whitelist_package($item['update_package'], $this->item_type, $item['name'], $item['update_version']);
}
$upgrader = $this->get_upgrader($assoc_args);
$result = $upgrader->bulk_upgrade(wp_list_pluck($items_to_update, 'update_id'));
}
// Let the user know the results.
$num_to_update = count($items_to_update);
$num_updated = count(array_filter($result));
$line = "Updated {$num_updated}/{$num_to_update} {$this->item_type}s.";
if ($num_to_update == $num_updated) {
\WP_CLI::success($line);
} else {
if ($num_updated > 0) {
\WP_CLI::warning($line);
} else {
\WP_CLI::error($line);
}
}
if ($num_to_update > 0) {
if (!empty($assoc_args['format']) && 'summary' === $assoc_args['format']) {
foreach ($items_to_update as $item_to_update => $info) {
$message = $result[$info['update_id']] !== null ? 'updated successfully' : 'did not update';
\WP_CLI::log("{$info['title']} {$message} from version {$info['version']} to version {$info['update_version']}");
}
} else {
$status = array();
foreach ($items_to_update as $item_to_update => $info) {
$status[$item_to_update] = array('name' => $info['name'], 'old_version' => $info['version'], 'new_version' => $info['update_version'], 'status' => $result[$info['update_id']] !== null ? 'Updated' : 'Error');
}
$format = 'table';
if (!empty($assoc_args['format']) && in_array($assoc_args['format'], array('json', 'csv'))) {
$format = $assoc_args['format'];
}
\WP_CLI\Utils\format_items($format, $status, array('name', 'old_version', 'new_version', 'status'));
}
}
}
示例3: update_many
protected function update_many($args, $assoc_args)
{
call_user_func($this->upgrade_refresh);
$items = $this->get_item_list();
if (!isset($assoc_args['all'])) {
$items = $this->filter_item_list($items, $args);
}
$items_to_update = wp_list_filter($items, array('update' => true));
if (isset($assoc_args['dry-run'])) {
if (empty($items_to_update)) {
\WP_CLI::line("No {$this->item_type} updates available.");
return;
}
\WP_CLI::line("Available {$this->item_type} updates:");
\WP_CLI\Utils\format_items('table', $items_to_update, array('name', 'status', 'version', 'update_version'));
return;
}
$result = array();
// Only attempt to update if there is something to update
if (!empty($items_to_update)) {
$cache_manager = \WP_CLI::get_http_cache_manager();
foreach ($items_to_update as $item) {
$cache_manager->whitelist_package($item['update_package'], $this->item_type, $item['name'], $item['update_version']);
}
$upgrader = $this->get_upgrader($assoc_args);
$result = $upgrader->bulk_upgrade(wp_list_pluck($items_to_update, 'update_id'));
}
// Let the user know the results.
$num_to_update = count($items_to_update);
$num_updated = count(array_filter($result));
$line = "Updated {$num_updated}/{$num_to_update} {$this->item_type}s.";
if ($num_to_update == $num_updated) {
\WP_CLI::success($line);
} else {
if ($num_updated > 0) {
\WP_CLI::warning($line);
} else {
\WP_CLI::error($line);
}
}
}
示例4: install_from_repo
protected function install_from_repo($slug, $assoc_args)
{
$api = plugins_api('plugin_information', array('slug' => $slug));
if (is_wp_error($api)) {
return $api;
}
if (isset($assoc_args['version'])) {
self::alter_api_response($api, $assoc_args['version']);
}
$status = install_plugin_install_status($api);
if (!\WP_CLI\Utils\get_flag_value($assoc_args, 'force') && 'install' != $status['status']) {
// We know this will fail, so avoid a needless download of the package.
return new WP_Error('already_installed', 'Plugin already installed.');
}
WP_CLI::log(sprintf('Installing %s (%s)', html_entity_decode($api->name, ENT_QUOTES), $api->version));
if (\WP_CLI\Utils\get_flag_value($assoc_args, 'version') != 'dev') {
WP_CLI::get_http_cache_manager()->whitelist_package($api->download_link, $this->item_type, $api->slug, $api->version);
}
$result = $this->get_upgrader($assoc_args)->install($api->download_link);
return $result;
}
示例5: install_from_repo
protected function install_from_repo($slug, $assoc_args)
{
$api = themes_api('theme_information', array('slug' => $slug));
if (is_wp_error($api)) {
return $api;
}
if (isset($assoc_args['version'])) {
self::alter_api_response($api, $assoc_args['version']);
}
if (!\WP_CLI\Utils\get_flag_value($assoc_args, 'force')) {
$theme = wp_get_theme($slug);
if ($theme->exists()) {
// We know this will fail, so avoid a needless download of the package.
return new WP_Error('already_installed', 'Theme already installed.');
}
// Clear cache so WP_Theme doesn't create a "missing theme" object.
$cache_hash = md5($theme->theme_root . '/' . $theme->stylesheet);
foreach (array('theme', 'screenshot', 'headers', 'page_templates') as $key) {
wp_cache_delete($key . '-' . $cache_hash, 'themes');
}
}
WP_CLI::log(sprintf('Installing %s (%s)', html_entity_decode($api->name, ENT_QUOTES), $api->version));
if (\WP_CLI\Utils\get_flag_value($assoc_args, 'version') != 'dev') {
WP_CLI::get_http_cache_manager()->whitelist_package($api->download_link, $this->item_type, $api->slug, $api->version);
}
$result = $this->get_upgrader($assoc_args)->install($api->download_link);
return $result;
}