Skip to content
This repository has been archived by the owner on Nov 11, 2021. It is now read-only.

Commit

Permalink
Update API Generator to take versions as input
Browse files Browse the repository at this point in the history
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
  • Loading branch information
mattyrob committed Apr 15, 2021
1 parent deaa72e commit fc5ba52
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions api-hashes-generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "<?php\n" . '$filehashes = array(' . "\n";
foreach ( $checksums['checksums'] as $file => $checksum ) {
Expand All @@ -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";
}
}

0 comments on commit fc5ba52

Please sign in to comment.