|
31 | 31 | */ |
32 | 32 | class Core_Command extends WP_CLI_Command { |
33 | 33 |
|
| 34 | + /** |
| 35 | + * Stores HTTP API errors encountered during version check. |
| 36 | + * |
| 37 | + * @var \WP_Error|null |
| 38 | + */ |
| 39 | + private $version_check_error = null; |
| 40 | + |
34 | 41 | /** |
35 | 42 | * Checks for WordPress updates via Version Check API. |
36 | 43 | * |
@@ -93,7 +100,17 @@ public function check_update( $args, $assoc_args ) { |
93 | 100 | ); |
94 | 101 | $formatter->display_items( $updates ); |
95 | 102 | } else { |
96 | | - WP_CLI::success( 'WordPress is at the latest version.' ); |
| 103 | + // If there was an HTTP error during version check, show a warning |
| 104 | + if ( $this->version_check_error ) { |
| 105 | + WP_CLI::warning( |
| 106 | + sprintf( |
| 107 | + 'Failed to check for updates: %s', |
| 108 | + $this->version_check_error->get_error_message() |
| 109 | + ) |
| 110 | + ); |
| 111 | + } else { |
| 112 | + WP_CLI::success( 'WordPress is at the latest version.' ); |
| 113 | + } |
97 | 114 | } |
98 | 115 | } |
99 | 116 |
|
@@ -1439,8 +1456,18 @@ private function get_download_url( $version, $locale = 'en_US', $file_type = 'zi |
1439 | 1456 | */ |
1440 | 1457 | private function get_updates( $assoc_args ) { |
1441 | 1458 | $force_check = Utils\get_flag_value( $assoc_args, 'force-check' ); |
| 1459 | + |
| 1460 | + // Reset error tracking |
| 1461 | + $this->version_check_error = null; |
| 1462 | + |
| 1463 | + // Hook into HTTP API debug to capture errors during version check |
| 1464 | + add_action( 'http_api_debug', [ $this, 'capture_version_check_error' ], 10, 5 ); |
| 1465 | + |
1442 | 1466 | wp_version_check( [], $force_check ); |
1443 | 1467 |
|
| 1468 | + // Remove the hook after version check |
| 1469 | + remove_action( 'http_api_debug', [ $this, 'capture_version_check_error' ], 10 ); |
| 1470 | + |
1444 | 1471 | /** |
1445 | 1472 | * @var object{updates: array<object{version: string, locale: string, packages: object{partial?: string, full: string}}>}|false $from_api |
1446 | 1473 | */ |
@@ -1496,6 +1523,27 @@ private function get_updates( $assoc_args ) { |
1496 | 1523 | return array_values( $updates ); |
1497 | 1524 | } |
1498 | 1525 |
|
| 1526 | + /** |
| 1527 | + * Handles the http_api_debug action to capture HTTP errors during version check. |
| 1528 | + * |
| 1529 | + * @param array|WP_Error $response HTTP response or WP_Error object. |
| 1530 | + * @param string $context Context of the HTTP request. |
| 1531 | + * @param string $class HTTP transport class name. |
| 1532 | + * @param array $args HTTP request arguments. |
| 1533 | + * @param string $url URL being requested. |
| 1534 | + */ |
| 1535 | + private function capture_version_check_error( $response, $context, $class, $args, $url ) { |
| 1536 | + // Only capture errors for the version check API |
| 1537 | + if ( false === strpos( $url, 'api.wordpress.org/core/version-check' ) ) { |
| 1538 | + return; |
| 1539 | + } |
| 1540 | + |
| 1541 | + // Store the error if the response is a WP_Error |
| 1542 | + if ( is_wp_error( $response ) ) { |
| 1543 | + $this->version_check_error = $response; |
| 1544 | + } |
| 1545 | + } |
| 1546 | + |
1499 | 1547 | /** |
1500 | 1548 | * Clean up extra files. |
1501 | 1549 | * |
|
0 commit comments