Merge pull request #21073 from woocommerce/fix/20694

Show system status updates for woocommerce wp.org plugins
This commit is contained in:
Claudiu Lodromanean 2018-08-20 10:29:01 -07:00 committed by GitHub
commit 42e2e4a4b2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 35 additions and 11 deletions

View File

@ -796,18 +796,42 @@ class WC_REST_System_Status_Controller extends WC_REST_Controller {
$version_data = get_transient( md5( $plugin ) . '_version_data' ); $version_data = get_transient( md5( $plugin ) . '_version_data' );
if ( false === $version_data ) { if ( false === $version_data ) {
$changelog = wp_safe_remote_get( 'http://dzv365zjfbd8v.cloudfront.net/changelogs/' . $dirname . '/changelog.txt' ); $changelog = wp_safe_remote_get( 'http://dzv365zjfbd8v.cloudfront.net/changelogs/' . $dirname . '/changelog.txt' );
$cl_lines = explode( "\n", wp_remote_retrieve_body( $changelog ) ); if ( 200 === wp_remote_retrieve_response_code( $changelog ) ) {
if ( ! empty( $cl_lines ) ) { $cl_lines = explode( "\n", wp_remote_retrieve_body( $changelog ) );
foreach ( $cl_lines as $line_num => $cl_line ) { if ( ! empty( $cl_lines ) ) {
if ( preg_match( '/^[0-9]/', $cl_line ) ) { foreach ( $cl_lines as $line_num => $cl_line ) {
$date = str_replace( '.', '-', trim( substr( $cl_line, 0, strpos( $cl_line, '-' ) ) ) ); if ( preg_match( '/^[0-9]/', $cl_line ) ) {
$version = preg_replace( '~[^0-9,.]~', '', stristr( $cl_line, 'version' ) ); $date = str_replace( '.', '-', trim( substr( $cl_line, 0, strpos( $cl_line, '-' ) ) ) );
$update = trim( str_replace( '*', '', $cl_lines[ $line_num + 1 ] ) ); $version = preg_replace( '~[^0-9,.]~', '', stristr( $cl_line, 'version' ) );
$update = trim( str_replace( '*', '', $cl_lines[ $line_num + 1 ] ) );
$version_data = array(
'date' => $date,
'version' => $version,
'update' => $update,
'changelog' => $changelog,
);
set_transient( md5( $plugin ) . '_version_data', $version_data, DAY_IN_SECONDS );
break;
}
}
}
} else {
$args = (object) array(
'slug' => $dirname,
);
$request = array(
'action' => 'plugin_information',
'request' => serialize( $args ),
);
$plugin_info = wp_safe_remote_post( 'http://api.wordpress.org/plugins/info/1.0/', array( 'body' => $request ) );
if ( 200 === wp_remote_retrieve_response_code( $plugin_info ) ) {
$body = maybe_unserialize( wp_remote_retrieve_body( $plugin_info ) );
if ( is_object( $body ) && isset( $body->sections['changelog'] ) ) {
$version_data = array( $version_data = array(
'date' => $date, 'date' => $body->last_updated,
'version' => $version, 'version' => $body->version,
'update' => $update, 'update' => $body->sections['changelog'],
'changelog' => $changelog, 'changelog' => $body->sections['changelog'],
); );
set_transient( md5( $plugin ) . '_version_data', $version_data, DAY_IN_SECONDS ); set_transient( md5( $plugin ) . '_version_data', $version_data, DAY_IN_SECONDS );
break; break;