Skip to content

Commit 062a77f

Browse files
committed
Use WpOrgApi abstraction
1 parent e57258e commit 062a77f

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/WP_CLI/CommandWithUpgrade.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace WP_CLI;
44

55
use Composer\Semver\Comparator;
6+
use Exception;
67
use WP_CLI;
78
use WP_CLI\Fetchers;
89
use WP_CLI\Loggers;
@@ -583,15 +584,14 @@ private function get_color( $status ) {
583584
* @return array
584585
*/
585586
private function get_minor_or_patch_updates( $items, $type, $insecure ) {
587+
$wp_org_api = new WpOrgApi( [ 'insecure' => $insecure ] );
586588
foreach ( $items as $i => $item ) {
587-
$wporg_url = sprintf( 'https://api.wordpress.org/plugins/info/1.0/%s.json', $item['name'] );
588-
$response = Utils\http_request( 'GET', $wporg_url, null, [], [ 'insecure' => $insecure ] );
589-
// Must not be hosted on wp.org
590-
if ( 20 !== absint( substr( $response->status_code, 0, 2 ) ) ) {
589+
try {
590+
$data = $wp_org_api->get_plugin_info( $item['name'] );
591+
} catch ( Exception $exception ) {
591592
unset( $items[ $i ] );
592593
continue;
593594
}
594-
$data = json_decode( $response->body, true );
595595
// No minor or patch versions to access.
596596
if ( empty( $data['versions'] ) ) {
597597
unset( $items[ $i ] );

0 commit comments

Comments
 (0)