woocommerce / woocommerce-admin

(Deprecated) This plugin has been merged to woocommerce/woocommerce
https://woocommerce.github.io/woocommerce-admin/#/
Other
360 stars 145 forks source link

Marketing: Error triggered when viewing the overview page #8211

Closed joashrajin closed 2 years ago

joashrajin commented 2 years ago

Prerequisites

Describe the bug

I have multiple sites using PHP 8+ which trigger this error when opening the Marketing > Overview Page. The error is:

2022-01-24T12:55:45+00:00 CRITICAL Uncaught TypeError: count(): Argument woocommerce/woocommerce#1 ($value) must be of type Countable|array, null given in /Users/test/Local Sites/woo/app/public/wp-content/plugins/woocommerce/packages/woocommerce-admin/src/Features/Marketing.php:270
Stack trace:
#0 /Users/test/Local Sites/woo/app/public/wp-content/plugins/woocommerce/packages/woocommerce-admin/src/Features/Marketing.php(270): count(NULL)
woocommerce/woocommerce#1 /Users/test/Local Sites/woo/app/public/wp-content/plugins/woocommerce/packages/woocommerce-admin/src/API/Marketing.php(118): Automattic\WooCommerce\Admin\Features\Marketing->get_knowledge_base_posts('marketing')
woocommerce/woocommerce#2 /Users/test/Local Sites/woo/app/public/wp-includes/rest-api/class-wp-rest-server.php(1140): Automattic\WooCommerce\Admin\API\Marketing->get_knowledge_base_posts(Object(WP_REST_Request))
woocommerce/woocommerce#3 /Users/test/Local Sites/woo/app/public/wp-includes/rest-api/class-wp-rest-server.php(987): WP_REST_Server->respond_to_request(Object(WP_REST_Request), '/wc-admin/marke...', Array, NULL)
woocommerce/woocommerce#4 /Users/test/Local Sites/woo/app/public/wp-includes/rest-api/class-wp-rest-server.php(414): WP_REST_Server->dispatch(Object(WP_REST_Request))
woocommerce/woocommerce#5 /Users/test/Local Sites/woo/app/public/wp-includes/rest-api.php(370): WP_REST_Server->serve_request('/wc-admin/marke...')
woocommerce/woocommerce#6 /Users/test/Local Sites/woo/app/public/wp-includes/class-wp-hook.php(303): rest_api_loaded(Object(WP))
woocommerce/woocommerce#7 /Users/test/Local Sites/woo/app/public/wp-includes/class-wp-hook.php(327): WP_Hook->apply_filters(NULL, Array)
woocommerce/woocommerce#8 /Users/test/Local Sites/woo/app/public/wp-includes/plugin.php(518): WP_Hook->do_action(Array)
woocommerce/woocommerce#9 /Users/test/Local Sites/woo/app/public/wp-includes/class-wp.php(388): do_action_ref_array('parse_request', Array)
woocommerce/woocommerce#10 /Users/test/Local Sites/woo/app/public/wp-includes/class-wp.php(750): WP->parse_request('')
woocommerce/woocommerce#11 /Users/test/Local Sites/woo/app/public/wp-includes/functions.php(1291): WP->main('')
woocommerce/woocommerce#12 /Users/test/Local Sites/woo/app/public/wp-blog-header.php(16): wp()
woocommerce/woocommerce#13 /Users/test/Local Sites/woo/app/public/index.php(17): require('/Users/test...')
woocommerce/woocommerce#14 {main}
  thrown in /Users/test/Local Sites/woo/app/public/wp-content/plugins/woocommerce/packages/woocommerce-admin/src/Features/Marketing.php on line 270

Expected behavior

There should not be an error triggered

Actual behavior

A Critical Error is triggered

Steps to reproduce

  1. Go to Marketing > Overview
  2. View your Error Logs and you should notice this error

WordPress Environment

### WordPress Environment ###

WordPress address (URL): http://woo.local
Site address (URL): http://woo.local
WC Version: 6.1.1
REST API Version: ✔ 6.1.1
WC Blocks Version: ✔ 6.5.2
Action Scheduler Version: ✔ 3.4.0
WC Admin Version: ✔ 3.0.3
Log Directory Writable: ✔
WP Version: 5.8.3
WP Multisite: –
WP Memory Limit: 256 MB
WP Debug Mode: –
WP Cron: ✔
Language: en_US
External object cache: –

