Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions src/Core_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,19 +95,22 @@ public function check_update( $args, $assoc_args ) {

$updates = $this->get_updates( $assoc_args );

// Set by the HTTP API hooks that run during the version check.
$version_check_error = $this->get_version_check_error();

if ( $updates || 'table' !== $format ) {
$updates = array_reverse( $updates );
$formatter = new Formatter(
$assoc_args,
[ 'version', 'update_type', 'package_url' ]
);
$formatter->display_items( $updates );
} elseif ( $this->version_check_error ) {
} elseif ( $version_check_error ) {
// If there was an HTTP error during version check, show a warning
WP_CLI::warning(
sprintf(
'Failed to check for updates: %s',
$this->version_check_error->get_error_message()
$version_check_error->get_error_message()
)
);
} else {
Expand Down Expand Up @@ -1870,6 +1873,15 @@ private function get_updates( $assoc_args ) {
return array_values( $updates );
}

/**
* Returns the HTTP API error encountered during the last version check, if any.
*
* @return \WP_Error|null
*/
private function get_version_check_error() {
return $this->version_check_error;
}

/**
* Sets or clears the version check error property based on an HTTP response.
*
Expand Down