PHP notice: “Undefined index: phone_format” in Mailchimp plugin
-
I don’t know exactly the situation to replicate it, but my logs are full of this pointless error:
PHP notice: "Undefined index: phone_format" file: rising_live/wp-content/plugins/mailchimp/mailchimp.php:861
The code makes it clear why:
if ($var['type'] === 'phone' && $var['options']['phone_format'] === 'US') {
Nothing above that does any checking for
$var['options']['phone_format']
or$var['options']['phone_format']
, and clearly, sometimes it’s not there (which seems to be ok except that it generates the warning).Solution: Do an
isset($var['options']['phone_format'])
if ($var['type'] === 'phone' && isset($var['options']['phone_format']) && $var['options']['phone_format'] === 'US') {
This is an ugly solution, but solves the problem. If you want to make it cleaner than that, there’s lots of ways you could do it.
If anyone ever makes another version of this plugin, please fix this. After 3 years with no updates, I’m not holding my breath. I’m mostly creating this ticket so I have something to link to in the changelog of my forked version of this plugin ˉ\_(ツ)_/ˉ
May all beings live at ease, free from PHP Warnings.
- The topic ‘PHP notice: “Undefined index: phone_format” in Mailchimp plugin’ is closed to new replies.