### Server Environment ###

Server Info: nginx/1.16.0
PHP Version: 8.0.0
PHP Post Max Size: 1,000 MB
PHP Time Limit: 1200
PHP Max Input Vars: 4000
cURL Version: 7.54.0
LibreSSL/2.6.5

SUHOSIN Installed: –
MySQL Version: 8.0.16
Max Upload Size: 300 MB
Default Timezone is UTC: ✔
fsockopen/cURL: ✔
SoapClient: ✔
DOMDocument: ✔
GZip: ✔
Multibyte String: ✔
Remote Post: ✔
Remote Get: ✔

### Database ###

WC Database Version: 6.1.1
WC Database Prefix: wp_
Total Database Size: 15.32MB
Database Data Size: 11.53MB
Database Index Size: 3.79MB
wp_woocommerce_sessions: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
wp_woocommerce_api_keys: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
wp_woocommerce_attribute_taxonomies: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
wp_woocommerce_downloadable_product_permissions: Data: 0.02MB + Index: 0.06MB + Engine InnoDB
wp_woocommerce_order_items: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
wp_woocommerce_order_itemmeta: Data: 0.05MB + Index: 0.03MB + Engine InnoDB
wp_woocommerce_tax_rates: Data: 0.02MB + Index: 0.06MB + Engine InnoDB
wp_woocommerce_tax_rate_locations: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
wp_woocommerce_shipping_zones: Data: 0.02MB + Index: 0.00MB + Engine InnoDB
wp_woocommerce_shipping_zone_locations: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
wp_woocommerce_shipping_zone_methods: Data: 0.02MB + Index: 0.00MB + Engine InnoDB
wp_woocommerce_payment_tokens: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
wp_woocommerce_payment_tokenmeta: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
wp_woocommerce_log: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
wp_actionscheduler_actions: Data: 0.02MB + Index: 0.13MB + Engine InnoDB
wp_actionscheduler_claims: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
wp_actionscheduler_groups: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
wp_actionscheduler_logs: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
wp_commentmeta: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
wp_comments: Data: 0.06MB + Index: 0.09MB + Engine InnoDB
wp_gla_budget_recommendations: Data: 0.22MB + Index: 0.14MB + Engine InnoDB
wp_gla_merchant_issues: Data: 0.02MB + Index: 0.00MB + Engine InnoDB
wp_gla_shipping_rates: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
wp_gla_shipping_times: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
wp_links: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
wp_mailchimp_carts: Data: 0.02MB + Index: 0.00MB + Engine InnoDB
wp_mailchimp_jobs: Data: 0.02MB + Index: 0.00MB + Engine InnoDB
wp_mailpoet_custom_fields: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
wp_mailpoet_dynamic_segment_filters: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
wp_mailpoet_feature_flags: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
wp_mailpoet_forms: Data: 0.02MB + Index: 0.00MB + Engine InnoDB
wp_mailpoet_log: Data: 0.02MB + Index: 0.00MB + Engine InnoDB
wp_mailpoet_mapping_to_external_entities: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
wp_mailpoet_newsletter_links: Data: 0.02MB + Index: 0.05MB + Engine InnoDB
wp_mailpoet_newsletter_option: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
wp_mailpoet_newsletter_option_fields: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
wp_mailpoet_newsletter_posts: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
wp_mailpoet_newsletter_segment: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
wp_mailpoet_newsletter_templates: Data: 2.52MB + Index: 0.00MB + Engine InnoDB
wp_mailpoet_newsletters: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
wp_mailpoet_scheduled_task_subscribers: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
wp_mailpoet_scheduled_tasks: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
wp_mailpoet_segments: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
wp_mailpoet_sending_queues: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
wp_mailpoet_settings: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
wp_mailpoet_statistics_clicks: Data: 0.02MB + Index: 0.05MB + Engine InnoDB
wp_mailpoet_statistics_forms: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
wp_mailpoet_statistics_newsletters: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
wp_mailpoet_statistics_opens: Data: 0.02MB + Index: 0.08MB + Engine InnoDB
wp_mailpoet_statistics_unsubscribes: Data: 0.02MB + Index: 0.05MB + Engine InnoDB
wp_mailpoet_statistics_woocommerce_purchases: Data: 0.02MB + Index: 0.06MB + Engine InnoDB
wp_mailpoet_stats_notifications: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
wp_mailpoet_subscriber_custom_field: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
wp_mailpoet_subscriber_ips: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
wp_mailpoet_subscriber_segment: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
wp_mailpoet_subscribers: Data: 0.02MB + Index: 0.13MB + Engine InnoDB
wp_mailpoet_user_agents: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
wp_mailpoet_user_flags: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
wp_options: Data: 6.06MB + Index: 0.06MB + Engine InnoDB
wp_postmeta: Data: 0.47MB + Index: 0.47MB + Engine InnoDB
wp_posts: Data: 0.14MB + Index: 0.06MB + Engine InnoDB
wp_snippets: Data: 0.02MB + Index: 0.00MB + Engine InnoDB
wp_term_relationships: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
wp_term_taxonomy: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
wp_termmeta: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
wp_terms: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
wp_usermeta: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
wp_users: Data: 0.02MB + Index: 0.05MB + Engine InnoDB
wp_wc_admin_note_actions: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
wp_wc_admin_notes: Data: 0.06MB + Index: 0.00MB + Engine InnoDB
wp_wc_booking_relationships: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
wp_wc_bookings_availability: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
wp_wc_bookings_availabilitymeta: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
wp_wc_category_lookup: Data: 0.02MB + Index: 0.00MB + Engine InnoDB
wp_wc_customer_lookup: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
wp_wc_download_log: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
wp_wc_order_bundle_lookup: Data: 0.02MB + Index: 0.09MB + Engine InnoDB
wp_wc_order_coupon_lookup: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
wp_wc_order_product_lookup: Data: 0.02MB + Index: 0.06MB + Engine InnoDB
wp_wc_order_stats: Data: 0.02MB + Index: 0.05MB + Engine InnoDB
wp_wc_order_tax_lookup: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
wp_wc_product_meta_lookup: Data: 0.02MB + Index: 0.09MB + Engine InnoDB
wp_wc_rate_limits: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
wp_wc_reserved_stock: Data: 0.02MB + Index: 0.00MB + Engine InnoDB
wp_wc_tax_rate_classes: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
wp_wc_webhooks: Data: 0.02MB + Index: 0.02MB + Engine InnoDB
wp_woocommerce_bundled_itemmeta: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
wp_woocommerce_bundled_items: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
wp_wsf_field: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
wp_wsf_field_meta: Data: 0.05MB + Index: 0.03MB + Engine InnoDB
wp_wsf_form: Data: 0.08MB + Index: 0.13MB + Engine InnoDB
wp_wsf_form_meta: Data: 0.06MB + Index: 0.03MB + Engine InnoDB
wp_wsf_form_stat: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
wp_wsf_group: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
wp_wsf_group_meta: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
wp_wsf_section: Data: 0.02MB + Index: 0.05MB + Engine InnoDB
wp_wsf_section_meta: Data: 0.02MB + Index: 0.03MB + Engine InnoDB
wp_wsf_submit: Data: 0.02MB + Index: 0.11MB + Engine InnoDB
wp_wsf_submit_meta: Data: 0.02MB + Index: 0.05MB + Engine InnoDB

