From fc5ba529c44061db03e401d6d8f8b034b8303b6e Mon Sep 17 00:00:00 2001 From: mattyrob Date: Thu, 15 Apr 2021 08:34:59 +0100 Subject: [PATCH] Update API Generator to take versions as input WordPress API is currently only reporting an `offer` of 5.7.1 as the latest version so alternative route is needed for back-ported versions --- api-hashes-generator.php | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/api-hashes-generator.php b/api-hashes-generator.php index 91ef868..06fc3ab 100644 --- a/api-hashes-generator.php +++ b/api-hashes-generator.php @@ -6,16 +6,24 @@ */ $version_url = 'https://api.wordpress.org/core/version-check/1.7/'; -$checksum_url = 'https://api.wordpress.org/core/checksums/1.0/?version='; -$locale = '&locale=en_US'; $versions = file_get_contents( $version_url ); $versions = json_decode( $versions ); foreach( $versions->offers as $wp_version ) { - $filename = dirname( __FILE__ ) . '/' . 'hashes-' . $wp_version->version . '.php'; + create_hashes( $wp_version->version ); +} + +if ( isset( $_GET['version'] ) ) { + create_hashes( $_GET['version'] ); +} + +function create_hashes( $wp_version ) { + $checksum_url = 'https://api.wordpress.org/core/checksums/1.0/?version='; + $locale = '&locale=en_US'; + $filename = dirname( __FILE__ ) . '/' . 'hashes-' . $wp_version . '.php'; if ( ! file_exists( $filename ) ) { - $checksums = file_get_contents( $checksum_url . $wp_version->version . $locale ); + $checksums = file_get_contents( $checksum_url . $wp_version . $locale ); $checksums = json_decode( $checksums, true ); $hashes = " $checksum ) { @@ -25,6 +33,6 @@ } $hashes .= ");\n"; file_put_contents( $filename, $hashes ); - echo 'Hash file created for ' . $wp_version->version . "\n"; + echo 'Hash file created for ' . $wp_version . "\n"; } }