Skip to content

Commit

Permalink
It is previously checked if there is any error in the call to wp_remo…
Browse files Browse the repository at this point in the history
…te_get
  • Loading branch information
teamcrombie committed Oct 8, 2024
1 parent c021ef6 commit 1a75f95
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 12 deletions.
29 changes: 22 additions & 7 deletions admin/Ilove_Img_Wm_Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -388,18 +388,33 @@ public function show_notices() {
)
);

if ( isset( $response['response']['code'] ) && 200 === $response['response']['code'] ) {
$account = json_decode( $response['body'], true );

if ( $account['files_used'] >= $account['free_files_limit'] && $account['package_files_used'] >= $account['package_files_limit'] && (int) $account['subscription_files_used'] >= $account['subscription_files_limit'] ) {
if ( ! is_wp_error( $response ) ) {

if ( 200 === $response['response']['code'] ) {
$account = json_decode( $response['body'], true );

if ( $account['files_used'] >= $account['free_files_limit'] && $account['package_files_used'] >= $account['package_files_limit'] && (int) $account['subscription_files_used'] >= $account['subscription_files_limit'] ) {
?>
<div class="notice notice-warning is-dismissible">
<p><strong>iLoveIMG</strong> - Please you need more credits. <a href="https://iloveapi.com/pricing" target="_blank">Buy more credits</a></p>
</div>
<?php
}
} else {
?>
<div class="notice notice-warning is-dismissible">
<p><strong>iLoveIMG</strong> - Please you need more credits. <a href="https://iloveapi.com/pricing" target="_blank">Buy more credits</a></p>
<div class="notice notice-error is-dismissible">
<p><strong>iLoveIMG</strong> - We were unable to verify the status of your iloveAPI account. Please try again later.</p>
</div>
<?php
}
} else {
?>
<div class="notice notice-error is-dismissible">
<p><strong>iLoveIMG</strong> - We were unable to verify the status of your iloveAPI account. Please try again later.</p>
</div>
<?php
}
}
}
}
}

Expand Down
18 changes: 13 additions & 5 deletions admin/views/account.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,19 @@
)
);

if ( isset( $ilove_img_wm_response['response']['code'] ) && 200 === $ilove_img_wm_response['response']['code'] ) {
$ilove_img_wm_account = json_decode( $ilove_img_wm_response['body'], true );
$ilove_img_wm_account['token'] = $ilove_img_wm_token;
update_option( 'iloveimg_account', wp_json_encode( $ilove_img_wm_account ) );
}
if ( ! is_wp_error( $ilove_img_wm_response ) ) {
if ( 200 === $ilove_img_wm_response['response']['code'] ) {
$ilove_img_wm_account = json_decode( $ilove_img_wm_response['body'], true );
$ilove_img_wm_account['token'] = $ilove_img_wm_token;
update_option( 'iloveimg_account', wp_json_encode( $ilove_img_wm_account ) );
}
} else {
?>
<div class="notice notice-error is-dismissible">
<p><strong>iLoveIMG</strong> - We were unable to verify the status of your iloveAPI account. Please try again later.</p>
</div>
<?php
}
} elseif ( get_option( 'iloveimg_account_error' ) ) {
$ilove_img_wm_account_error = json_decode( get_option( 'iloveimg_account_error' ), true );
delete_option( 'iloveimg_account_error' );
Expand Down

0 comments on commit 1a75f95

Please sign in to comment.