function usp_is_contact($form_id) { global $usp_admin; if (!empty($usp_admin['contact_form'])) { $contact_forms = rtrim(trim($usp_admin['contact_form']), ','); $contact_forms = explode(',', $contact_forms); if (in_array($form_id, $contact_forms)) { return true; } foreach ($contact_forms as $contact_form) { $contact_form = rtrim(trim($contact_form), ','); $contact_id = usp_get_form_id($contact_form); if ($form_id == $contact_id) { return true; } } } return false; }
function usp_custom_field($args) { $fieldset = usp_fieldset(); $fieldset_before = $fieldset['fieldset_before']; $fieldset_after = $fieldset['fieldset_after']; if (isset($args['id']) && !empty($args['id'])) { $id = $args['id']; } else { return __('error:usp_custom_field:1:', 'usp') . $args['id']; } if (isset($args['form']) && !empty($args['form'])) { $form = usp_get_form_id($args['form']); } else { return __('error:usp_custom_field:2:', 'usp') . $args['form']; } $custom_fields = get_post_custom($form); if (is_null($custom_fields) || empty($custom_fields)) { return __('error:usp_custom_field:3:', 'usp') . $custom_fields; } foreach ($custom_fields as $key => $value) { $key = trim($key); if ('_' == $key[0]) { continue; } if ($key !== '[usp_custom_field form="' . $args['form'] . '" id="' . $id . '"]') { continue; } $get_value = ''; if (isset($_COOKIE['remember'])) { if (preg_match("/name#([0-9a-z_-]+)/i", $value[0], $matches)) { if (isset($_SESSION['usp_form_session']['usp-custom-' . $matches[1]])) { $get_value = $_SESSION['usp_form_session']['usp-custom-' . $matches[1]]; } } elseif (isset($_SESSION['usp_form_session']['usp-custom-' . $id])) { $get_value = $_SESSION['usp_form_session']['usp-custom-' . $id]; } } if (preg_match("/usp_custom_field/i", $key)) { $default_atts = array('field' => 'input', 'type' => 'text', 'value' => $get_value, 'data-required' => 'true', 'placeholder' => 'Example Input ' . $id, 'class' => 'example-class-' . $id, 'label' => 'Example Label ' . $id, 'for' => $id, 'name' => $id, 'label_class' => 'example-class-' . $id, 'label_custom' => '', 'custom_1' => '', 'custom_2' => '', 'custom_3' => '', 'custom_4' => '', 'custom_5' => '', 'rows' => '3', 'cols' => '30', 'accept' => 'image/*', 'checked' => '', 'selected' => ''); $atts = explode("|", $value[0]); foreach ($atts as $att) { $a = explode("#", $att); // eg: $a[0] = field, $a[1] = input if ($a[0] == 'atts' && $a[1] == 'defaults') { continue; } // use defaults if (isset($a[0])) { $user_att_names[] = $a[0]; } if (isset($a[1])) { $user_att_values[] = $a[1]; } } if (!empty($user_att_names) && !empty($user_att_values)) { $user_atts = array_combine($user_att_names, $user_att_values); } else { $user_atts = $default_atts; } $field_atts = wp_parse_args($user_atts, $default_atts); if (isset($user_att_names)) { unset($user_att_names); } if (isset($user_att_values)) { unset($user_att_values); } $custom_att_names = array(); $custom_att_values = array(); foreach ($field_atts as $key => $value) { if (preg_match("/custom_/i", $key)) { $b = explode(":", $value); if (isset($b[0])) { $custom_att_names[] = $b[0]; } if (isset($b[1])) { $custom_att_values[] = $b[1]; } if (isset($field_atts[$key])) { unset($field_atts[$key]); } } } foreach ($custom_att_names as $key => $value) { if (is_null($value) || empty($value)) { unset($custom_att_names[$key]); } } foreach ($custom_att_values as $key => $value) { if (is_null($value) || empty($value)) { unset($custom_att_values[$key]); } } if (!empty($custom_att_names) && !empty($custom_att_values)) { $custom_atts = array_combine($custom_att_names, $custom_att_values); } else { $custom_atts = array(); } $field_atts = wp_parse_args($custom_atts, $field_atts); if (isset($custom_att_names)) { unset($custom_att_names); } if (isset($custom_att_values)) { unset($custom_att_values); } if ($field_atts) { if ($field_atts['data-required'] == 'true') { $field_hidden = '<input name="usp-custom-' . $field_atts['name'] . '-required" value="1" type="hidden" />'; $parsley = ' required="required"'; } else { $field_hidden = ''; $parsley = ''; } if (isset($field_atts['data-richtext']) && $field_atts['data-richtext'] == 'true') { $settings = array('wpautop' => true, 'media_buttons' => true, 'textarea_name' => 'usp-custom-' . $field_atts['name'], 'textarea_rows' => $field_atts['rows'], 'tabindex' => '', 'editor_css' => '', 'editor_class' => $field_atts['class'], 'teeny' => false, 'dfw' => false, 'tinymce' => true, 'quicktags' => true); ob_start(); // until get_wp_editor() is available.. wp_editor($field_atts['value'], 'uspcustom', $settings); $get_wp_editor = ob_get_clean(); if (!empty($get_wp_editor)) { return $fieldset_before . $get_wp_editor . $field_hidden . $fieldset_after; } } if (!empty($field_atts['checked'])) { $checked = ' checked="checked"'; } else { $checked = ''; } if (!empty($field_atts['selected'])) { $selected = ' selected="selected"'; } else { $selected = ''; } $error = ''; wp_parse_str(wp_strip_all_tags($_SERVER['QUERY_STRING']), $vars); if ($vars) { foreach ($vars as $var) { if (preg_match("/^usp_error_custom_([0-9a-z_-]+)\$/i", $var, $match)) { if ($match[1] == $id) { $error = 'usp-error-field usp-error-custom '; } } elseif (preg_match("/^usp_error_([a-g]+)\$/i", $var, $match)) { $user_fields = array('a' => 'nicename', 'b' => 'displayname', 'c' => 'nickname', 'd' => 'firstname', 'e' => 'lastname', 'f' => 'description', 'g' => 'password'); foreach ($user_fields as $key => $value) { if ($field_atts['name'] == $value && $match[1] == $key) { $error = 'usp-error-field usp-error-register '; } } } } } switch ($field_atts['field']) { case 'input': if ($field_atts['type'] == 'file' && !empty($field_atts['accept'])) { $accept = 'accept="' . $field_atts['accept'] . '" '; } else { $accept = ''; } $field_start = '<input ' . $accept . 'name="usp-custom-' . $field_atts['name'] . '" '; $field_end = 'class="' . $error . $field_atts['class'] . ' usp-input usp-input-custom usp-form-' . $form . '"' . $checked . $selected . $parsley . ' />' . "\n" . $field_hidden; $label_class = 'class="' . $field_atts['label_class'] . ' usp-label usp-label-input usp-label-custom usp-form-' . $form; break; case 'textarea': $field_start = '<textarea name="usp-custom-' . $field_atts['name'] . '" '; $field_end = 'class="' . $error . $field_atts['class'] . ' usp-input usp-textarea usp-textarea-custom usp-form-' . $form . '" rows="' . $field_atts['rows'] . '" cols="' . $field_atts['cols'] . '"' . $parsley . '>' . $field_atts['value'] . '</textarea>' . "\n" . $field_hidden; $label_class = 'class="' . $field_atts['label_class'] . ' usp-label usp-label-textarea usp-label-custom usp-form-' . $form; break; default: return __('error:usp_custom_field:4:', 'usp') . $field_atts['field']; break; } $label_for = 'usp-custom-' . $field_atts['for']; $label_custom = $field_atts['label_custom']; $label = $field_atts['label']; $label_start = '<label for="' . $label_for . '" ' . $label_class . '" ' . $label_custom; $label_end = '>' . $label . '</label>'; if ($field_atts['label'] == 'null') { $label = ''; } else { $label = trim($label_start) . trim($label_end) . "\n"; } unset($field_atts['field'], $field_atts['accept'], $field_atts['name'], $field_atts['checked'], $field_atts['selected'], $field_atts['class'], $field_atts['label_class'], $field_atts['rows'], $field_atts['cols']); unset($field_atts['for'], $field_atts['label_custom'], $field_atts['label']); $attributes = ''; $content_start = $label . $field_start; $content_end = $field_end; foreach ($field_atts as $att_name => $att_value) { $attributes .= $att_name . '="' . $att_value . '" '; } $content = $content_start . $attributes . $content_end; return $fieldset_before . $content . $fieldset_after; } else { return __('error:usp_custom_field:5:', 'usp') . $field_atts; } } } }
function usp_custom_field($args) { global $usp_advanced; if (isset($args['id']) && !empty($args['id'])) { $id = $args['id']; } else { return __('error:usp_custom_field:1:', 'usp') . $args['id']; } if (isset($args['form']) && !empty($args['form'])) { $form = usp_get_form_id($args['form']); } else { return __('error:usp_custom_field:2:', 'usp') . $args['form']; } $custom_fields = get_post_custom($form); if (is_null($custom_fields) || empty($custom_fields)) { return __('error:usp_custom_field:3:', 'usp') . $custom_fields; } $custom_merged = usp_merge_custom_fields(); $custom_arrays = usp_custom_field_string_to_array(); $custom_prefix = $usp_advanced['custom_prefix']; if (empty($custom_prefix)) { $custom_prefix = 'prefix_'; } foreach ($custom_fields as $key => $value) { $key = trim($key); if ('_' == $key[0]) { continue; } if ($key !== '[usp_custom_field form="' . $args['form'] . '" id="' . $id . '"]') { continue; } if (preg_match("/usp_custom_field/i", $key)) { $atts = explode("|", $value[0]); $get_value = $this->usp_custom_field_cookies($id, $value); $default_atts = $this->usp_custom_field_defaults($id, $get_value); $field_atts = $this->usp_custom_field_atts($atts, $default_atts); if (empty($field_atts)) { return __('error:usp_custom_field:4:', 'usp') . $field_atts; } $fieldset = usp_fieldset_custom($field_atts['fieldset'], $field_atts['field_class']); if (in_array($field_atts['name'], $custom_merged) || preg_match("/^{$custom_prefix}/i", $field_atts['name'])) { $prefix = ''; } else { $prefix = 'usp-custom-'; } $checked = ''; $selected = ''; $class = ''; $class_label = ''; $label_custom = ''; if (!empty($field_atts['checked'])) { $checked = ' checked="checked"'; } if (!empty($field_atts['selected'])) { $selected = ' selected="selected"'; } if (!empty($field_atts['class'])) { $class = $field_atts['class'] . ' '; } if (!empty($field_atts['label_class'])) { $class_label = $field_atts['label_class'] . ' '; } if (!empty($field_atts['label_custom'])) { $label_custom = ' ' . $field_atts['label_custom']; } $multiple = ''; $select_array = ''; $multiple_enable = array('multiple', 'true', 'yes', 'on'); if (in_array($field_atts['multiple'], $multiple_enable)) { $multiple = ' multiple="multiple"'; $select_array = '[]'; } if (in_array($field_atts['name'], $custom_arrays['required'])) { $field_atts['data-required'] = 'true'; } elseif (in_array($field_atts['name'], $custom_arrays['optional'])) { $field_atts['data-required'] = 'false'; } $field_hidden = ''; $parsley = ''; if ($field_atts['data-required'] == 'true') { if (!empty($field_atts['checkboxes']) && empty($multiple)) { unset($field_atts['data-required']); } else { if ($field_atts['field'] !== 'input_file') { $field_hidden = '<input name="' . $prefix . $field_atts['name'] . '-required" value="1" type="hidden" />' . "\n"; } } $parsley = ' required="required"'; } else { if ($field_atts['data-required'] == 'null') { unset($field_atts['data-required']); } } $get_wp_editor = $this->usp_custom_field_wp_editor($field_atts); if (!empty($get_wp_editor)) { return $fieldset['fieldset_before'] . $get_wp_editor . $field_hidden . $fieldset['fieldset_after']; } $error = $this->usp_custom_field_errors($id, $field_atts, $custom_prefix); $checkboxes = $this->usp_custom_fields_checkboxes($field_atts, $prefix, $select_array); $radio = $this->usp_custom_fields_radio($field_atts, $prefix); $options = $this->usp_custom_fields_select($field_atts); $files = $this->usp_custom_fields_files($field_atts, $prefix, $class_label, $label_custom); // switch ($field_atts['field']) { case 'input': $field_start = '<input name="' . $prefix . $field_atts['name'] . '" '; $field_end = 'class="' . $error . $class . 'usp-input usp-input-custom usp-form-' . $form . '"' . $checked . $selected . $parsley . ' />'; $label_class = 'class="' . $class_label . 'usp-label usp-label-input usp-label-custom usp-form-' . $form; break; case 'textarea': $field_start = '<textarea name="' . $prefix . $field_atts['name'] . '" '; $field_end = 'class="' . $error . $class . 'usp-input usp-textarea usp-form-' . $form . '" rows="' . $field_atts['rows'] . '" cols="' . $field_atts['cols'] . '"' . $parsley . '>' . $field_atts['value'] . '</textarea>'; $label_class = 'class="' . $class_label . 'usp-label usp-label-textarea usp-label-custom usp-form-' . $form; unset($field_atts['type']); break; case 'select': $field_start = '<select name="' . $prefix . $field_atts['name'] . $select_array . '" '; $field_end = 'class="' . $error . $class . 'usp-input usp-select usp-form-' . $form . '"' . $parsley . $multiple . '>' . $options . '</select>'; $label_class = 'class="' . $class_label . 'usp-label usp-label-select usp-label-custom usp-form-' . $form; unset($field_atts['type'], $field_atts['value'], $field_atts['multiple'], $field_atts['placeholder']); break; case 'input_checkbox': $field_start = '<div class="' . $error . $class . 'usp-input usp-checkboxes usp-form-' . $form . '">'; $field_end = $checkboxes . '</div>'; $label_class = ''; unset($field_atts['type'], $field_atts['value'], $field_atts['multiple'], $field_atts['placeholder'], $field_atts['data-required']); break; case 'input_radio': $field_start = '<div class="' . $error . $class . 'usp-input usp-radio usp-form-' . $form . '">'; $field_end = $radio . '</div>'; $label_class = ''; unset($field_atts['type'], $field_atts['value'], $field_atts['placeholder'], $field_atts['data-required']); break; case 'input_file': $field_start = '<div id="' . $prefix . $field_atts['name'] . '-files" class="' . $error . $class . 'usp-files">' . $files['start']; $field_end = $files['end'] . '</div>' . "\n" . '<div class="usp-preview"></div>'; $label_class = ''; unset($field_atts['type'], $field_atts['value']); break; default: return __('error:usp_custom_field:5:', 'usp') . $field_atts['field']; break; } // if ($field_atts['field'] == 'input_checkbox' || $field_atts['field'] == 'input_radio' || $field_atts['field'] == 'input_file') { $label = ''; } else { $label = '<label for="' . $prefix . $field_atts['for'] . $select_array . '" ' . $label_class . '"' . $label_custom . '>' . $field_atts['label'] . '</label>' . "\n"; } if (isset($field_atts['label']) && $field_atts['label'] == 'null') { $label = ''; } if (isset($field_atts['placeholder']) && $field_atts['placeholder'] == 'null') { unset($field_atts['placeholder']); } $field_atts = $this->usp_custom_field_unset($field_atts); $attributes = ''; foreach ($field_atts as $att_name => $att_value) { $attributes .= $att_name . '="' . $att_value . '" '; } $content = $label . $field_start . $attributes . $field_end . "\n" . $field_hidden; $return = $fieldset['fieldset_before'] . $content . $fieldset['fieldset_after']; return apply_filters('usp_custom_field_data', $return); } } }