Skip to content

Commit

Permalink
Merge pull request #4177 from impress-org/issue/4176
Browse files Browse the repository at this point in the history
fix: prevent fatal error when refresh licenses #4176
  • Loading branch information
ravinderk committed Jul 15, 2019
2 parents 0962a16 + 2712291 commit 097dc93
Showing 1 changed file with 22 additions and 21 deletions.
43 changes: 22 additions & 21 deletions includes/misc-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -2380,34 +2380,36 @@ function ( $plugin_name ) {
)
: array();

$tmp = Give_License::request_license_api(
array(
'edd_action' => 'check_licenses',
'licenses' => $license_keys,
'unlicensed' => implode( ',', $unlicensed_give_addon ),
)
);
$tmp = Give_License::request_license_api( array(
'edd_action' => 'check_licenses',
'licenses' => $license_keys,
'unlicensed' => implode( ',', $unlicensed_give_addon ),
), true );

if ( ! $tmp || is_wp_error( $tmp ) ) {
return array();
}

// Prevent fatal error on WP 4.9.10
// Because wp_list_pluck accept only array or array of array in that version.
// @see https://github.com/impress-org/give/issues/4176
$tmp = json_decode( json_encode( $tmp ), true );

// Remove unlicensed add-on from response.
$tmp_unlicensed = array();
foreach ( $tmp as $key => $data ){
if( empty( $data ) ) {
unset( $tmp->{"{$key}"} );
foreach ( $tmp as $key => $data ) {
if ( empty( $data ) ) {
unset( $tmp["{$key}"] );
continue;
}

if( ! isset( $data->check_license ) ) {
$tmp_unlicensed[$key] = $data;
unset( $tmp->{"{$key}"} );
if ( empty( $data['check_license'] ) ) {
$tmp_unlicensed[ $key ] = $data;
unset( $tmp["{$key}"] );
}
}

$check_licenses = json_decode( json_encode( wp_list_pluck( $tmp, 'check_license' ) ), true );
$check_licenses = wp_list_pluck( $tmp, 'check_license' );

/* @var stdClass $data */
foreach ( $check_licenses as $key => $data ) {
Expand All @@ -2424,25 +2426,24 @@ function ( $plugin_name ) {
}

$tmp_update_plugins = array_merge(
array_filter( json_decode( json_encode( wp_list_pluck( $tmp, 'get_version' ) ), true ) ),
array_filter( json_decode( json_encode( wp_list_pluck( $tmp, 'get_versions' ) ), true ) )
array_filter( wp_list_pluck( $tmp, 'get_version' ) ),
array_filter( wp_list_pluck( $tmp, 'get_versions' ) )
);

if( $tmp_unlicensed ) {
$tmp_unlicensed = json_decode( json_encode( $tmp_unlicensed ), true );
if ( $tmp_unlicensed ) {
$tmp_update_plugins = array_merge( $tmp_update_plugins, $tmp_unlicensed );
}

update_option( 'give_licenses', $give_licenses, 'no' );
update_option( 'give_get_versions', $tmp_update_plugins, 'no' );

$refresh = Give_License::refresh_license_status();
$refresh['time'] = current_time( 'timestamp', 1 );
$refresh = Give_License::refresh_license_status();
$refresh['time'] = current_time( 'timestamp', 1 );

update_option( 'give_licenses_refreshed_last_checked', $refresh, 'no' );

// Tell WordPress to look for updates.
if( $wp_check_updates ) {
if ( $wp_check_updates ) {
set_site_transient( 'update_plugins', null );
}

Expand Down

0 comments on commit 097dc93

Please sign in to comment.