From 1d7f1fe97c28f3a29625e3c70fe8c68e05d47f3c Mon Sep 17 00:00:00 2001 From: Joe Dolson Date: Sun, 14 Apr 2024 11:16:23 -0500 Subject: [PATCH] Improve handling if data from twitter is not valid JSON. --- src/wp-to-twitter-oauth.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/wp-to-twitter-oauth.php b/src/wp-to-twitter-oauth.php index c4d9b2f..3520fa5 100644 --- a/src/wp-to-twitter-oauth.php +++ b/src/wp-to-twitter-oauth.php @@ -195,9 +195,15 @@ function wpt_update_oauth_settings( $auth = false, $post = false ) { if ( $connection ) { $data = $connection->get( 'https://api.twitter.com/1.1/account/verify_credentials.json' ); if ( '200' !== (string) $connection->http_code ) { - $data = json_decode( $data ); - $code = "" . $data->errors[0]->code . ''; - $error = $data->errors[0]->message; + $parsed = json_decode( $data ); + if ( is_object( $parsed ) ) { + $code = "" . $parsed->errors[0]->code . ''; + $error = $parsed->errors[0]->message; + } else { + $code = 'null'; + $error = __( 'Data was not returned in a recognizable format.', 'wp-to-twitter' ); + echo '
'; print_r( $data ); echo '
'; + } update_option( 'wpt_error', "$code: $error" ); } else { delete_option( 'wpt_error' );