PluginProbe
weForms – Easy Drag & Drop Contact Form Builder For WordPress / 1.4.9
weForms – Easy Drag & Drop Contact Form Builder For WordPress v1.4.9
1.6.7 1.6.8 1.6.9 1.6.12 1.6.13 1.6.14 1.6.15 1.6.16 1.6.17 1.6.18 1.6.19 1.6.2 1.6.20 1.6.21 1.6.22 1.6.23 1.6.24 1.6.25 1.6.26 1.6.27 1.6.28 1.6.3 1.6.4 1.6.5 1.6.6 All 74 releases
← All changes | includes/fields/class-field-email.php +135 -137 1.6.131.4.9 View file →
@@ -1,137 +1,135 @@
1 -<?php
2 -
3 -/**
4 - * Text Field Class
5 - */
6 -class WeForms_Form_Field_Email extends WeForms_Form_Field_Text {
7 -
8 - public function __construct() {
9 - $this->name = __( 'Email Address', 'weforms' );
10 - $this->input_type = 'email_address';
11 - $this->icon = 'envelope-o';
12 - }
13 -
14 - /**
15 - * Render the text field
16 - *
17 - * @param array $field_settings
18 - * @param int $form_id
19 - *
20 - * @return void
21 - */
22 - public function render( $field_settings, $form_id ) {
23 -
24 - // let's not show the email field if user choose to auto populate for logged users
25 - if ( isset( $field_settings['auto_populate'] ) && $field_settings['auto_populate'] == 'yes' && is_user_logged_in() ) {
26 - return;
27 - }
28 - $form_settings = weforms()->form->get( $form_id )->get_settings();
29 - $use_theme_css = isset( $form_settings['use_theme_css'] ) ? $form_settings['use_theme_css'] : 'wpuf-style';
30 - $value = $field_settings['default']; ?>
31 - <li <?php $this->print_list_attributes( $field_settings ); ?>>
32 - <?php $this->print_label( $field_settings, $form_id ); ?>
33 -
34 - <div class="wpuf-fields">
35 - <input
36 - id="<?php echo esc_attr( $field_settings['name'] ) . '_' . esc_attr( $form_id ); ?>"
37 - type="email"
38 - class="email <?php echo ' wpuf_'. esc_attr( $field_settings['name'] ).'_'. esc_attr( $form_id ); ?>"
39 - data-duplicate="<?php echo isset( $field_settings['duplicate'] ) ? esc_attr( $field_settings['duplicate'] ) : 'no'; ?>"
40 - data-required="<?php echo esc_attr( $field_settings['required'] ) ?>"
41 - data-type="email"
42 - data-style="<?php echo esc_attr( $use_theme_css ); ?>"
43 - name="<?php echo esc_attr( $field_settings['name'] ); ?>"
44 - placeholder="<?php echo esc_attr( $field_settings['placeholder'] ); ?>"
45 - value="<?php echo esc_attr( $value ); ?>"
46 - size="<?php echo esc_attr( $field_settings['size'] ); ?>"
47 - autocomplete="email"
48 - />
49 - <?php $this->help_text( $field_settings ); ?>
50 - </div>
51 - </li>
52 - <?php
53 - }
54 -
55 - /**
56 - * Get field options setting
57 - *
58 - * @return array
59 - */
60 - public function get_options_settings() {
61 - $default_options = $this->get_default_option_settings();
62 - $default_text_options = $this->get_default_text_option_settings();
63 - $check_duplicate = [
64 - [
65 - 'name' => 'duplicate',
66 - 'title' => 'No Duplicates',
67 - 'type' => 'checkbox',
68 - 'is_single_opt' => true,
69 - 'options' => [
70 - 'no' => __( 'Unique Values Only', 'weforms' ),
71 - ],
72 - 'default' => '',
73 - 'section' => 'advanced',
74 - 'priority' => 23,
75 - 'help_text' => __( 'Select this option to limit user input to unique values only. This will require that a value entered in a field does not currently exist in the entry database for that field.', 'weforms' ),
76 - ],
77 - [
78 - 'name' => 'auto_populate',
79 - 'title' => 'Auto-populate email for logged users',
80 - 'type' => 'checkbox',
81 - 'is_single_opt' => true,
82 - 'options' => [
83 - 'yes' => __( 'Auto-populate Email', 'weforms' ),
84 - ],
85 - 'default' => '',
86 - 'section' => 'advanced',
87 - 'priority' => 23,
88 - 'help_text' => __( 'If a user is logged into the site, this email field will be auto-populated with his email. And form\'s email field will be hidden.', 'weforms' ),
89 - ],
90 - ];
91 -
92 - return array_merge( $default_options, $default_text_options, $check_duplicate );
93 - }
94 -
95 - /**
96 - * Prepare entry default, can be replaced through field classes
97 - *
98 - * @param $field
99 - *
100 - * @return mixed
101 - */
102 - public function prepare_entry( $field, $args = [] ) {
103 - if( empty( $_POST['_wpnonce'])) {
104 - wp_send_json_error( __( 'Unauthorized operation', 'weforms' ) );
105 - }
106 -
107 - if ( ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['_wpnonce'] ) ), 'wpuf_form_add' ) ) {
108 - wp_send_json_error( __( 'Unauthorized operation', 'weforms' ) );
109 - }
110 -
111 - $args = ! empty( $args ) ? $args : weforms_clean( $_POST );
112 -
113 - if ( isset( $field['auto_populate'] ) && $field['auto_populate'] == 'yes' && is_user_logged_in() ) {
114 - $user = wp_get_current_user();
115 -
116 - if ( !empty( $user->user_email ) ) {
117 - return $user->user_email;
118 - }
119 - }
120 -
121 - $value = !empty( $args[ $field[ 'name' ] ] ) ? $args[ $field[ 'name' ] ] : '';
122 -
123 - return sanitize_text_field( trim( $value ) );
124 - }
125 -
126 - /**
127 - * Get the field props
128 - *
129 - * @return array
130 - */
131 - public function get_field_props() {
132 - $defaults = $this->default_attributes();
133 - $defaults['duplicate'] = '';
134 -
135 - return $defaults;
136 - }
137 -}
1 +<?php
2 +
3 +/**
4 + * Text Field Class
5 + */
6 +class WeForms_Form_Field_Email extends WeForms_Form_Field_Text {
7 +
8 + public function __construct() {
9 + $this->name = __( 'Email Address', 'weforms' );
10 + $this->input_type = 'email_address';
11 + $this->icon = 'envelope-o';
12 + }
13 +
14 + /**
15 + * Render the text field
16 + *
17 + * @param array $field_settings
18 + * @param int $form_id
19 + *
20 + * @return void
21 + */
22 + public function render( $field_settings, $form_id ) {
23 +
24 + // let's not show the email field if user choose to auto populate for logged users
25 + if ( isset( $field_settings['auto_populate'] ) && $field_settings['auto_populate'] == 'yes' && is_user_logged_in() ) {
26 + return;
27 + }
28 +
29 + $value = $field_settings['default']; ?>
30 + <li <?php $this->print_list_attributes( $field_settings ); ?>>
31 + <?php $this->print_label( $field_settings, $form_id ); ?>
32 +
33 + <div class="wpuf-fields">
34 + <input
35 + id="<?php echo esc_attr( $field_settings['name'] ) . '_' . esc_attr( $form_id ); ?>"
36 + type="email"
37 + class="email <?php echo ' wpuf_'. esc_attr( $field_settings['name'] ).'_'. esc_attr( $form_id ); ?>"
38 + data-duplicate="<?php echo isset( $field_settings['duplicate'] ) ? esc_attr( $field_settings['duplicate'] ) : 'no'; ?>"
39 + data-required="<?php echo esc_attr( $field_settings['required'] ) ?>"
40 + data-type="email"
41 + name="<?php echo esc_attr( $field_settings['name'] ); ?>"
42 + placeholder="<?php echo esc_attr( $field_settings['placeholder'] ); ?>"
43 + value="<?php echo esc_attr( $value ); ?>"
44 + size="<?php echo esc_attr( $field_settings['size'] ); ?>"
45 + autocomplete="email"
46 + />
47 + <?php $this->help_text( $field_settings ); ?>
48 + </div>
49 + </li>
50 + <?php
51 + }
52 +
53 + /**
54 + * Get field options setting
55 + *
56 + * @return array
57 + */
58 + public function get_options_settings() {
59 + $default_options = $this->get_default_option_settings();
60 + $default_text_options = $this->get_default_text_option_settings();
61 + $check_duplicate = [
62 + [
63 + 'name' => 'duplicate',
64 + 'title' => 'No Duplicates',
65 + 'type' => 'checkbox',
66 + 'is_single_opt' => true,
67 + 'options' => [
68 + 'no' => __( 'Unique Values Only', 'weforms' ),
69 + ],
70 + 'default' => '',
71 + 'section' => 'advanced',
72 + 'priority' => 23,
73 + 'help_text' => __( 'Select this option to limit user input to unique values only. This will require that a value entered in a field does not currently exist in the entry database for that field.', 'weforms' ),
74 + ],
75 + [
76 + 'name' => 'auto_populate',
77 + 'title' => 'Auto-populate email for logged users',
78 + 'type' => 'checkbox',
79 + 'is_single_opt' => true,
80 + 'options' => [
81 + 'yes' => __( 'Auto-populate Email', 'weforms' ),
82 + ],
83 + 'default' => '',
84 + 'section' => 'advanced',
85 + 'priority' => 23,
86 + 'help_text' => __( 'If a user is logged into the site, this email field will be auto-populated with his email. And form\'s email field will be hidden.', 'weforms' ),
87 + ],
88 + ];
89 +
90 + return array_merge( $default_options, $default_text_options, $check_duplicate );
91 + }
92 +
93 + /**
94 + * Prepare entry default, can be replaced through field classes
95 + *
96 + * @param $field
97 + *
98 + * @return mixed
99 + */
100 + public function prepare_entry( $field, $args = [] ) {
101 + if( empty( $_POST['_wpnonce'])) {
102 + wp_send_json_error( __( 'Unauthorized operation', 'weforms' ) );
103 + }
104 +
105 + if ( ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['_wpnonce'] ) ), 'wpuf_form_add' ) ) {
106 + wp_send_json_error( __( 'Unauthorized operation', 'weforms' ) );
107 + }
108 +
109 + $args = ! empty( $args ) ? $args : weforms_clean( $_POST );
110 +
111 + if ( isset( $field['auto_populate'] ) && $field['auto_populate'] == 'yes' && is_user_logged_in() ) {
112 + $user = wp_get_current_user();
113 +
114 + if ( !empty( $user->user_email ) ) {
115 + return $user->user_email;
116 + }
117 + }
118 +
119 + $value = !empty( $args[ $field[ 'name' ] ] ) ? $args[ $field[ 'name' ] ] : '';
120 +
121 + return sanitize_text_field( trim( $value ) );
122 + }
123 +
124 + /**
125 + * Get the field props
126 + *
127 + * @return array
128 + */
129 + public function get_field_props() {
130 + $defaults = $this->default_attributes();
131 + $defaults['duplicate'] = '';
132 +
133 + return $defaults;
134 + }
135 +}