@@ -1004,42 +1004,6 @@ private static function find_var( $var_name, $code ) {
10041004 return trim ( $ value , " ' " );
10051005 }
10061006
1007- /**
1008- * Security copy of the core function with Requests - Gets the checksums for the given version of WordPress.
1009- *
1010- * @param string $version Version string to query.
1011- * @param string $locale Locale to query.
1012- * @param bool $insecure Whether to retry without certificate validation on TLS handshake failure.
1013- * @return string|array String message on failure. An array of checksums on success.
1014- */
1015- private static function get_core_checksums ( $ version , $ locale , $ insecure ) {
1016- $ query = http_build_query ( compact ( 'version ' , 'locale ' ), '' , '& ' );
1017- $ url = "https://api.wordpress.org/core/checksums/1.0/? {$ query }" ;
1018-
1019- $ headers = [ 'Accept ' => 'application/json ' ];
1020- $ options = [
1021- 'timeout ' => 30 ,
1022- 'insecure ' => $ insecure ,
1023- ];
1024-
1025- $ response = Utils \http_request ( 'GET ' , $ url , null , $ headers , $ options );
1026-
1027- if ( ! $ response ->success || 200 !== (int ) $ response ->status_code ) {
1028- return "Checksum request ' {$ url }' failed (HTTP {$ response ->status_code }). " ;
1029- }
1030-
1031- $ body = trim ( $ response ->body );
1032- $ body = json_decode ( $ body , true );
1033-
1034- if ( ! is_array ( $ body )
1035- || ! isset ( $ body ['checksums ' ] )
1036- || ! is_array ( $ body ['checksums ' ] ) ) {
1037- return "Checksums not available for WordPress {$ version }/ {$ locale }. " ;
1038- }
1039-
1040- return $ body ['checksums ' ];
1041- }
1042-
10431007 /**
10441008 * Updates WordPress to a newer version.
10451009 *
@@ -1432,14 +1396,19 @@ private function cleanup_extra_files( $version_from, $version_to, $locale, $inse
14321396 return ;
14331397 }
14341398
1435- $ old_checksums = self ::get_core_checksums ( $ version_from , $ locale ?: 'en_US ' , $ insecure );
1436- if ( ! is_array ( $ old_checksums ) ) {
1437- WP_CLI ::warning ( "{$ old_checksums } Please cleanup files manually. " );
1399+ $ wp_org_api = new WpOrgApi ( [ 'insecure ' => $ insecure ] );
1400+
1401+ try {
1402+ $ old_checksums = $ wp_org_api ->get_core_checksums ( $ version_from , $ locale );
1403+ } catch ( Exception $ exception ) {
1404+ WP_CLI ::warning ( "{$ exception ->getMessage ()} Please cleanup files manually. " );
14381405 return ;
14391406 }
1440- $ new_checksums = self ::get_core_checksums ( $ version_to , $ locale ?: 'en_US ' , $ insecure );
1441- if ( ! is_array ( $ new_checksums ) ) {
1442- WP_CLI ::warning ( "{$ new_checksums } Please cleanup files manually. " );
1407+
1408+ try {
1409+ $ new_checksums = $ wp_org_api ->get_core_checksums ( $ version_to , $ locale );
1410+ } catch ( Exception $ exception ) {
1411+ WP_CLI ::warning ( "{$ exception ->getMessage ()} Please cleanup files manually. " );
14431412 return ;
14441413 }
14451414
0 commit comments