function test_invalid_address() { $var = array('tag' => 'ADDRESS', 'name' => 'Address', 'type' => 'Address', 'required' => 'Y'); $value = array('addr1' => '123 Magic Street'); $submit = mailchimpSF_merge_validate_address($value, $var); $this->assertTrue(is_wp_error($submit)); $this->assertTrue(is_object($submit)); }
function mailchimpSF_merge_submit($mv) { // Loop through our Merge Vars, and if they're empty, but required, then print an error, and mark as failed $merge = new stdClass(); foreach ($mv as $var) { // We also want to create an array where the keys are the tags for easier validation later $tag = $var['tag']; $mv_tag_keys[$tag] = $var; $opt = 'mc_mv_' . $tag; $opt_val = isset($_POST[$opt]) ? stripslashes_deep($_POST[$opt]) : ''; // Handle phone number logic if ($var['type'] === 'phone' && $var['options']['phone_format'] === 'US') { $opt_val = mailchimpSF_merge_validate_phone($opt_val, $var); if (is_wp_error($opt_val)) { return $opt_val; } } else { if (is_array($opt_val) && $var['type'] == 'address') { $validate = mailchimpSF_merge_validate_address($opt_val, $var); if (is_wp_error($validate)) { return $validate; } if ($validate) { $merge->{$tag} = $validate; } continue; } else { if (is_array($opt_val)) { $keys = array_keys($opt_val); $val = new stdClass(); foreach ($keys as $key) { $val->{$key} = $opt_val[$key]; } $opt_val = $val; } } } if ($var['required'] == 'Y' && trim($opt_val) == '') { $message = sprintf(__("You must fill in %s.", 'mailchimp_i18n'), esc_html($var['name'])); $error = new WP_Error('missing_required_field', $message); return $error; } else { if ($tag != 'EMAIL') { $merge->{$tag} = $opt_val; } } } return $merge; }