Skip to content

When the PHONE field in a Mailchimp account is set to US style and NOT included a form submission in WP will trigger a fatal PHP error #103

@MaxwellGarceau

Description

@MaxwellGarceau

Describe the bug

The following conditions cause a PHP fatal error on form submission

  • Phone number is set to US style in the Mailchimp account
  • Phone number is NOT included as a merge field in the WP plugin

Explanation

I haven't investigated, but I suspect that mailchimp_sf_merge_validate_phone is activating because the Phone Number merge field is set to US style, but since that field is not included the function is receiving invalid input.

The solution is most likely as simple as adding a conditional check for the input the function needs. In addition, instead of a fatal error being thrown there should at worst be a failed validation check.

PHP Error Log

Fatal error: Uncaught TypeError: array_filter(): Argument #1 ($array) must be of type array, string given in /var/www/html/wp-content/plugins/wordpress/mailchimp.php:1053
Stack trace: 
#0 /var/www/html/wp-content/plugins/wordpress/mailchimp.php(1053): array_filter('')
#1 /var/www/html/wp-content/plugins/wordpress/mailchimp.php(1008): mailchimp_sf_merge_validate_phone('', Array)
#2 /var/www/html/wp-content/plugins/wordpress/mailchimp.php(854): mailchimp_sf_merge_submit(Array)
#3 /var/www/html/wp-content/plugins/wordpress/mailchimp.php(245): mailchimp_sf_signup_submit()
#4 /var/www/html/wp-includes/class-wp-hook.php(324): mailchimp_sf_request_handler('')
#5 /var/www/html/wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters(NULL, Array)
#6 /var/www/html/wp-includes/plugin.php(517): WP_Hook->do_action(Array)
#7 /var/www/html/wp-settings.php(704): do_action('init')
#8 /var/www/html/wp-config.php(151): require_once('/var/www/html/w...')
#9 /var/www/html/wp-load.php(50): require_once('/var/www/html/w...')
#10 /var/www/html/wp-blog-header.php(13): require_once('/var/www/html/w...')
#11 /var/www/html/index.php(17): require('/var/www/html/w...')
#12 {main} 
thrown in /var/www/html/wp-content/plugins/wordpress/mailchimp.php on line 1053

Steps to Reproduce

  1. Set the phone format in the test Mailchimp account (/lists/settings/merge-tags) to US style
  2. Select the "Update List" button to refresh the Mailchimp data with WP
  3. Ensure that Phone Number is not an included merge field. The error will only occur when Phone Number is not included in the form.
  4. Submit a form submission using only email (any merge field is okay and the error should occur regardless)
  5. You will see the fatal PHP error

Screenshots, screen recording, code snippet

us-phone-fatal-error-when-merge-field-not-included.mov

Environment information

No response

WordPress information

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct

Metadata

Metadata

Labels

type:bugSomething isn't working.

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions