Get latest pre-release by comparing against (beta/rc) versions higher than latest release

This commit is contained in:
Boro Sitnikovski 2018-06-05 23:18:07 +02:00
parent 6f95040c5e
commit c1c73611fd
1 changed files with 8 additions and 12 deletions

View File

@ -106,21 +106,17 @@ class WC_Beta_Tester {
if ( $this->overrule_transients() || empty( $tagged_version ) ) { if ( $this->overrule_transients() || empty( $tagged_version ) ) {
$raw_response = wp_remote_get( trailingslashit( $this->config['api_url'] ) . 'releases' ); $data = $this->get_wporg_data();
if ( is_wp_error( $raw_response ) ) { $latest_version = $data->version;
return false; $versions = (array) $data->versions;
}
$releases = json_decode( $raw_response['body'] ); foreach ( $versions as $version => $download_url ) {
$tagged_version = false; if ( version_compare( $version, $latest_version, '>' )
&& preg_match( '/(.*)?-(beta|rc)(.*)/', $version ) ) {
if ( is_array( $releases ) ) { $tagged_version = $version;
foreach ( $releases as $release ) { break;
if ( $release->prerelease ) {
$tagged_version = $release->tag_name;
break;
}
} }
} }