### Post Type Counts ###

attachment: 26
custom_css: 1
mailpoet_page: 1
nav_menu_item: 5
page: 10
post: 2
product: 25
product_variation: 9
revision: 16
shop_coupon: 1
shop_order: 112
wc_booking: 6
wc_order_status: 7
wcpf_item: 4
wcpf_project: 1
yay-currency-manage: 2

### Security ###

Secure connection (HTTPS): ❌
                    Your store is not using HTTPS. Learn more about HTTPS and SSL Certificates.
Hide errors from visitors: ✔

### Active Plugins (1) ###

WooCommerce: by Automattic – 6.1.1

### Inactive Plugins (29) ###

All-in-One WP Migration: by ServMask – 7.53
Bookings Helper: by WooCommerce – 1.0.3
Classic Widgets: by WordPress Contributors – 0.2
Code Snippets: by Code Snippets Pro – 2.14.3
ExS Optimizations for Theme: by ExS – 0.0.1
ExS Widgets: by ExS – 0.3.0
Google Listings and Ads: by WooCommerce – 1.10.0
Health Check & Troubleshooting: by The WordPress.org community – 1.4.5
Jetpack: by Automattic – 10.5
Loco Translate: by Tim Whitlock – 2.5.7
Mailchimp for WooCommerce: by Mailchimp – 2.5.4
MailPoet 3 (New): by MailPoet – 3.77.1
Product Filters for WooCommerce: by WooCommerce – 1.2.5
Query Monitor: by John Blackbourn – 3.8.2
WooCommerce Blocks: by Automattic – 6.8.0
WooCommerce Bookings: by WooCommerce – 1.15.48
WooCommerce EU VAT Number: by WooCommerce – 2.4.1
WooCommerce Multi-currency: by TIV.NET INC – 2.14.3
WooCommerce Order Status Manager: by SkyVerge – 1.13.3
WooCommerce Payments: by Automattic – 3.6.0
WooCommerce Product Add-ons: by WooCommerce – 4.4.0
WooCommerce Product Bundles: by SomewhereWarm – 6.12.7
WooCommerce Stripe Gateway: by WooCommerce – 6.0.0
WooCommerce Subscriptions: by WooCommerce – 4.0.0
WooCommerce WS Form PRO Product Add-Ons: by Westguard Solutions – 1.1.54
WordPress Importer: by wordpressdotorg – 0.7
WP Debugging: by Andy Fragen – 2.11.7
WS Form PRO: by WS Form – 1.8.112
YayCurrency Pro: by YayCommerce – 1.6.6

