From 8281eac885d0696ab01db47c71df27a231fc85d4 Mon Sep 17 00:00:00 2001 From: Chi-Hsuan Huang Date: Wed, 26 Jan 2022 22:42:03 +0800 Subject: [PATCH] Fix Uncaught TypeError count(NULL) for php8+ in Marketing.php (https://github.com/woocommerce/woocommerce-admin/pull/8213) * Fix Uncaught TypeError count(NULL) for php8+ in Marketing.php * Add changelog --- .../changelogs/fix-8211-marketing-overview-type-error | 4 ++++ plugins/woocommerce-admin/src/Features/Marketing.php | 3 +-- 2 files changed, 5 insertions(+), 2 deletions(-) create mode 100644 plugins/woocommerce-admin/changelogs/fix-8211-marketing-overview-type-error diff --git a/plugins/woocommerce-admin/changelogs/fix-8211-marketing-overview-type-error b/plugins/woocommerce-admin/changelogs/fix-8211-marketing-overview-type-error new file mode 100644 index 00000000000..8544cd48e54 --- /dev/null +++ b/plugins/woocommerce-admin/changelogs/fix-8211-marketing-overview-type-error @@ -0,0 +1,4 @@ +Significance: patch +Type: Fix + +Fix Uncaught TypeError count(NULL) for php8+ in Marketing.php. #8213 diff --git a/plugins/woocommerce-admin/src/Features/Marketing.php b/plugins/woocommerce-admin/src/Features/Marketing.php index 1c70ed940db..f07d8e5250d 100644 --- a/plugins/woocommerce-admin/src/Features/Marketing.php +++ b/plugins/woocommerce-admin/src/Features/Marketing.php @@ -265,8 +265,7 @@ class Marketing { 'author_avatar' => isset( $raw_post['author_avatar_url'] ) ? $raw_post['author_avatar_url'] : '', ]; - $featured_media = $raw_post['_embedded']['wp:featuredmedia']; - + $featured_media = $raw_post['_embedded']['wp:featuredmedia'] ?? []; if ( count( $featured_media ) > 0 ) { $image = current( $featured_media ); $post['image'] = add_query_arg(