Пример #1
0
 function test_valid_phone_number()
 {
     $var['name'] = 'Phone';
     $value = array('123', '456', '7890');
     $phone = mailchimpSF_merge_validate_phone($value, $var);
     $this->assertFalse(is_wp_error($phone));
     $this->assertTrue(is_string($phone));
 }
Пример #2
0
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;
}