### Must Use Plugins (1) ###

Health Check Troubleshooting Mode: by  – 1.7.2

### Settings ###

API Enabled: –
Force SSL: ✔
Currency: USD ($)
Currency Position: left
Thousand Separator: ,
Decimal Separator: .
Number of Decimals: 2
Taxonomies: Product Types: booking (booking)
bundle (bundle)
external (external)
grouped (grouped)
simple (simple)
subscription (subscription)
variable (variable)
variable subscription (variable-subscription)

Taxonomies: Product Visibility: exclude-from-catalog (exclude-from-catalog)
exclude-from-search (exclude-from-search)
featured (featured)
outofstock (outofstock)
rated-1 (rated-1)
rated-2 (rated-2)
rated-3 (rated-3)
rated-4 (rated-4)
rated-5 (rated-5)

Connected to WooCommerce.com: –

### WC Pages ###

Shop base: woocommerce/woocommerce#6 - /shop/
Cart: woocommerce/woocommerce#7 - /cart/
Checkout: woocommerce/woocommerce#8 - /checkout/
My account: woocommerce/woocommerce#9 - /my-account/
Terms and conditions: ❌ Page not set

### Theme ###

Name: Storefront
Version: 3.9.1
Author URL: https://woocommerce.com/
Child Theme: ❌ – If you are modifying WooCommerce on a parent theme that you did not build personally we recommend using a child theme. See: How to create a child theme
WooCommerce Support: ✔

### Templates ###

Overrides: –

### Action Scheduler ###

Complete: 23
Oldest: 2022-01-08 06:27:50 +0000
Newest: 2022-01-24 12:56:57 +0000

Pending: 1
Oldest: 2022-02-07 06:27:50 +0000
Newest: 2022-02-07 06:27:50 +0000

### Status report information ###

Generated at: 2022-01-24 12:58:24 +00:00

Isolating the problem

ObliviousHarmony commented 2 years ago

Hi @joashrajin,

Thank you for reporting the issue. The marketing page is being developed in another repository: woocommerce/woocommerce-admin

I am going to move your bug report there so that the right team could take a look further.

chihsuan commented 2 years ago

Hi, @joashrajin Thank you for reporting the issue. I was able to reproduce this bug and confirmed "WooCommerce knowledge base" can't load the data properly.

Screen Shot 2022-01-25 at 10 59 52

Looks like count(NULL) is a warning in PHP 7 but becomes a fatal error in PHP 8+. I think we can add a null check to fix this.

https://github.com/woocommerce/woocommerce-admin/blob/1d0a3cdd8fe048754f0bf02feef33e8f4cd42b83/src/Features/Marketing.php#L270

We'll work on it as soon as possible.