Skip to content

Commit

Permalink
only store the API response if the status code was 200 and the respon…
Browse files Browse the repository at this point in the history
…se not empty
  • Loading branch information
2ndkauboy committed Feb 5, 2023
1 parent 4c3342e commit ef008d6
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions wpmeetup-widget.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,14 @@ public function get_meetups() {
if ( false === $api_data ) {
$api_request = 'https://wpmeetups.de/wp-json/wp/v2/meetup/?per_page=100&orderby=title&order=asc';
$api_response = wp_remote_get( $api_request );
$api_data = json_decode( wp_remote_retrieve_body( $api_response ), true );
set_transient( 'wpmg_wpmeetup_meetups', $api_data, DAY_IN_SECONDS );
$api_code = wp_remote_retrieve_response_code( $api_response );
if ( 200 !== $api_code ) {
return;
}
$api_data = json_decode( wp_remote_retrieve_body( $api_response ), true );
if ( ! empty( $api_data ) ) {
set_transient( 'wpmg_wpmeetup_meetups', $api_data, DAY_IN_SECONDS );
}
}

foreach ( $api_data as $meetup ) {
Expand Down

0 comments on commit ef008d6

Please sign in to comment.