From 0819dbbc192a636d2d967da624d543fd73943005 Mon Sep 17 00:00:00 2001 From: scottlimmer Date: Tue, 23 May 2023 14:01:00 +1000 Subject: [PATCH] Update functions.php to check if twitter json contains errors --- functions.php | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/functions.php b/functions.php index a1dd508..a31906a 100644 --- a/functions.php +++ b/functions.php @@ -200,20 +200,24 @@ function build_tweet($tweet, $user_template): string function display_tweet($template = '') { $json = json_decode(file_get_contents(get_template_directory() . '/cron/vwsg_web.json'), JSON_OBJECT_AS_ARRAY); - $tweet = $json[0]; + if (!array_key_exists('errors', $json)) { + $tweet = $json[0]; - echo build_tweet($tweet, $template); + echo build_tweet($tweet, $template); + } } function display_tweets($template = '') { $json = json_decode(file_get_contents(get_template_directory() . '/cron/vwsg_web.json'), JSON_OBJECT_AS_ARRAY); - foreach ($json as $i => $tweet) { - if ($i > 2) { - break; - } - echo build_tweet($tweet, $template); + if (!array_key_exists('errors', $json)) { + foreach ($json as $i => $tweet) { + if ($i > 2) { + break; + } + echo build_tweet($tweet, $template); + } } }