Skip to content

Commit

Permalink
add error handling if the version-check api is unavailable for some r…
Browse files Browse the repository at this point in the history
…eason
  • Loading branch information
jazzsequence committed Apr 3, 2024
1 parent f686069 commit 1a10130
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions features/bootstrap/utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -706,13 +706,18 @@ function get_temp_dir() {
*
* @access public
* @category System
*
* @throws Exception If the version check API fails to respond.
* @return string
*/
function get_wp_version() {
// Fetch the latest WordPress version info from the WordPress.org API
$url = 'https://api.wordpress.org/core/version-check/1.7/';
$json = file_get_contents($url);
$context = stream_context_create(['http' => ['timeout' => 5]]);
$json = file_get_contents($url, false, $context);
if ($json === false) {
throw new \Exception('Failed to fetch the latest WordPress version.');
}

$data = json_decode($json, true);

// Extract the latest version number
Expand Down

0 comments on commit 1a10130

Please sign in to comment.