PluginProbe
UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP / 1.2.38
UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP v1.2.38
1.2.74 1.2.73 1.2.72 1.2.71 1.2.70 1.2.69 1.2.68 1.2.67 1.2.66 1.2.65 1.2.64 1.2.63 trunk 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.15 1.0.16 1.0.17 1.0.18 1.0.19 1.0.20 1.0.21 All 174 releases
← All changes | admin/settings/class-formbuilder.php +2902 -2318 1.0.221.2.38 View file →
@@ -16,2811 +16,3395 @@
16 16 * @subpackage userswp/admin/settings
17 17 * @author GeoDirectory Team <info@wpgeodirectory.com>
18 18 */
19 19 class UsersWP_Form_Builder {
20 -
21 - public function uwp_form_builder($default_tab = 'account')
22 - {
20 +
21 + public static function get_form_id() {
22 + $register_forms = (array) uwp_get_option( 'multiple_registration_forms', array() );
23 +
24 + if ( isset( $_GET['form'] ) && ! empty( $_GET['form'] ) ) {
25 + $current_form_id = absint( $_GET['form'] );
26 + } elseif ( ! empty( $register_forms ) ) {
27 + $default_form = array_filter(
28 + $register_forms,
29 + function ( $form ) {
30 + return (int) $form['id'] === 1;
31 + }
32 + );
33 +
34 + $default_form = array_shift( $default_form );
35 +
36 + if ( isset( $default_form['id'] ) ) {
37 + $current_form_id = (int) $default_form['id'];
38 + } else {
39 + $current_form = reset( $register_forms );
40 + $current_form_id = isset( $current_form['id'] ) ? absint( $current_form['id'] ) : 1;
41 + }
42 + }
43 +
44 + return $current_form_id;
45 + }
46 +
47 + public static function output( $tab = '' ) {
48 +
49 + global $current_tab;
50 +
51 + do_action( 'uwp_form_builder_start' );
52 +
53 + // Get current tab/section
54 + if ( $tab ) {
55 + $current_tab = sanitize_title( $tab );
56 + } else {
57 + $current_tab = empty( $_GET['tab'] ) ? 'account' : sanitize_title( $_GET['tab'] );
58 + }
59 +
60 + $form = '';
61 + if ( isset( $_GET['form'] ) && ! empty( $_GET['form'] ) ) {
62 + $form = '&form=' . (int) $_GET['form'];
63 + }
64 +
65 + // Get tabs for the form builder page
66 + $tabs = apply_filters(
67 + 'uwp_form_builder_tabs_array',
68 + array(
69 + 'account' => __( 'Account', 'userswp' ),
70 + 'register' => __( 'Register', 'userswp' ),
71 + )
72 + );
73 +
74 + ?>
75 + <div class="wrap">
76 + <nav class="nav-tab-wrapper uwp-nav-tab-wrapper">
77 + <?php
78 + foreach ( $tabs as $name => $label ) {
79 + echo '<a href="' . esc_url( admin_url( 'admin.php?page=uwp_form_builder&tab=' . $name . $form ) ) . '" id="uwp-form-builder-' . esc_attr( $name ) . '" class="nav-tab ' . ( $current_tab == $name ? 'nav-tab-active' : '' ) . '">' . esc_html( $label ) . '</a>';
80 + }
81 + do_action( 'uwp_form_builder_tabs' );
82 + ?>
83 + </nav>
84 + <h1 class="screen-reader-text"><?php echo esc_html( $tabs[ $current_tab ] ); ?></h1>
85 + <?php
86 + do_action( 'uwp_form_builder_tabs_content', $current_tab, $tabs );
87 + do_action( 'uwp_form_builder_tabs_' . $current_tab, $tabs );
88 + do_action( 'uwp_extra_form_builder_content', $current_tab, $tabs );
89 + ?>
90 + </div>
91 + <?php
92 + }
93 +
94 + public function uwp_form_builder( $default_tab = 'account' ) {
23 95 ob_start();
24 - $form_type = (isset($_REQUEST['tab']) && $_REQUEST['tab'] != '') ? sanitize_text_field($_REQUEST['tab']) : $default_tab;
96 + $form_type = ( isset( $_GET['tab'] ) && $_GET['tab'] != '' ) ? sanitize_text_field( $_GET['tab'] ) : $default_tab;
25 97 ?>
26 - <div class="uwp-panel-heading">
27 - <h3><?php echo apply_filters('uwp_form_builder_panel_head', ''); ?></h3>
28 - </div>
98 + <div class="uwp-settings-wrap bsui">
29 99
30 - <div id="uwp_form_builder_container" class="clearfix">
31 - <div class="uwp-form-builder-frame">
32 - <div class="uwp-side-sortables" id="uwp-available-fields">
33 - <h3 class="hndle">
34 - <span>
35 - <?php echo apply_filters('uwp_form_builder_available_fields_head', __('Add new form field', 'userswp'), $form_type); ?>
36 - </span>
37 - </h3>
100 + <div class="container-fluid p-0 mt-3">
101 + <?php do_action( 'uwp_before_form_builder_content', $default_tab ); ?>
38 102
39 - <p>
40 - <?php
41 - $note = sprintf(__('Click on any box below to add a field of that type on %s form. You must be use a fieldset to group your fields.', 'userswp'), $form_type);
42 - echo apply_filters('uwp_form_builder_available_fields_note', $note, $form_type);
43 - ?>
44 - </p>
103 + <div id="uwp_form_builder_container" class="row">
104 + <div class="col-md-6">
45 105
46 - <h3>
47 - <?php _e('Setup New Field', 'userswp'); ?>
48 - </h3>
106 + <!-- required for tabs to work -->
107 + <ul class="nav nav-tabs d-none " role="tablist">
108 + <li class="nav-item" role="presentation">
109 + <a class="nav-link active" id="uwp-fields-tab" data-toggle="tab" href="#uwp-available-fields" role="tab" aria-controls="home" aria-selected="true">1</a>
110 + </li>
111 + <li class="nav-item" role="presentation">
112 + <a class="nav-link" id="uwp-field-settings-tab" data-toggle="tab" href="#uwp-field-settings" role="tab" aria-controls="profile" aria-selected="false">2</a>
113 + </li>
114 + </ul>
115 + <!-- required for tabs to work -->
49 116
50 - <div class="inside">
51 - <div id="uwp-form-builder-tab" class="uwp-tabs-panel">
52 - <?php do_action('uwp_manage_available_fields', $form_type); ?>
53 - </div>
54 - </div>
117 + <div class="tab-content sticky-top" style="top: 40px;">
55 118
56 - <?php if ($form_type == 'account') { ?>
57 - <h3>
58 - <?php _e('Predefined Fields', 'userswp'); ?>
59 - </h3>
119 + <div class="side-sortables side-sortables tab-pane fade show active card p-0 mw-100 w-100 border-0 shadow-sm" id="uwp-available-fields" role="tabpanel">
120 + <div class="card border-0 shadow-sm mb-4 px-0 mw-100">
121 + <div class="card-header bg-white">
122 + <h3 class="h5 mb-0 text-dark py-0">
123 + <span><?php echo apply_filters( 'uwp_form_builder_available_fields_head', __( 'Add new form field', 'userswp' ), $form_type ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></span>
124 + </h3>
125 + </div>
126 + <div class="card-body">
127 + <p>
128 + <?php
129 + $note = sprintf( __( 'Click on any box below to add a field of that type on %s form. You must use a fieldset to group your fields.', 'userswp' ), $form_type );
130 + echo apply_filters( 'uwp_form_builder_available_fields_note', $note, $form_type ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
131 + ?>
132 + </p>
133 + <?php do_action( 'uwp_before_available_fields', $default_tab ); ?>
60 134
61 - <div class="inside">
62 - <div id="uwp-form-builder-tab-predefined" class="uwp-tabs-panel">
63 - <?php do_action('uwp_manage_available_fields_predefined', $form_type); ?>
135 + <h4 class="h6 text-muted"><?php esc_html_e( 'Standard Fields', 'userswp' ); ?></h4>
136 + <div id="uwp-form-builder-tab" class="uwp-tabs-panel mb-4">
137 + <?php do_action( 'uwp_manage_available_fields', $form_type ); ?>
138 + </div>
139 +
140 + <?php
141 + $predefined_fields = apply_filters( 'uwp_predefined_fields_tabs', array( 'account', 'profile-tabs' ) );
142 + if ( in_array( $form_type, $predefined_fields ) ) {
143 + ?>
144 + <h4 class="h6 text-muted"><?php esc_html_e( 'Predefined Fields', 'userswp' ); ?></h4>
145 + <div id="uwp-form-builder-tab-predefined" class="uwp-tabs-panel mb-4">
146 + <?php do_action( 'uwp_manage_available_fields_predefined', $form_type ); ?>
147 + </div>
148 + <?php
149 + }
150 +
151 + $custom_fields = apply_filters( 'uwp_custom_fields_tabs', array( 'account', 'profile-tabs' ) );
152 + if ( in_array( $form_type, $custom_fields ) ) {
153 + ?>
154 + <h4 class="h6 text-muted"><?php esc_html_e( 'Custom Fields', 'userswp' ); ?></h4>
155 + <div id="uwp-form-builder-tab-custom" class="uwp-tabs-panel">
156 + <?php do_action( 'uwp_manage_available_fields_custom', $form_type ); ?>
157 + </div>
158 + <?php
159 + }
160 +
161 + do_action( 'uwp_after_available_fields', $default_tab );
162 + ?>
64 163 </div>
65 164 </div>
66 - <?php } ?>
67 -
68 - </div>
165 + </div>
69 166
70 167
71 - <div class="uwp-side-sortables" id="uwp-selected-fields">
168 + <div class="side-sortables side-sortables tab-pane fade card p-0 mw-100 w-100 border-0 shadow-sm" id="uwp-field-settings" role="tabpanel">
169 + <div class="card border-0 shadow-sm mb-4 px-0 mw-100">
170 + <div class="card-header bg-white d-flex justify-content-between">
171 + <h3 class="h5 mb-0 text-dark py-0">
172 + <span><?php echo apply_filters( 'uwp_form_builder_available_fields_settings_head', __( 'Field Settings', 'userswp' ), $form_type ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></span>
173 + </h3>
174 + <?php
175 + global $aui_bs5;
176 + if ( $aui_bs5 ) {
177 + ?>
178 + <button type="button" class="btn-close align-self-center" aria-label="Close" onclick="uwp_tabs_close_settings(this);"></button>
179 + <?php } else { ?>
180 + <button type="button" class="close" aria-label="Close" onclick="uwp_tabs_close_settings(this);">
181 + <span aria-hidden="true">&times;</span>
182 + </button>
183 + <?php } ?>
184 + </div>
72 185
73 - <h3 class="hndle">
74 - <span>
75 - <?php
76 - $title = __('List of fields those will appear on add new listing form', 'userswp');
77 - echo apply_filters('uwp_form_builder_selected_fields_head', $title, $form_type); ?>
78 - </span>
79 - </h3>
186 + <form></form> <!-- required as chrome removes first empty form -->
187 + <form class="uwp-form-settings-form">
188 + <div class="card-body scrollbars-ios" style="max-height: 70vh; overflow-y:auto;">
189 + </div>
190 + </form>
80 191
81 - <p>
82 - <?php
83 - $note = sprintf(__('Click to expand and view field related settings. You may drag and drop to arrange fields order on %s form too.', 'userswp'), $form_type);
84 - echo apply_filters('uwp_form_builder_selected_fields_note', $note, $form_type); ?>
85 - </p>
192 + <div class="card-footer text-right text-end">
86 193
87 - <div class="inside">
88 - <div id="uwp-form-builder-tab-selected" class="uwp-tabs-panel">
89 - <div class="field_row_main">
90 - <?php do_action('uwp_manage_selected_fields', $form_type); ?>
194 + </div>
195 + </div>
91 196 </div>
92 197 </div>
93 198 </div>
94 199
200 + <div class="col-md-6 uwp-side-sortables" id="uwp-selected-fields">
201 + <div class="card border-0 shadow-sm mb-4 px-0 mw-100">
202 + <div class="card-header bg-white">
203 + <h3 class="h5 mb-0 text-dark py-0">
204 + <span>
205 + <?php
206 + $title = __( 'List of fields that will appear in the account form.', 'userswp' );
207 + echo apply_filters( 'uwp_form_builder_selected_fields_head', $title, $form_type ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
208 + ?>
209 + </span>
210 + </h3>
211 + </div>
212 + <div class="card-body">
213 + <p>
214 + <?php
215 + $note = sprintf( __( 'Click to expand and view field related settings. You may drag and drop to arrange fields order on %s form too.', 'userswp' ), $form_type );
216 + echo apply_filters( 'uwp_form_builder_selected_fields_note', $note, $form_type ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
217 + ?>
218 + </p>
219 + <div id="uwp-form-builder-tab-selected" class="uwp-tabs-panel">
220 + <div class="field_row_main">
221 + <?php do_action( 'uwp_manage_selected_fields', $form_type ); ?>
222 + </div>
223 + </div>
224 + </div>
225 + </div>
226 + </div>
227 +
95 228 </div>
96 229
97 230 </div>
98 231 </div>
99 -
100 232 <?php
101 - $output = ob_get_contents();
102 - ob_end_clean();
103 - return $output;
233 + echo ob_get_clean(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
104 234 }
105 235
106 - public function uwp_custom_available_fields($type = '', $form_type)
107 - {
108 - ?>
109 - <input type="hidden" name="form_type" id="form_type" value="<?php echo $form_type; ?>"/>
110 - <input type="hidden" name="manage_field_type" class="manage_field_type" value="custom_fields">
111 - <?php
112 - if ($type == 'predefined') {
113 - $fields = $this->uwp_form_fields_predefined($form_type);
114 - }elseif ($type == 'custom') {
115 - $fields = $this->uwp_form_fields_custom($form_type);
116 - } else {
117 - $fields = $this->uwp_form_fields($form_type);
118 - ?>
119 - <ul class="full uwp-tooltip-wrap">
120 - <li>
121 - <div class="uwp-tooltip">
122 - <?php _e('This adds a section separator with a title.', 'userswp'); ?>
123 - </div>
124 - <a id="uwp-fieldset"
125 - class="uwp-draggable-form-items uwp-fieldset"
126 - href="javascript:void(0);"
127 - data-field-custom-type=""
128 - data-field-type="fieldset"
129 - data-field-type-key="fieldset">
236 + public function display_before_available_fields( $tab = '' ) {
237 + global $wpdb;
130 238
131 - <i class="fas fa-long-arrow-alt-left " aria-hidden="true"></i>
132 - <i class="fas fa-long-arrow-alt-right " aria-hidden="true"></i>
133 - <?php _e('Fieldset (section separator)', 'userswp'); ?>
134 - </a>
135 - </li>
136 - </ul>
239 + if ( empty( $tab ) || $tab == 'account' ) {
240 + $form_type = 'account';
241 + $type = 'predefined';
242 + ?>
243 + <h3 class="h6 text-muted">
244 + <span>
245 + <?php
246 + echo apply_filters( 'uwp_form_builder_available_fields_head', __( 'Existing Fields', 'userswp' ), $form_type ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
137 247
138 - <?php
139 - }
248 + $note = sprintf( __( 'Click on field to add it to the form. Existing fields are most used fields in all other forms.', 'userswp' ), $form_type );
249 + $note_text = apply_filters( 'uwp_form_builder_existing_fields_note', $note, $form_type ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
250 + echo uwp_help_tip( $note_text );
251 + ?>
252 + </span>
253 + </h3>
140 254
141 - if (!empty($fields)) {
142 - ?>
143 - <ul>
144 - <?php
145 - foreach ($fields as $id => $field) {
146 - ?>
147 - <li class="uwp-tooltip-wrap">
148 - <?php
149 - if (isset($field['description']) && $field['description']) {
150 - echo '<div class="uwp-tooltip">' . $field['description'] . '</div>';
151 - } ?>
255 + <div class="inside mb-4">
256 + <div id="uwp-form-builder-tab-existing" class="uwp-tabs-panel">
257 + <input type="hidden" name="form_type" id="form_type" value="<?php echo esc_attr( $form_type ); ?>"/>
258 + <input type="hidden" name="manage_field_type" class="manage_field_type" value="custom_fields">
259 + <ul class="corex uwp-tabs-selected uwp_form_extras row row-cols-2 px-2">
260 + <?php
261 + $form_id = self::get_form_id();
262 + $table_name = uwp_get_table_prefix() . 'uwp_form_fields';
263 + $existing_fields = $wpdb->get_results( 'select htmlvar_name from ' . $table_name . " where form_type ='" . $form_type . "' AND form_id = " . $form_id );
152 264
153 - <a id="uwp-<?php echo $id; ?>"
154 - data-field-custom-type="<?php echo $type; ?>"
155 - data-field-type-key="<?php echo $id; ?>"
156 - data-field-type="<?php echo $field['field_type']; ?>"
157 - class="uwp-draggable-form-items <?php echo $field['class']; ?>"
158 - href="javascript:void(0);">
265 + $existing_field_ids = array();
266 + if ( ! empty( $existing_fields ) ) {
267 + foreach ( $existing_fields as $existing_field ) {
268 + $existing_field_ids[] = $existing_field->htmlvar_name;
269 + }
270 + }
159 271
160 - <?php if (isset($field['icon']) && strpos($field['icon'], ' fa-') !== false) {
161 - echo '<i class="' . $field['icon'] . '" aria-hidden="true"></i>';
162 - } elseif (isset($field['icon']) && $field['icon']) {
163 - echo '<b style="background-image: url("' . $field['icon'] . '")"></b>';
164 - } else {
165 - echo '<i class="fas fa-cog" aria-hidden="true"></i>';
166 - } ?>
167 - <?php echo $field['name']; ?>
168 - </a>
169 - </li>
170 - <?php
171 - }
172 - } else {
173 - _e('There are no custom fields here yet.', 'userswp');
174 - }
175 - ?>
176 - </ul>
272 + $fields = $this->get_form_existing_fields( $form_type, 'array' );
177 273
178 - <?php
274 + if ( ! empty( $fields ) ) {
275 + foreach ( $fields as $id => $field ) {
276 + $display = '';
277 + if ( in_array( $field['htmlvar_name'], $existing_field_ids ) ) {
278 + $display = 'display:none;';
279 + }
179 280
180 - }
281 + $style = 'style="' . $display . '"';
282 + ?>
283 + <li class="uwp-tooltip-wrap col px-1"<?php echo ( $display ? ' style="' . esc_attr( $display ) . '"' : '' ); ?>>
284 + <a id="uwp-<?php echo esc_attr( $field['htmlvar_name'] ); ?>"
285 + data-field-custom-type="<?php echo esc_attr( $type ); ?>"
286 + data-field-type-key="<?php echo esc_attr( $field['htmlvar_name'] ); ?>"
287 + data-field-type="<?php echo esc_attr( $field['field_type'] ); ?>"
288 + class="uwp-draggable-form-itemsx btn btn-sm d-block m-0 btn-outline-gray text-dark text-start"
289 + href="javascript:void(0);">
181 290
182 - public function uwp_form_fields_predefined($type = '') {
183 - $custom_fields = array();
291 + <?php
292 + if ( isset( $field['field_icon'] ) && strpos( $field['field_icon'], ' fa-' ) !== false ) {
293 + echo '<i class="' . esc_attr( $field['field_icon'] ) . '" aria-hidden="true"></i>';
294 + } elseif ( isset( $field['field_icon'] ) && $field['field_icon'] ) {
295 + echo '<b style="background-image: url("' . esc_url( $field['field_icon'] ) . '")"></b>';
296 + } else {
297 + echo '<i class="fas fa-cog" aria-hidden="true"></i>';
298 + }
184 299
185 -
300 + echo ' ' . esc_attr( $field['site_title'] );
186 301
187 - // Country
188 - $custom_fields['country'] = array( // The key value should be unique and not contain any spaces.
189 - 'field_type' => 'select',
190 - 'class' => 'uwp-country',
191 - 'icon' => 'fas fa-map-marker-alt',
192 - 'name' => __('Country', 'userswp'),
193 - 'description' => __('Adds a input for Country field.', 'userswp'),
194 - 'defaults' => array(
195 - 'admin_title' => 'Country',
196 - 'site_title' => 'Country',
197 - 'htmlvar_name' => 'country',
198 - 'is_active' => 1,
199 - 'default_value' => '',
200 - 'is_required' => 0,
201 - 'option_values' => '',
202 - 'required_msg' => '',
203 - 'field_icon' => 'fas fa-map-marker-alt',
204 - 'css_class' => ''
205 - )
206 - );
302 + if ( isset( $field['help_text'] ) && $field['help_text'] ) {
303 + echo uwp_help_tip( $field['help_text'] ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
304 + }
305 + ?>
306 + </a>
307 + </li>
308 + <?php
309 + }
310 + }
311 + ?>
312 + </ul>
313 + </div>
314 + </div>
315 + <?php
316 + }
317 + }
207 318
208 - // Gender
209 - $custom_fields['gender'] = array( // The key value should be unique and not contain any spaces.
210 - 'field_type' => 'select',
211 - 'class' => 'uwp-gender',
212 - 'icon' => 'fas fa-user',
213 - 'name' => __('Gender', 'userswp'),
214 - 'description' => __('Adds a input for Gender field.', 'userswp'),
215 - 'defaults' => array(
216 - 'admin_title' => 'Gender',
217 - 'site_title' => 'Gender',
218 - 'htmlvar_name' => 'gender',
219 - 'is_active' => 1,
220 - 'default_value' => '',
221 - 'is_required' => 0,
222 - 'option_values' => __('Select Gender/,Male,Female,Other', 'userswp'),
223 - 'required_msg' => '',
224 - 'field_icon' => 'fas fa-user',
225 - 'css_class' => ''
226 - )
227 - );
319 + public function get_form_existing_fields( $type = '', $output = '' ) {
228 320
229 - // Mobile
230 - $custom_fields['mobile'] = array( // The key value should be unique and not contain any spaces.
231 - 'field_type' => 'phone',
232 - 'class' => 'uwp-mobile',
233 - 'icon' => 'fas fa-mobile-alt',
234 - 'name' => __('Mobile', 'userswp'),
235 - 'description' => __('Adds a input for Mobile field.', 'userswp'),
236 - 'defaults' => array(
237 - 'admin_title' => 'Mobile',
238 - 'site_title' => 'Mobile',
239 - 'htmlvar_name' => 'mobile',
240 - 'is_active' => 1,
241 - 'default_value' => '',
242 - 'is_required' => 0,
243 - 'required_msg' => '',
244 - 'field_icon' => 'fas fa-mobile-alt',
245 - 'css_class' => ''
246 - )
247 - );
248 -
321 + global $wpdb;
322 + $custom_fields = array();
323 + $table_name = uwp_get_table_prefix() . 'uwp_form_fields';
324 + $register_forms = uwp_get_option( 'multiple_registration_forms' );
325 + if ( 'array' == $output ) {
326 + $output = ARRAY_A;
327 + } else {
328 + $output = OBJECT;
329 + }
330 + if ( ! empty( $register_forms ) && is_array( $register_forms ) ) {
331 + foreach ( $register_forms as $key => $register_form ) {
332 + $form_ids[] = (int) $register_form['id'];
333 + }
249 334
250 - return apply_filters('uwp_form_fields_predefined', $custom_fields, $type);
251 - }
335 + if ( in_array( 1, $form_ids ) ) {
336 + $form_ids[] = 0;
337 + }
252 338
253 - public function uwp_form_fields_custom($type = '') {
254 - $custom_fields = array();
255 - return apply_filters('uwp_form_fields_custom', $custom_fields, $type);
256 - }
339 + if ( isset( $form_ids ) && count( $form_ids ) > 0 ) {
340 + $form_ids_placeholder = array_fill( 0, count( $form_ids ), '%s' );
341 + $form_ids_placeholder = implode( ', ', $form_ids_placeholder );
342 + $query = 'SELECT * FROM ' . $table_name . " WHERE form_type = 'account' AND form_id IN (" . $form_ids_placeholder . ') ORDER BY sort_order ASC';
343 + $custom_fields = $wpdb->get_results( $wpdb->prepare( $query, $form_ids ), $output );
344 + }
345 + }
257 346
258 - public function uwp_form_fields($type = '') {
347 + $custom_fields = uwp_get_unique_custom_fields( $custom_fields );
259 348
260 - $custom_fields = array(
261 - 'text' => array(
262 - 'field_type' => 'text',
263 - 'class' => 'uwp-text',
264 - 'icon' => 'fas fa-minus',
265 - 'name' => __('Text', 'userswp'),
266 - 'description' => __('Add any sort of text field, text or numbers', 'userswp')
267 - ),
268 - 'datepicker' => array(
269 - 'field_type' => 'datepicker',
270 - 'class' => 'uwp-datepicker',
271 - 'icon' => 'fas fa-calendar-alt',
272 - 'name' => __('Date', 'userswp'),
273 - 'description' => __('Adds a date picker.', 'userswp')
274 - ),
275 - 'textarea' => array(
276 - 'field_type' => 'textarea',
277 - 'class' => 'uwp-textarea',
278 - 'icon' => 'fas fa-bars',
279 - 'name' => __('Textarea', 'userswp'),
280 - 'description' => __('Adds a textarea', 'userswp')
281 - ),
282 - 'time' => array(
283 - 'field_type' => 'time',
284 - 'class' => 'uwp-time',
285 - 'icon' => 'far fa-clock',
286 - 'name' => __('Time', 'userswp'),
287 - 'description' => __('Adds a time picker', 'userswp')
288 - ),
289 - 'checkbox' => array(
290 - 'field_type' => 'checkbox',
291 - 'class' => 'uwp-checkbox',
292 - 'icon' => 'far fa-check-square',
293 - 'name' => __('Checkbox', 'userswp'),
294 - 'description' => __('Adds a checkbox', 'userswp')
295 - ),
296 - 'phone' => array(
297 - 'field_type' => 'phone',
298 - 'class' => 'uwp-phone',
299 - 'icon' => 'fas fa-phone',
300 - 'name' => __('Phone', 'userswp'),
301 - 'description' => __('Adds a phone input', 'userswp')
302 - ),
303 - 'radio' => array(
304 - 'field_type' => 'radio',
305 - 'class' => 'uwp-radio',
306 - 'icon' => 'far fa-dot-circle',
307 - 'name' => __('Radio', 'userswp'),
308 - 'description' => __('Adds a radio input', 'userswp')
309 - ),
310 - 'email' => array(
311 - 'field_type' => 'email',
312 - 'class' => 'uwp-email',
313 - 'icon' => 'far fa-envelope',
314 - 'name' => __('Email', 'userswp'),
315 - 'description' => __('Adds a email input', 'userswp')
316 - ),
317 - 'select' => array(
318 - 'field_type' => 'select',
319 - 'class' => 'uwp-select',
320 - 'icon' => 'far fa-caret-square-down',
321 - 'name' => __('Select', 'userswp'),
322 - 'description' => __('Adds a select input', 'userswp')
323 - ),
324 - 'multiselect' => array(
325 - 'field_type' => 'multiselect',
326 - 'class' => 'uwp-multiselect',
327 - 'icon' => 'far fa-caret-square-down',
328 - 'name' => __('Multi Select', 'userswp'),
329 - 'description' => __('Adds a multiselect input', 'userswp')
330 - ),
331 - 'url' => array(
332 - 'field_type' => 'url',
333 - 'class' => 'uwp-url',
334 - 'icon' => 'fas fa-link',
335 - 'name' => __('URL', 'userswp'),
336 - 'description' => __('Adds a url input', 'userswp')
337 - ),
338 - 'file' => array(
339 - 'field_type' => 'file',
340 - 'class' => 'uwp-file',
341 - 'icon' => 'fas fa-file',
342 - 'name' => __('File Upload', 'userswp'),
343 - 'description' => __('Adds a file input', 'userswp')
344 - )
345 - );
349 + return apply_filters( 'uwp_form_existing_fields', $custom_fields, $type );
350 + }
346 351
347 - return apply_filters('uwp_form_fields', $custom_fields, $type);
348 - }
352 + /**
353 + * Render the multiple registration form.
354 + *
355 + * @param string $tab Current tab.
356 + */
357 + public function multiple_registration_form( $tab = '' ) {
358 + $default_tabs = array( 'account', 'register', 'profile-tabs' );
349 359
360 + /**
361 + * Filter the tabs that should show the multiple registration form.
362 + *
363 + * @param array $default_tabs Default tabs.
364 + */
365 + $tabs = apply_filters( 'uwp_multiple_registration_form_tabs', $default_tabs );
350 366
351 - public function uwp_manage_available_fields_predefined($form_type) {
352 - switch ($form_type) {
353 - case 'account':
354 - $this->uwp_custom_available_fields('predefined', $form_type);
355 - break;
367 + if ( ! in_array( $tab, $tabs, true ) ) {
368 + return;
356 369 }
357 - }
358 370
359 - public function uwp_manage_available_fields_custom($form_type) {
360 - switch ($form_type) {
361 - case 'account':
362 - $this->uwp_custom_available_fields('custom', $form_type);
363 - break;
364 - }
365 - }
371 + $register_forms = (array) uwp_get_option( 'multiple_registration_forms', array() );
372 + $current_form_id = self::get_form_id();
373 + ?>
374 + <div class="row">
375 + <div class="col-12">
376 + <div class="card border-0 shadow-sm mb-3 px-0 mw-100">
377 + <div class="card-body">
378 + <input type="hidden" name="manage_field_form_id" class="manage_field_form_id" id="manage_field_form_id" value="<?php echo absint( $current_form_id ); ?>">
379 + <?php
380 + if ( ! empty( $register_forms ) && is_array( $register_forms ) && count( $register_forms ) > 1 ) {
381 + $register_tab = admin_url( "admin.php?page=uwp_form_builder&tab={$tab}" );
366 382
367 - public function uwp_manage_available_fields($form_type) {
368 - switch ($form_type) {
369 - case 'account':
370 - $this->uwp_custom_available_fields('', $form_type);
371 - break;
372 - }
373 - }
383 + ?>
384 + <div class="d-flex align-items-center">
385 + <label class="form-label h1">
386 + <i class="fas fa-user me-3 iconbox border-0 fill rounded-circle transition-all btn-translucent-info iconsmallmedium"></i>
387 + <?php esc_html_e( 'Select user type', 'userswp' ); ?>
388 + </label>
389 + <div class="ms-3 col-6">
390 + <select onChange="window.location.replace(jQuery(this).val());" name="form_select" id="multiple_registration_select" class="form-select form-select-lgx">
391 + <?php
392 + foreach ( $register_forms as $form ) :
393 + $form_id = ! empty( $form['id'] ) ? $form['id'] : '';
394 + $form_title = ! empty( $form['title'] ) ? sanitize_title_with_dashes( $form['title'] ) : '';
395 + $option_text = sprintf(
396 + /* translators: %1$s: Form title, %2$s: Form ID */
397 + esc_html__( '%1$s - #%2$s', 'userswp' ),
398 + $form_title,
399 + $form_id
400 + );
401 + $option_value = esc_url( add_query_arg( 'form', $form_id, $register_tab ) );
402 + ?>
403 + <option <?php selected( $current_form_id, $form_id ); ?> value="<?php echo esc_attr( $option_value ); ?>">
404 + <?php echo esc_html( $option_text ); ?>
405 + </option>
406 + <?php endforeach; ?>
407 + </select>
408 + </div>
409 + </div>
410 + <?php
411 + } else {
412 + $alert_content = wp_kses(
413 + sprintf(
414 + /* translators: %1$s: Alert message, %2$s: URL to add user type, %3$s: Add User Type button text */
415 + '%1$s <a href="%2$s" class="btn btn-primary btn-sm text-decoration-none ms-auto" role="button">%3$s</a>',
416 + esc_html__( 'Add different user types to create custom registration forms with unique roles and redirects.', 'userswp' ),
417 + esc_url( admin_url( 'admin.php?page=uwp_user_types&form=add' ) ),
418 + esc_html__( 'Add User Type', 'userswp' )
419 + ),
420 + array(
421 + 'a' => array(
422 + 'href' => array(),
423 + 'class' => array(),
424 + 'role' => array(),
425 + ),
426 + )
427 + );
374 428
375 - public function uwp_manage_selected_fields($form_type) {
376 - switch ($form_type) {
377 - case 'account':
378 - $this->uwp_custom_selected_fields($form_type);
379 - break;
380 - }
381 - }
429 + aui()->alert(
430 + array(
431 + 'type' => 'dark',
432 + 'class' => 'd-flex align-items-center mb-0',
433 + 'content' => $alert_content,
434 + 'dismissible' => false,
435 + ),
436 + true
437 + );
438 + }
439 + ?>
440 + </div>
441 + </div>
442 + </div>
443 + </div>
444 + <?php
445 + }
382 446
383 - function uwp_custom_selected_fields($form_type)
384 - {
447 + public function manage_available_fields_predefined( $form_type ) {
448 + switch ( $form_type ) {
449 + case 'account':
450 + $this->custom_available_fields( 'predefined', $form_type );
451 + break;
452 + }
453 + }
385 454
386 - global $wpdb;
387 - $table_name = uwp_get_table_prefix() . 'uwp_form_fields';
388 - ?>
389 - <input type="hidden" name="form_type" id="form_type" value="<?php echo $form_type; ?>"/>
455 + public function custom_available_fields( $type, $form_type ) {
456 + ?>
457 + <input type="hidden" name="form_type" id="form_type" value="<?php echo esc_attr( $form_type ); ?>"/>
390 458 <input type="hidden" name="manage_field_type" class="manage_field_type" value="custom_fields">
391 - <ul class="core">
392 - <?php
393 - $fields = $wpdb->get_results($wpdb->prepare("SELECT * FROM " . $table_name . " WHERE form_type = %s ORDER BY sort_order ASC", array($form_type)));
459 + <?php
460 + if ( $type == 'predefined' ) {
461 + $fields = $this->form_fields_predefined( $form_type );
462 + } elseif ( $type == 'custom' ) {
463 + $fields = $this->form_fields_custom( $form_type );
464 + } else {
465 + $fields = $this->form_fields( $form_type );
466 + ?>
467 + <ul class="row row-cols-1 px-2 mb-0">
468 + <li class="uwp-tooltip-wrapx col px-1">
469 + <a id="uwp-fieldset"
470 + class="uwp-draggable-form-itemsx uwp-fieldset btn btn-sm d-block m-0 btn-outline-gray text-dark text-start"
471 + href="javascript:void(0);"
472 + data-field-custom-type=""
473 + data-field-type="fieldset"
474 + data-field-type-key="fieldset">
475 + <i class="fas fa-long-arrow-alt-left " aria-hidden="true"></i>
476 + <i class="fas fa-long-arrow-alt-right " aria-hidden="true"></i>
477 + <?php
478 + esc_html_e( 'Fieldset (section separator)', 'userswp' );
479 + echo uwp_help_tip( __( 'This adds a section separator with a title.', 'userswp' ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
480 + ?>
481 + </a>
482 + </li>
483 + </ul>
394 484
395 - if (!empty($fields)) {
396 - foreach ($fields as $field) {
397 - //$result_str = $field->id;
398 - $result_str = $field;
399 - $field_type = $field->field_type;
400 - $field_type_key = $field->field_type_key;
401 - $field_ins_upd = 'display';
485 + <?php
486 + }
402 487
403 - $this->uwp_form_field_adminhtml($field_type, $result_str, $field_ins_upd, $field_type_key);
404 - }
405 - }
406 - ?></ul>
407 - <?php
488 + if ( ! empty( $fields ) ) {
489 + ?>
490 + <ul class="row row-cols-2 px-2 mb-0">
491 + <?php
492 + foreach ( $fields as $id => $field ) {
493 + ?>
494 + <li class="uwp-tooltip-wrapx col px-1">
495 + <a id="uwp-<?php echo esc_attr( $id ); ?>"
496 + data-field-custom-type="<?php echo esc_attr( $type ); ?>"
497 + data-field-type-key="<?php echo esc_attr( $id ); ?>"
498 + data-field-type="<?php echo esc_attr( $field['field_type'] ); ?>"
499 + class="uwp-draggable-form-itemsx btn btn-sm d-block m-0 btn-outline-gray text-dark text-start"
500 + href="javascript:void(0);">
408 501
409 - }
502 + <?php
503 + if ( isset( $field['field_icon'] ) && strpos( $field['field_icon'], ' fa-' ) !== false ) {
504 + echo '<i class="' . esc_attr( $field['field_icon'] ) . '" aria-hidden="true"></i>';
505 + } elseif ( isset( $field['field_icon'] ) && $field['field_icon'] ) {
506 + echo '<b style="background-image: url("' . esc_url( $field['field_icon'] ) . '")"></b>';
507 + } else {
508 + echo '<i class="fas fa-cog" aria-hidden="true"></i>';
509 + }
410 510
411 - /**
412 - * @param $field_info
413 - * @param $field_type
414 - * @param string $field_type_key
415 - * @param string $field_ins_upd
416 - * @param $result_str
417 - * @param bool $form_type
418 - */
419 - public function uwp_admin_form_field_html($field_info, $field_type, $field_type_key, $field_ins_upd, $result_str, $form_type = false) {
511 + echo ' ' . esc_attr( $field['site_title'] );
420 512
421 - if (!$form_type) {
422 - if (!isset($field_info->form_type)) {
423 - $form_type = sanitize_text_field($_REQUEST['tab']);
424 - } else {
425 - $form_type = $field_info->form_type;
426 - }
427 - }
513 + if ( isset( $field['help_text'] ) && $field['help_text'] ) {
514 + echo uwp_help_tip( $field['help_text'] ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
515 + }
516 + ?>
517 + </a>
518 + </li>
519 + <?php
520 + }
521 + } else {
522 + esc_html_e( 'There are no custom fields here yet.', 'userswp' );
523 + }
524 + ?>
525 + </ul>
428 526
429 - $cf_arr1 = $this->uwp_form_fields($form_type);
430 - $cf_arr2 = $this->uwp_form_fields_predefined($form_type);
431 - $cf_arr3 = $this->uwp_form_fields_custom($form_type);
527 + <?php
528 + }
432 529
433 - $cf_arr = $cf_arr1 + $cf_arr2 + $cf_arr3; // this way defaults can't be overwritten
530 + public function form_fields_predefined( $type = '' ) {
531 + $custom_fields = array();
434 532
435 - $cf = (isset($cf_arr[$field_type_key])) ? $cf_arr[$field_type_key] : '';
533 + // Country
534 + $custom_fields['uwp_country'] = array(
535 + 'field_type' => 'select',
536 + 'class' => 'uwp-country',
537 + 'field_icon' => 'fas fa-map-marker-alt',
538 + 'site_title' => __( 'Country', 'userswp' ),
539 + 'help_text' => __( 'Adds a input for Country field.', 'userswp' ),
540 + 'defaults' => array(
541 + 'admin_title' => 'Country',
542 + 'site_title' => 'Country',
543 + 'htmlvar_name' => 'uwp_country',
544 + 'is_active' => 1,
545 + 'default_value' => '',
546 + 'is_required' => 0,
547 + 'option_values' => '',
548 + 'required_msg' => '',
549 + 'field_icon' => 'fas fa-map-marker-alt',
550 + 'css_class' => '',
551 + ),
552 + );
436 553
437 - $field_info = stripslashes_deep($field_info); // strip slashes from labels
554 + // Gender
555 + $custom_fields['gender'] = array(
556 + 'field_type' => 'select',
557 + 'class' => 'uwp-gender',
558 + 'field_icon' => 'fas fa-user',
559 + 'site_title' => __( 'Gender', 'userswp' ),
560 + 'help_text' => __( 'Adds a input for Gender field.', 'userswp' ),
561 + 'defaults' => array(
562 + 'admin_title' => 'Gender',
563 + 'site_title' => 'Gender',
564 + 'htmlvar_name' => 'gender',
565 + 'is_active' => 1,
566 + 'default_value' => '',
567 + 'is_required' => 0,
568 + 'option_values' => __( 'Male,Female,Other', 'userswp' ),
569 + 'required_msg' => '',
570 + 'field_icon' => 'fas fa-user',
571 + 'css_class' => '',
572 + ),
573 + );
438 574
439 - $field_site_title = '';
440 - if (isset($field_info->site_title))
441 - $field_site_title = $field_info->site_title;
575 + $custom_fields['dob'] = array(
576 + 'field_type' => 'datepicker',
577 + 'class' => 'uwp-dob',
578 + 'field_icon' => 'fas fa-birthday-cake',
579 + 'site_title' => __( 'Date of birth', 'userswp' ),
580 + 'help_text' => __( 'Adds a date input for users to enter their date of birth.', 'userswp' ),
581 + 'defaults' => array(
582 + 'data_type' => 'DATE',
583 + 'admin_title' => __( 'Date of birth', 'userswp' ),
584 + 'site_title' => __( 'Date of birth', 'userswp' ),
585 + 'form_label' => __( 'Enter your date of birth.', 'userswp' ),
586 + 'htmlvar_name' => 'dob',
587 + 'is_active' => true,
588 + 'for_admin_use' => false,
589 + 'default_value' => '',
590 + 'is_required' => false,
591 + 'validation_pattern' => '',
592 + 'validation_msg' => '',
593 + 'required_msg' => '',
594 + 'field_icon' => 'fas fa-birthday-cake',
595 + 'css_class' => '',
596 + 'extra_fields' => array(
597 + 'date_range' => 'c-100:c+0',
598 + ),
599 + ),
600 + );
442 601
443 - $default = isset($field_info->is_default) ? $field_info->is_default : '';
602 + // Mobile
603 + $custom_fields['mobile'] = array(
604 + 'field_type' => 'phone',
605 + 'class' => 'uwp-mobile',
606 + 'field_icon' => 'fas fa-mobile-alt',
607 + 'site_title' => __( 'Mobile', 'userswp' ),
608 + 'help_text' => __( 'Adds a input for Mobile field.', 'userswp' ),
609 + 'defaults' => array(
610 + 'admin_title' => 'Mobile',
611 + 'site_title' => 'Mobile',
612 + 'htmlvar_name' => 'mobile',
613 + 'is_active' => 1,
614 + 'default_value' => '',
615 + 'is_required' => 0,
616 + 'required_msg' => '',
617 + 'field_icon' => 'fas fa-mobile-alt',
618 + 'css_class' => '',
619 + ),
620 + );
444 621
445 - $field_display = $field_type == 'address' && $field_info->htmlvar_name == 'post' ? 'style="display:none"' : '';
622 + $custom_fields['register_gdpr'] = array(
623 + 'field_type' => 'checkbox',
624 + 'class' => 'uwp-register-gdpr',
625 + 'field_icon' => 'fas fa-file',
626 + 'site_title' => __( 'GDPR Policy Page', 'userswp' ),
627 + 'help_text' => __( 'Adds Register GDPR page.', 'userswp' ),
628 + 'defaults' => array(
629 + 'admin_title' => 'GDPR Policy',
630 + 'site_title' => 'GDPR Policy',
631 + 'form_label' => __( 'GDPR Policy', 'userswp' ),
632 + 'htmlvar_name' => 'register_gdpr',
633 + 'is_active' => 1,
634 + 'default_value' => '',
635 + 'is_required' => 1,
636 + 'required_msg' => '',
637 + 'field_icon' => 'fas fa-file',
638 + 'css_class' => 'btn-register-gdpr',
639 + ),
640 + );
446 641
447 - $radio_id = (isset($field_info->htmlvar_name)) ? $field_info->htmlvar_name : rand(5, 500);
642 + $custom_fields['register_tos'] = array(
643 + 'field_type' => 'checkbox',
644 + 'class' => 'uwp-register-tos',
645 + 'field_icon' => 'fas fa-file',
646 + 'site_title' => __( 'Terms & Conditions', 'userswp' ),
647 + 'help_text' => __( 'Adds Register TOS page.', 'userswp' ),
648 + 'help_text_tip' => __( 'This will show next to the checkbox, to add a link to the TOS page, use format: %%link_start%% View TOS %%link_end%%', 'userswp' ),
649 + 'defaults' => array(
650 + 'admin_title' => 'Terms & Conditions',
651 + 'site_title' => 'Terms & Conditions',
652 + 'form_label' => __( 'Terms & Conditions', 'userswp' ),
653 + 'htmlvar_name' => 'register_tos',
654 + 'is_active' => 1,
655 + 'default_value' => '',
656 + 'is_required' => 1,
657 + 'required_msg' => '',
658 + 'field_icon' => 'fas fa-file',
659 + 'css_class' => 'btn-register-tos',
660 + ),
661 + );
448 662
663 + // Website
664 + $custom_fields['user_url'] = array(
665 + 'field_type' => 'url',
666 + 'class' => 'uwp-website',
667 + 'field_icon' => 'fas fa-link',
668 + 'site_title' => __( 'Website', 'userswp' ),
669 + 'help_text' => __( 'Let users enter their website url.', 'userswp' ),
670 + 'defaults' => array(
671 + 'admin_title' => 'Website',
672 + 'site_title' => 'Website',
673 + 'form_label' => __( 'Website', 'userswp' ),
674 + 'htmlvar_name' => 'user_url',
675 + 'is_active' => 1,
676 + 'default_value' => '',
677 + 'is_required' => 0,
678 + 'required_msg' => '',
679 + 'field_icon' => 'fas fa-link',
680 + 'css_class' => 'btn-website',
681 + ),
682 + );
449 683
450 - if (isset($cf['icon']) && strpos($cf['icon'], ' fa-') !== false) {
451 - $field_icon = '<i class="' . $cf['icon'] . '" aria-hidden="true"></i>';
452 - }elseif (isset($cf['icon']) && $cf['icon']) {
453 - $field_icon = '<b style="background-image: url("' . $cf['icon'] . '")"></b>';
454 - } else {
455 - $field_icon = '<i class="fas fa-cog" aria-hidden="true"></i>';
456 - }
684 + // Facebook
685 + $custom_fields['facebook'] = array(
686 + 'field_type' => 'url',
687 + 'class' => 'uwp-facebook',
688 + 'field_icon' => 'fab fa-facebook-square',
689 + 'site_title' => __( 'Facebook', 'userswp' ),
690 + 'help_text' => __( 'Let users enter their facebook url.', 'userswp' ),
691 + 'defaults' => array(
692 + 'admin_title' => 'Facebook',
693 + 'site_title' => 'Facebook',
694 + 'form_label' => __( 'Facebook url', 'userswp' ),
695 + 'htmlvar_name' => 'facebook',
696 + 'is_active' => 1,
697 + 'default_value' => '',
698 + 'is_required' => 0,
699 + 'required_msg' => '',
700 + 'field_icon' => 'fab fa-facebook-f',
701 + 'css_class' => 'btn-facebook',
702 + ),
703 + );
457 704
458 - if (isset($cf['name']) && $cf['name']) {
459 - $field_type_name = $cf['name'];
460 - } else {
461 - $field_type_name = $field_type;
462 - }
705 + // Twitter
706 + $custom_fields['twitter'] = array(
707 + 'field_type' => 'url',
708 + 'class' => 'uwp-twitter',
709 + 'field_icon' => 'fab fa-twitter-square',
710 + 'site_title' => __( 'Twitter', 'userswp' ),
711 + 'help_text' => __( 'Let users enter their twitter url.', 'userswp' ),
712 + 'defaults' => array(
713 + 'admin_title' => 'Twitter',
714 + 'site_title' => 'Twitter',
715 + 'form_label' => __( 'Twitter url', 'userswp' ),
716 + 'htmlvar_name' => 'twitter',
717 + 'is_active' => 1,
718 + 'default_value' => '',
719 + 'is_required' => 0,
720 + 'required_msg' => '',
721 + 'field_icon' => 'fab fa-twitter',
722 + 'css_class' => 'btn-twitter',
723 + ),
724 + );
463 725
464 - ?>
465 - <li class="text" id="licontainer_<?php echo $result_str; ?>">
466 - <div class="title title<?php echo $result_str; ?> uwp-fieldset"
467 - title="<?php _e('Double Click to toggle and drag-drop to sort', 'userswp'); ?>"
468 - ondblclick="uwp_show_hide('field_frm<?php echo $result_str; ?>')">
469 - <?php
726 + // Instagram
727 + $custom_fields['instagram'] = array(
728 + 'field_type' => 'url',
729 + 'class' => 'uwp-instagram',
730 + 'field_icon' => 'fab fa-instagram',
731 + 'site_title' => __( 'Instagram', 'userswp' ),
732 + 'help_text' => __( 'Let users enter their instagram url.', 'userswp' ),
733 + 'defaults' => array(
734 + 'admin_title' => 'Instagram',
735 + 'site_title' => 'Instagram',
736 + 'form_label' => __( 'Instagram url', 'userswp' ),
737 + 'htmlvar_name' => 'instagram',
738 + 'is_active' => 1,
739 + 'default_value' => '',
740 + 'is_required' => 0,
741 + 'required_msg' => '',
742 + 'field_icon' => 'fab fa-instagram',
743 + 'css_class' => 'btn-instagram',
744 + ),
745 + );
470 746
471 - $nonce = wp_create_nonce('custom_fields_' . $result_str);
472 - ?>
747 + // Linkedin
748 + $custom_fields['linkedin'] = array(
749 + 'field_type' => 'url',
750 + 'class' => 'uwp-linkedin',
751 + 'field_icon' => 'fab fa-linkedin',
752 + 'site_title' => __( 'Linkedin', 'userswp' ),
753 + 'help_text' => __( 'Let users enter their linkedin url.', 'userswp' ),
754 + 'defaults' => array(
755 + 'admin_title' => 'Linkedin',
756 + 'site_title' => 'Linkedin',
757 + 'form_label' => __( 'Linkedin url', 'userswp' ),
758 + 'htmlvar_name' => 'linkedin',
759 + 'is_active' => 1,
760 + 'default_value' => '',
761 + 'is_required' => 0,
762 + 'required_msg' => '',
763 + 'field_icon' => 'fab fa-linkedin-in',
764 + 'css_class' => 'btn-linkedin',
765 + ),
766 + );
473 767
474 - <?php if ($default): ?>
475 - <?php else: ?>
476 - <div title="<?php _e('Click to remove field', 'userswp'); ?>"
477 - onclick="delete_field('<?php echo $result_str; ?>', '<?php echo $nonce; ?>')"
478 - class="handlediv close"><i class="fas fa-times" aria-hidden="true"></i></div>
479 - <?php endif;
480 - if ($field_type == 'fieldset') {
481 - ?>
482 - <i class="fas fa-long-arrow-alt-left " aria-hidden="true"></i>
483 - <i class="fas fa-long-arrow-alt-right " aria-hidden="true"></i>
484 - <b style="cursor:pointer;"
485 - onclick="uwp_show_hide('field_frm<?php echo $result_str; ?>')"><?php echo uwp_ucwords(__('Fieldset:', 'userswp') . ' ' . $field_site_title); ?></b>
486 - <?php
487 - } else {echo $field_icon;
488 - ?>
489 - <b style="cursor:pointer;"
490 - onclick="uwp_show_hide('field_frm<?php echo $result_str; ?>')"><?php echo uwp_ucwords(' ' . $field_site_title . ' (' . $field_type_name . ')'); ?></b>
491 - <?php
492 - }
493 - ?>
494 - </div>
768 + // Flickr
769 + $custom_fields['flickr'] = array(
770 + 'field_type' => 'url',
771 + 'class' => 'uwp-flickr',
772 + 'field_icon' => 'fab fa-flickr',
773 + 'site_title' => __( 'Flickr', 'userswp' ),
774 + 'help_text' => __( 'Let users enter their Flickr url.', 'userswp' ),
775 + 'defaults' => array(
776 + 'admin_title' => 'Flickr',
777 + 'site_title' => 'Flickr',
778 + 'form_label' => __( 'Flickr url', 'userswp' ),
779 + 'htmlvar_name' => 'flickr',
780 + 'is_active' => 1,
781 + 'default_value' => '',
782 + 'is_required' => 0,
783 + 'required_msg' => '',
784 + 'field_icon' => 'fab fa-flickr',
785 + 'css_class' => 'btn-flickr',
786 + ),
787 + );
495 788
496 - <form><!-- we need to wrap in a fom so we can use radio buttons with same name -->
497 - <div id="field_frm<?php echo $result_str; ?>" class="field_frm"
498 - style="display:<?php if ($field_ins_upd == 'submit') {
499 - echo 'block;';
500 - } else {
501 - echo 'none;';
502 - } ?>">
503 - <input type="hidden" name="_wpnonce" value="<?php echo esc_attr($nonce); ?>"/>
504 - <input type="hidden" name="form_type" id="form_type" value="<?php echo $form_type; ?>"/>
505 - <input type="hidden" name="field_type" id="field_type" value="<?php echo $field_type; ?>"/>
506 - <input type="hidden" name="field_type_key" id="field_type_key" value="<?php echo $field_type_key; ?>"/>
507 - <input type="hidden" name="field_id" id="field_id" value="<?php echo esc_attr($result_str); ?>"/>
508 - <input type="hidden" name="is_active" id="is_active" value="1"/>
789 + // GitHub
790 + $custom_fields['github'] = array(
791 + 'field_type' => 'url',
792 + 'class' => 'uwp-github',
793 + 'field_icon' => 'fab fa-github-square',
794 + 'site_title' => __( 'GitHub', 'userswp' ),
795 + 'help_text' => __( 'Let users enter their GitHub url.', 'userswp' ),
796 + 'defaults' => array(
797 + 'admin_title' => 'GitHub',
798 + 'site_title' => 'GitHub',
799 + 'form_label' => __( 'GitHub url', 'userswp' ),
800 + 'htmlvar_name' => 'github',
801 + 'is_active' => 1,
802 + 'default_value' => '',
803 + 'is_required' => 0,
804 + 'required_msg' => '',
805 + 'field_icon' => 'fab fa-github-alt',
806 + 'css_class' => 'btn-github',
807 + ),
808 + );
509 809
510 - <input type="hidden" name="is_default" value="<?php echo isset($field_info->is_default) ? $field_info->is_default : ''; ?>" /><?php // show in sidebar value?>
810 + // YouTube
811 + $custom_fields['youtube'] = array(
812 + 'field_type' => 'url',
813 + 'class' => 'uwp-youtube',
814 + 'field_icon' => 'fab fa-youtube-square',
815 + 'site_title' => __( 'YouTube', 'userswp' ),
816 + 'help_text' => __( 'Let users enter their YouTube url.', 'userswp' ),
817 + 'defaults' => array(
818 + 'admin_title' => 'YouTube',
819 + 'site_title' => 'YouTube',
820 + 'form_label' => __( 'YouTube url', 'userswp' ),
821 + 'htmlvar_name' => 'youtube',
822 + 'is_active' => 1,
823 + 'default_value' => '',
824 + 'is_required' => 0,
825 + 'required_msg' => '',
826 + 'field_icon' => 'fab fa-youtube',
827 + 'css_class' => 'btn-youtube',
828 + ),
829 + );
511 830
512 - <ul class="widefat post fixed" style="width:100%;">
831 + // WordPress
832 + $custom_fields['wordpress'] = array(
833 + 'field_type' => 'url',
834 + 'class' => 'uwp-wordpress',
835 + 'field_icon' => 'fab fa-wordpress-simple',
836 + 'site_title' => __( 'WordPress', 'userswp' ),
837 + 'help_text' => __( 'Let users enter their WordPress profile url.', 'userswp' ),
838 + 'defaults' => array(
839 + 'admin_title' => 'WordPress',
840 + 'site_title' => 'WordPress',
841 + 'form_label' => __( 'WordPress url', 'userswp' ),
842 + 'htmlvar_name' => 'wordpress',
843 + 'is_active' => 1,
844 + 'default_value' => '',
845 + 'is_required' => 0,
846 + 'required_msg' => '',
847 + 'field_icon' => 'fab fa-wordpress-simple',
848 + 'css_class' => 'btn-wordpress',
849 + ),
850 + );
513 851
514 - <?php
515 - // data_type
516 - if (has_filter("uwp_builder_data_type_{$field_type}")) {
852 + // Language
853 + $custom_fields['uwp_language'] = array(
854 + 'field_type' => 'select',
855 + 'class' => 'uwp-language',
856 + 'field_icon' => 'fas fa-language',
857 + 'site_title' => __( 'Select Language', 'userswp' ),
858 + 'help_text' => __( 'Adds a input for user language selection.', 'userswp' ),
859 + 'defaults' => array(
860 + 'admin_title' => 'Select Language',
861 + 'site_title' => 'Select Language',
862 + 'form_label' => __( 'Site Language', 'userswp' ),
863 + 'htmlvar_name' => 'uwp_language',
864 + 'is_active' => 1,
865 + 'default_value' => 'site-default',
866 + 'is_required' => 0,
867 + 'option_values' => '',
868 + 'required_msg' => '',
869 + 'field_icon' => 'fas fa-language',
870 + 'css_class' => '',
871 + ),
872 + );
517 873
518 - echo apply_filters("uwp_builder_data_type_{$field_type}", '', $result_str, $cf, $field_info);
874 + return apply_filters( 'uwp_form_fields_predefined', $custom_fields, $type );
875 + }
519 876
520 - } else {
521 - $value = '';
522 - if (isset($field_info->data_type)) {
523 - $value = esc_attr($field_info->data_type);
524 - }elseif (isset($cf['defaults']['data_type']) && $cf['defaults']['data_type']) {
525 - $value = $cf['defaults']['data_type'];
526 - }
527 - ?>
528 - <input type="hidden" name="data_type" id="data_type" value="<?php echo $value; ?>"/>
529 - <?php
530 - }
531 -
532 - // site_title
533 - if (has_filter("uwp_builder_site_title_{$field_type}")) {
877 + public function form_fields_custom( $type = '' ) {
878 + $custom_fields = array();
534 879
535 - echo apply_filters("uwp_builder_site_title_{$field_type}", '', $result_str, $cf, $field_info);
880 + return apply_filters( 'uwp_form_fields_custom', $custom_fields, $type );
881 + }
536 882
537 - } else {
538 - $value = '';
539 - if (isset($field_info->site_title)) {
540 - $value = esc_attr($field_info->site_title);
541 - }elseif (isset($cf['defaults']['site_title']) && $cf['defaults']['site_title']) {
542 - $value = $cf['defaults']['site_title'];
543 - }
544 - ?>
545 - <li>
546 - <label for="site_title" class="uwp-tooltip-wrap"> <i class="fas fa-info-circle" aria-hidden="true"></i> <?php _e('Label:', 'userswp'); ?>
547 - <div class="uwp-tooltip">
548 - <?php _e('This will be the label for the field.', 'userswp'); ?>
549 - </div>
550 - </label>
551 - <div class="uwp-input-wrap">
552 - <input type="text" name="site_title" id="site_title"
553 - value="<?php echo $value; ?>"/>
554 - </div>
555 - </li>
556 - <?php
557 - }
883 + public function form_fields( $type = '' ) {
558 884
559 - // Input Label
560 - if (has_filter("uwp_builder_form_label_{$field_type}")) {
885 + $custom_fields = array(
886 + 'text' => array(
887 + 'field_type' => 'text',
888 + 'class' => 'uwp-text',
889 + 'field_icon' => 'fas fa-minus',
890 + 'site_title' => __( 'Text', 'userswp' ),
891 + 'help_text' => __( 'Add any sort of text field, text or numbers', 'userswp' ),
892 + ),
893 + 'datepicker' => array(
894 + 'field_type' => 'datepicker',
895 + 'class' => 'uwp-datepicker',
896 + 'field_icon' => 'fas fa-calendar-alt',
897 + 'site_title' => __( 'Date', 'userswp' ),
898 + 'help_text' => __( 'Adds a date picker.', 'userswp' ),
899 + ),
900 + 'textarea' => array(
901 + 'field_type' => 'textarea',
902 + 'class' => 'uwp-textarea',
903 + 'field_icon' => 'fas fa-bars',
904 + 'site_title' => __( 'Textarea', 'userswp' ),
905 + 'help_text' => __( 'Adds a textarea', 'userswp' ),
906 + ),
907 + 'time' => array(
908 + 'field_type' => 'time',
909 + 'class' => 'uwp-time',
910 + 'field_icon' => 'far fa-clock',
911 + 'site_title' => __( 'Time', 'userswp' ),
912 + 'help_text' => __( 'Adds a time picker', 'userswp' ),
913 + ),
914 + 'checkbox' => array(
915 + 'field_type' => 'checkbox',
916 + 'class' => 'uwp-checkbox',
917 + 'field_icon' => 'far fa-check-square',
918 + 'site_title' => __( 'Checkbox', 'userswp' ),
919 + 'help_text' => __( 'Adds a checkbox', 'userswp' ),
920 + ),
921 + 'phone' => array(
922 + 'field_type' => 'phone',
923 + 'class' => 'uwp-phone',
924 + 'field_icon' => 'fas fa-phone',
925 + 'site_title' => __( 'Phone', 'userswp' ),
926 + 'help_text' => __( 'Adds a phone input', 'userswp' ),
927 + ),
928 + 'radio' => array(
929 + 'field_type' => 'radio',
930 + 'class' => 'uwp-radio',
931 + 'field_icon' => 'far fa-dot-circle',
932 + 'site_title' => __( 'Radio', 'userswp' ),
933 + 'help_text' => __( 'Adds a radio input', 'userswp' ),
934 + ),
935 + 'email' => array(
936 + 'field_type' => 'email',
937 + 'class' => 'uwp-email',
938 + 'field_icon' => 'far fa-envelope',
939 + 'site_title' => __( 'Email', 'userswp' ),
940 + 'help_text' => __( 'Adds a email input', 'userswp' ),
941 + ),
942 + 'select' => array(
943 + 'field_type' => 'select',
944 + 'field_icon' => 'far fa-caret-square-down',
945 + 'site_title' => __( 'Select', 'userswp' ),
946 + 'help_text' => __( 'Adds a select input', 'userswp' ),
947 + ),
948 + 'multiselect' => array(
949 + 'field_type' => 'multiselect',
950 + 'class' => 'uwp-multiselect',
951 + 'field_icon' => 'far fa-caret-square-down',
952 + 'site_title' => __( 'Multi Select', 'userswp' ),
953 + 'help_text' => __( 'Adds a multiselect input', 'userswp' ),
954 + ),
955 + 'url' => array(
956 + 'field_type' => 'url',
957 + 'class' => 'uwp-url',
958 + 'field_icon' => 'fas fa-link',
959 + 'site_title' => __( 'URL', 'userswp' ),
960 + 'help_text' => __( 'Adds a url input', 'userswp' ),
961 + ),
962 + 'editor' => array(
963 + 'field_type' => 'editor',
964 + 'class' => 'uwp-html',
965 + 'field_icon' => 'fas fa-code',
966 + 'site_title' => __( 'HTML', 'userswp' ),
967 + 'help_text' => __( 'Adds a wysiwyg editor input', 'userswp' ),
968 + ),
969 + 'file' => array(
970 + 'field_type' => 'file',
971 + 'class' => 'uwp-file',
972 + 'field_icon' => 'fas fa-file',
973 + 'site_title' => __( 'File Upload', 'userswp' ),
974 + 'help_text' => __( 'Adds a file input', 'userswp' ),
975 + ),
976 + );
561 977
562 - echo apply_filters("uwp_builder_form_label_{$field_type}", '', $result_str, $cf, $field_info);
978 + return apply_filters( 'uwp_form_fields', $custom_fields, $type );
979 + }
563 980
564 - } else {
565 - $value = '';
566 - if (isset($field_info->form_label)) {
567 - $value = esc_attr($field_info->form_label);
568 - }elseif (isset($cf['defaults']['form_label']) && $cf['defaults']['form_label']) {
569 - $value = $cf['defaults']['form_label'];
570 - }
571 - ?>
572 - <li>
573 - <label for="form_label" class="uwp-tooltip-wrap"> <i class="fas fa-info-circle" aria-hidden="true"></i> <?php _e('Form Label: (Optional)', 'userswp'); ?>
574 - <div class="uwp-tooltip">
575 - <?php _e('If your form label is different, then you can fill this field. Ex: You would like to display "What is your age?" in Form Field but would like to display "DOB" in site. In such cases "What is your age?" should be entered here and "DOB" should be entered in previous field. Note: If this field not filled, then the previous field will be used in Form. ', 'userswp'); ?>
576 - </div>
577 - </label>
578 - <div class="uwp-input-wrap">
579 - <input type="text" name="form_label" id="form_label"
580 - value="<?php echo $value; ?>"/>
581 - </div>
582 - </li>
583 - <?php
584 - }
981 + public function manage_available_fields_custom( $form_type ) {
982 + switch ( $form_type ) {
983 + case 'account':
984 + $this->custom_available_fields( 'custom', $form_type );
985 + break;
986 + }
987 + }
585 988
989 + public function manage_available_fields( $form_type ) {
990 + switch ( $form_type ) {
991 + case 'account':
992 + $this->custom_available_fields( '', $form_type );
993 + break;
994 + case 'register':
995 + $this->register_available_fields( $form_type );
996 + break;
997 + }
998 + }
586 999
587 - // htmlvar_name
588 - if(has_filter("uwp_builder_htmlvar_name_{$field_type}")){
1000 + public function register_available_fields( $form_type ) {
1001 + global $wpdb;
589 1002
590 - echo apply_filters("uwp_builder_htmlvar_name_{$field_type}",'',$result_str,$cf,$field_info);
1003 + $form_id = self::get_form_id();
591 1004
592 - }else{
593 - $value = '';
594 - if (isset($field_info->htmlvar_name)) {
595 - $value = esc_attr($field_info->htmlvar_name);
596 - }elseif(isset($cf['defaults']['htmlvar_name']) && $cf['defaults']['htmlvar_name']){
597 - $value = $cf['defaults']['htmlvar_name'];
598 - }
599 - ?>
600 - <li>
601 - <label for="htmlvar_name" class="uwp-tooltip-wrap"><i class="fas fa-info-circle" aria-hidden="true"></i> <?php _e('HTML variable name :', 'userswp');?>
602 - <div class="uwp-tooltip">
603 - <?php _e('This is a unique identifier used in the HTML, it MUST NOT contain spaces or special characters.', 'userswp'); ?>
604 - </div>
605 - </label>
606 - <div class="uwp-input-wrap">
607 - <input type="text" name="htmlvar_name" id="htmlvar_name" pattern="[a-zA-Z0-9]+" title="<?php _e('Must not contain spaces or special characters', 'userswp');?>"
608 - value="<?php if ($value) {
609 - echo preg_replace('/uwp_'.$form_type.'_/', '', $value, 1);
610 - }?>" <?php if ($default) {
611 - echo 'readonly="readonly"';
612 - }?> />
613 - </div>
614 - </li>
615 - <?php
616 - }
1005 + $extras_table_name = uwp_get_table_prefix() . 'uwp_form_extras';
617 1006
1007 + // Retrieve fields saved with form id 0.
1008 + if ( $form_id === 1 ) {
1009 + $where = 'AND ( form_id = 1 OR form_id = 0 )';
1010 + } else {
1011 + $where = $wpdb->prepare( 'AND form_id = %d', $form_id );
1012 + }
618 1013
619 - // is_active
620 - if (has_filter("uwp_builder_is_active_{$field_type}")) {
1014 + $existing_fields = $wpdb->get_results( $wpdb->prepare( 'SELECT site_htmlvar_name FROM `' . $extras_table_name . "` WHERE form_type = %s {$where}", $form_type ) );
621 1015
622 - echo apply_filters("uwp_builder_is_active_{$field_type}", '', $result_str, $cf, $field_info);
1016 + $existing_field_ids = array();
1017 + if ( ! empty( $existing_fields ) ) {
1018 + foreach ( $existing_fields as $existing_field ) {
1019 + $existing_field_ids[] = $existing_field->site_htmlvar_name;
1020 + }
1021 + }
1022 + ?>
1023 + <input type="hidden" name="form_type" id="form_type" value="<?php echo esc_attr( $form_type ); ?>"/>
1024 + <input type="hidden" name="manage_field_type" class="manage_field_type" value="register">
1025 + <ul class="row row-cols-1 px-2 mb-0">
1026 + <?php
623 1027
624 - } else {
625 - $value = '';
626 - if (isset($field_info->is_active)) {
627 - $value = esc_attr($field_info->is_active);
628 - }elseif (isset($cf['defaults']['is_active']) && $cf['defaults']['is_active']) {
629 - $value = $cf['defaults']['is_active'];
630 - }
631 - ?>
632 - <li <?php echo $field_display; ?>>
633 - <label for="is_active" class="uwp-tooltip-wrap"><i class="fas fa-info-circle" aria-hidden="true"></i> <?php _e('Is active :', 'userswp'); ?>
634 - <div class="uwp-tooltip">
635 - <?php _e('If no is selected then the field will not be displayed anywhere.', 'userswp'); ?>
636 - </div>
637 - </label>
638 - <div class="uwp-input-wrap uwp-switch">
1028 + $fields = $this->register_fields( $form_type, $form_id );
639 1029
640 - <input type="radio" id="is_active_yes<?php echo $radio_id; ?>" name="is_active" class="uwp-ri-enabled" value="1"
641 - <?php if ($value == '1') {
642 - echo 'checked';
643 - } ?>/>
644 - <label for="is_active_yes<?php echo $radio_id; ?>" class="uwp-cb-enable"><span><?php _e('Yes', 'userswp'); ?></span></label>
1030 + if ( ! empty( $fields ) ) {
1031 + foreach ( $fields as $field ) {
1032 + $field = stripslashes_deep( $field ); // strip slashes
645 1033
646 - <input type="radio" id="is_active_no<?php echo $radio_id; ?>" name="is_active" class="uwp-ri-disabled" value="0"
647 - <?php if ($value == '0' || !$value) {
648 - echo 'checked';
649 - } ?>/>
650 - <label for="is_active_no<?php echo $radio_id; ?>" class="uwp-cb-disable"><span><?php _e('No', 'userswp'); ?></span></label>
1034 + $fieldset_width = '';
1035 + if ( $field['field_type'] == 'fieldset' ) {
1036 + $fieldset_width = 'width:100%;';
1037 + }
651 1038
652 - </div>
653 - </li>
654 - <?php
655 - }
1039 + $display = '';
1040 + if ( in_array( $field['htmlvar_name'], $existing_field_ids ) ) {
1041 + $display = 'display:none;';
1042 + }
656 1043
657 - // for_admin_use
658 - if (isset($field_info->is_default) && $field_info->is_default == '1') {
659 - // do nothing for default fields
660 - } else {
661 - if (has_filter("uwp_builder_for_admin_use_{$field_type}")) {
1044 + $style = 'style="' . $display . $fieldset_width . '"';
1045 + ?>
1046 + <li <?php echo $style; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> class="col px-1" >
662 1047
663 - echo apply_filters("uwp_builder_for_admin_use_{$field_type}", '', $result_str, $cf, $field_info);
1048 + <a id="uwp-<?php echo esc_attr( $field['htmlvar_name'] ); ?>"
1049 + class="uwp-draggable-form-itemsx uwp-<?php echo esc_attr( $field['field_type'] ); ?> btn btn-sm d-block m-0 btn-outline-gray text-dark text-start"
1050 + href="javascript:void(0);" data-field-type="<?php echo esc_attr( $field['field_type'] ); ?>">
664 1051
665 - } else {
666 - $value = '';
667 - if (isset($field_info->for_admin_use)) {
668 - $value = esc_attr($field_info->for_admin_use);
669 - }elseif (isset($cf['defaults']['for_admin_use']) && $cf['defaults']['for_admin_use']) {
670 - $value = $cf['defaults']['for_admin_use'];
671 - }
672 - ?>
673 - <li <?php echo $field_display; ?>>
674 - <label for="for_admin_use" class="uwp-tooltip-wrap"><i class="fas fa-info-circle" aria-hidden="true"></i> <?php _e('For admin use only? :', 'userswp'); ?>
675 - <div class="uwp-tooltip">
676 - <?php _e('If yes is selected then only site admin can see and edit this field.', 'userswp'); ?>
677 - </div>
678 - </label>
679 - <div class="uwp-input-wrap uwp-switch">
1052 + <?php
1053 + if ( $icon = uwp_get_field_icon( $field['field_icon'] ) ) {
1054 + echo $icon; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1055 + } else {
1056 + echo '<i class="fas fa-cog" aria-hidden="true"></i>';
1057 + }
1058 + ?>
680 1059
681 - <input type="radio" id="for_admin_use_yes<?php echo $radio_id; ?>" name="for_admin_use" class="uwp-ri-enabled" value="1"
682 - <?php if ($value == '1') {
683 - echo 'checked';
684 - } ?>/>
685 - <label for="for_admin_use_yes<?php echo $radio_id; ?>" onclick="uwp_show_hide_radio(this,'hide','cf-incin-reg-form');uwp_show_hide_radio(this,'hide','cf-inconlyin-reg-form');" class="uwp-cb-enable"><span><?php _e('Yes', 'userswp'); ?></span></label>
1060 + <?php echo esc_attr( $field['site_title'] ); ?>
686 1061
687 - <input type="radio" id="for_admin_use_no<?php echo $radio_id; ?>" name="for_admin_use" class="uwp-ri-disabled" value="0"
688 - <?php if ($value == '0' || !$value) {
689 - echo 'checked';
690 - } ?>/>
691 - <label for="for_admin_use_no<?php echo $radio_id; ?>" onclick="uwp_show_hide_radio(this,'show','cf-incin-reg-form');uwp_show_hide_radio(this,'show','cf-inconlyin-reg-form');" class="uwp-cb-disable"><span><?php _e('No', 'userswp'); ?></span></label>
1062 + </a>
1063 + </li>
692 1064
693 - </div>
694 - </li>
695 - <?php
696 - }
697 - }
698 1065
1066 + <?php
1067 + }
1068 + }
1069 + ?>
1070 + </ul>
1071 + <?php
1072 + }
699 1073
700 - // is_public
701 - if (has_filter("uwp_builder_is_public_{$field_type}")) {
1074 + public function register_fields( $form_type, $form_id = 1 ) {
1075 + global $wpdb;
702 1076
703 - echo apply_filters("uwp_builder_is_public_{$field_type}", '', $result_str, $cf, $field_info);
1077 + $table_name = uwp_get_table_prefix() . 'uwp_form_fields';
704 1078
705 - } else {
706 - $value = '';
707 - if (isset($field_info->is_public)) {
708 - $value = esc_attr($field_info->is_public);
709 - }elseif (isset($cf['defaults']['is_public']) && $cf['defaults']['is_public']) {
710 - $value = $cf['defaults']['is_public'];
711 - }
712 - ?>
713 - <li <?php echo $field_display; ?>>
714 - <label for="is_public" class="uwp-tooltip-wrap"><i class="fas fa-info-circle" aria-hidden="true"></i> <?php _e('Is Public :', 'userswp'); ?>
715 - <div class="uwp-tooltip">
716 - <?php _e('If no is selected then the field will not be visible to other users.', 'userswp'); ?>
717 - </div>
718 - </label>
719 - <div class="uwp-input-wrap uwp-switch">
720 - <?php
721 - if (!$value) {
722 - $value = "0";
723 - }
724 - ?>
1079 + // Retrieve fields saved with form id 0.
1080 + if ( $form_id === 1 ) {
1081 + $where = 'AND ( form_id = 1 OR form_id = 0 )';
1082 + } else {
1083 + $where = $wpdb->prepare( 'AND form_id = %d', $form_id );
1084 + }
725 1085
726 - <select name="is_public" id="is_public">
727 - <option value="0" <?php selected($value, "0"); ?>><?php echo __("No", "userswp") ?></option>
728 - <option value="1" <?php selected($value, "1"); ?>><?php echo __("Yes", "userswp") ?></option>
729 - <option value="2" <?php selected($value, "2"); ?>><?php echo __("Let User Decide", "userswp") ?></option>
730 - </select>
1086 + $fields = $wpdb->get_results( $wpdb->prepare( 'SELECT field_type, site_title, htmlvar_name, field_icon FROM `' . $table_name . "` WHERE form_type = %s AND is_register_field = %s {$where} ORDER BY sort_order ASC", array( 'account', '1' ) ), ARRAY_A );
731 1087
732 - </div>
733 - </li>
734 - <?php
735 - }
1088 + return apply_filters( 'uwp_register_fields', $fields, $form_type );
1089 + }
736 1090
1091 + public function manage_selected_fields( $form_type ) {
1092 + switch ( $form_type ) {
1093 + case 'account':
1094 + $this->custom_selected_fields( $form_type );
1095 + break;
1096 + case 'register':
1097 + $this->register_selected_fields( $form_type );
1098 + break;
1099 + }
1100 + }
737 1101
738 - // default_value
739 - if (has_filter("uwp_builder_default_value_{$field_type}")) {
1102 + public function custom_selected_fields( $form_type ) {
740 1103
741 - echo apply_filters("uwp_builder_default_value_{$field_type}", '', $result_str, $cf, $field_info);
1104 + global $wpdb;
1105 + $table_name = uwp_get_table_prefix() . 'uwp_form_fields';
1106 + $form_id = self::get_form_id();
1107 + ?>
1108 + <input type="hidden" name="form_type" id="form_type" value="<?php echo esc_attr( $form_type ); ?>"/>
1109 + <input type="hidden" name="manage_field_type" class="manage_field_type" value="custom_fields">
1110 + <ul class="core uwp-tabs-selected uwp_form_extras ps-0 list-group">
1111 + <?php
1112 + // Retrieve fields saved with form id 0.
1113 + if ( $form_id === 1 ) {
1114 + $where = 'AND ( form_id = 1 OR form_id = 0 )';
1115 + } else {
1116 + $where = $wpdb->prepare( 'AND form_id = %d', $form_id );
1117 + }
742 1118
743 - } else {
744 - $value = '';
745 - if (isset($field_info->default_value)) {
746 - $value = esc_attr($field_info->default_value);
747 - }elseif (isset($cf['defaults']['default_value']) && $cf['defaults']['default_value']) {
748 - $value = $cf['defaults']['default_value'];
749 - }
750 - ?>
751 - <li>
752 - <label for="default_value" class="uwp-tooltip-wrap"><i class="fas fa-info-circle" aria-hidden="true"></i> <?php _e('Default value :', 'userswp'); ?>
753 - <div class="uwp-tooltip">
754 - <?php
755 - if ($field_type == 'checkbox') {
756 - _e('Should the checkbox be checked by default?', 'userswp');
757 - } else if ($field_type == 'email') {
758 - _e('A default value for the field, usually blank. Ex: info@mysite.com', 'userswp');
759 - } else {
760 - _e('A default value for the field, usually blank. (for "link" this will be used as the link text)', 'userswp');
761 - }
762 - ?>
763 - </div>
764 - </label>
765 - <div class="uwp-input-wrap">
766 - <?php if ($field_type == 'checkbox') { ?>
767 - <select name="default_value" id="default_value">
768 - <option value=""><?php _e('Unchecked', 'userswp'); ?></option>
769 - <option value="1" <?php selected(true, (int) $value === 1); ?>><?php _e('Checked', 'userswp'); ?></option>
770 - </select>
771 - <?php } else if ($field_type == 'email') { ?>
772 - <input type="email" name="default_value" placeholder="<?php _e('info@mysite.com', 'userswp'); ?>" id="default_value" value="<?php echo esc_attr($value); ?>" /><br/>
773 - <?php } else { ?>
774 - <input type="text" name="default_value" id="default_value" value="<?php echo esc_attr($value); ?>" /><br/>
775 - <?php } ?>
776 - </div>
777 - </li>
778 - <?php
779 - }
1119 + $fields = $wpdb->get_results( $wpdb->prepare( 'SELECT * FROM `' . $table_name . "` WHERE form_type = %s {$where} ORDER BY sort_order ASC", $form_type ) );
780 1120
1121 + if ( ! empty( $fields ) ) {
1122 + foreach ( $fields as $field ) {
1123 + $result_str = $field;
1124 + $field_type = $field->field_type;
1125 + $field_type_key = $field->field_type_key;
1126 + $field_ins_upd = 'display';
781 1127
782 - // advanced_editor
783 - if (has_filter("uwp_builder_advanced_editor_{$field_type}")) {
1128 + $this->form_field_adminhtml( $field_type, $result_str, $field_ins_upd, $field_type_key );
1129 + }
1130 + }
1131 + ?>
1132 + </ul>
1133 + <?php
1134 + }
784 1135
785 - echo apply_filters("uwp_builder_advanced_editor_{$field_type}", '', $result_str, $cf, $field_info);
1136 + public function form_field_adminhtml( $field_type, $result_str, $field_ins_upd = '', $field_type_key = '', $form_type = false ) {
1137 + global $wpdb;
1138 + $table_name = uwp_get_table_prefix() . 'uwp_form_fields';
1139 + $cf = $result_str;
1140 + $cf_arr = $this->get_form_existing_fields( $form_type );
786 1141
787 - }
1142 + if ( ! is_object( $cf ) ) {
788 1143
1144 + $field_info = $wpdb->get_row( $wpdb->prepare( 'select * from ' . $table_name . ' where id= %d', array( $cf ) ) );
789 1145
790 - ?>
1146 + } else {
1147 + $field_info = $cf;
1148 + $result_str = $cf->id;
1149 + }
791 1150
792 - <?php // we dont need to show the sort order ?>
793 - <input type="hidden" readonly="readonly" name="sort_order" id="sort_order" value="<?php if (isset($field_info->sort_order)) { echo esc_attr($field_info->sort_order); } ?>"/>
1151 + if ( ! $field_info ) {
1152 + $field_info = ( isset( $cf_arr[ $field_type_key ] ) ) ? $cf_arr[ $field_type_key ] : null;
1153 + }
794 1154
1155 + $this->admin_form_field_html( $field_info, $field_type, $field_type_key, $field_ins_upd, $result_str, $form_type );
1156 + }
795 1157
1158 + /**
1159 + * @param $field_info
1160 + * @param $field_type
1161 + * @param string $field_type_key
1162 + * @param string $field_ins_upd
1163 + * @param $result_str
1164 + * @param bool $form_type
1165 + */
1166 + public function admin_form_field_html( $field_info, $field_type, $field_type_key, $field_ins_upd, $result_str, $form_type = false ) {
796 1167
797 - <?php
1168 + if ( ! $form_type ) {
1169 + if ( ! isset( $field_info->form_type ) ) {
1170 + $form_type = sanitize_text_field( $_REQUEST['tab'] );
1171 + } else {
1172 + $form_type = $field_info->form_type;
1173 + }
1174 + }
798 1175
799 - // is_required
800 - if (has_filter("uwp_builder_is_required_{$field_type}")) {
1176 + $cf_arr1 = $this->form_fields( $form_type );
1177 + $cf_arr2 = $this->form_fields_predefined( $form_type );
1178 + $cf_arr3 = $this->form_fields_custom( $form_type );
801 1179
802 - echo apply_filters("uwp_builder_is_required_{$field_type}", '', $result_str, $cf, $field_info);
1180 + $cf_arr = $cf_arr1 + $cf_arr2 + $cf_arr3; // this way defaults can't be overwritten
803 1181
804 - } else {
805 - $value = '';
806 - if (isset($field_info->is_required)) {
807 - $value = esc_attr($field_info->is_required);
808 - }elseif (isset($cf['defaults']['is_required']) && $cf['defaults']['is_required']) {
809 - $value = $cf['defaults']['is_required'];
810 - }
811 - ?>
812 - <li>
813 - <label for="is_required" class="uwp-tooltip-wrap"><i class="fas fa-info-circle" aria-hidden="true"></i> <?php _e('Is required :', 'userswp'); ?>
814 - <div class="uwp-tooltip">
815 - <?php _e('Select yes to set field as required', 'userswp'); ?>
816 - </div>
817 - </label>
1182 + $cf = ( isset( $cf_arr[ $field_type_key ] ) ) ? $cf_arr[ $field_type_key ] : '';
818 1183
819 - <div class="uwp-input-wrap uwp-switch">
1184 + $field_info = stripslashes_deep( $field_info ); // strip slashes from labels
820 1185
821 - <input type="radio" id="is_required_yes<?php echo $radio_id; ?>" name="is_required" class="uwp-ri-enabled" value="1"
822 - <?php if ($value == '1') {
823 - echo 'checked';
824 - } ?>/>
825 - <label onclick="uwp_show_hide_radio(this,'show','cf-is-required-msg');" for="is_required_yes<?php echo $radio_id; ?>" class="uwp-cb-enable"><span><?php _e('Yes', 'userswp'); ?></span></label>
1186 + $field_site_title = '';
1187 + if ( isset( $field_info->site_title ) ) {
1188 + $field_site_title = $field_info->site_title;
1189 + }
826 1190
827 - <input type="radio" id="is_required_no<?php echo $radio_id; ?>" name="is_required" class="uwp-ri-disabled" value="0"
828 - <?php if ($value == '0' || !$value) {
829 - echo 'checked';
830 - } ?>/>
831 - <label onclick="uwp_show_hide_radio(this,'hide','cf-is-required-msg');" for="is_required_no<?php echo $radio_id; ?>" class="uwp-cb-disable"><span><?php _e('No', 'userswp'); ?></span></label>
1191 + $field_display = $field_type == 'address' && $field_info->htmlvar_name == 'post' ? 'style="display:none"' : '';
832 1192
833 - </div>
1193 + if ( isset( $cf['field_icon'] ) && strpos( $cf['field_icon'], ' fa-' ) !== false ) {
1194 + $field_icon = '<i class="' . esc_attr( $cf['field_icon'] ) . '" aria-hidden="true"></i>';
1195 + } elseif ( isset( $cf['field_icon'] ) && $cf['field_icon'] ) {
1196 + $field_icon = '<b style="background-image: url("' . esc_url( $cf['field_icon'] ) . '")"></b>';
1197 + } else {
1198 + $field_icon = '<i class="fas fa-cog" aria-hidden="true"></i>';
1199 + }
834 1200
835 - </li>
1201 + if ( isset( $cf['site_title'] ) && $cf['site_title'] ) {
1202 + $field_type_name = $cf['site_title'];
1203 + } else {
1204 + $field_type_name = $field_type;
1205 + }
836 1206
837 - <?php
838 - }
1207 + $htmlvar_name = isset( $field_info->htmlvar_name ) ? sanitize_text_field( $field_info->htmlvar_name ) : '';
1208 + $can_delete = apply_filters( 'uwp_cfa_can_delete_field', true, $field_info, $form_type );
1209 + $nonce = wp_create_nonce( 'custom_fields_' . $result_str );
839 1210
840 - // required_msg
841 - if (has_filter("uwp_builder_required_msg_{$field_type}")) {
1211 + ?>
1212 + <li class="text li-settings" id="licontainer_<?php echo esc_attr( $result_str ); ?>">
1213 + <div class="title title<?php echo esc_attr( $result_str ); ?> uwp-fieldset hover-shadow dd-form d-flex justify-content-between rounded c-pointer list-group-item border rounded-smx text-start bg-light " onclick="uwp_tabs_item_settings(this);">
1214 + <div class="flex-fill font-weight-bold fw-bold">
1215 + <?php if ( $field_type == 'fieldset' ) { ?>
1216 + <i class="fas fa-long-arrow-alt-left " aria-hidden="true"></i>
1217 + <i class="fas fa-long-arrow-alt-right " aria-hidden="true"></i>
1218 + <b><?php echo esc_html( uwp_ucwords( __( 'Fieldset:', 'userswp' ) ) ); ?></b>
1219 + <span class="field-type float-end text-end small"><?php echo ' (' . esc_html( uwp_ucwords( $field_site_title ) ) . ')'; ?></span>
1220 + <?php } else { ?>
1221 + <?php echo $field_icon; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
1222 + <b><?php echo esc_html( uwp_ucwords( ' ' . $field_site_title ) ); ?></b>
1223 + <span class="field-type float-end text-end small"><?php echo ' (' . esc_html( uwp_ucwords( $field_type_name ) ) . ')'; ?></span>
1224 + <?php } ?>
1225 + </div>
1226 + <div class="dd-handle ui-sortable-handle">
1227 + <?php if ( $can_delete ) { ?>
1228 + <i class="far fa-trash-alt text-danger ml-2 ms-2"
1229 + id="delete-<?php echo esc_attr( $result_str ); ?>"
1230 + onclick="delete_field('<?php echo esc_attr( $result_str ); ?>', '<?php echo esc_attr( wp_create_nonce( 'custom_fields_delete_' . $result_str ) ); ?>', '<?php echo esc_attr( $htmlvar_name ); ?>');event.stopPropagation();return false;"></i>
1231 + <?php } ?>
1232 + <i class="fas fa-grip-vertical text-muted ml-2 ms-2" style="cursor: move" aria-hidden="true"></i>
1233 + </div>
842 1234
843 - echo apply_filters("uwp_builder_required_msg_{$field_type}", '', $result_str, $cf, $field_info);
1235 + <?php // store the form as a template. This saves a load of memory on page load. ?>
1236 + <script type="text/template" class="dd-setting <?php echo 'dd-type-' . esc_attr( $field_type ); ?>">
1237 + <input type="hidden" name="_wpnonce" value="<?php echo esc_attr( $nonce ); ?>"/>
1238 + <input type="hidden" name="form_type" id="form_type" value="<?php echo esc_attr( $form_type ); ?>"/>
1239 + <input type="hidden" name="field_type" id="field_type" value="<?php echo esc_attr( $field_type ); ?>"/>
1240 + <input type="hidden" name="field_type_key" id="field_type_key" value="<?php echo esc_attr( $field_type_key ); ?>"/>
1241 + <input type="hidden" name="field_id" id="field_id" value="<?php echo esc_attr( $result_str ); ?>"/>
1242 + <input type="hidden" name="is_default" value="<?php echo isset( $field_info->is_default ) ? esc_attr( $field_info->is_default ) : ''; ?>"/><?php // show in sidebar value ?>
844 1243
845 - } else {
846 - $value = '';
847 - if (isset($field_info->required_msg)) {
848 - $value = esc_attr($field_info->required_msg);
849 - }elseif (isset($cf['defaults']['required_msg']) && $cf['defaults']['required_msg']) {
850 - $value = $cf['defaults']['required_msg'];
851 - }
852 - ?>
853 - <li class="cf-is-required-msg" <?php if ((isset($field_info->is_required) && $field_info->is_required == '0') || !isset($field_info->is_required)) {echo "style='display:none;'"; }?>>
854 - <label for="required_msg" class="uwp-tooltip-wrap">
855 - <i class="fas fa-info-circle" aria-hidden="true"></i> <?php _e('Required message:', 'userswp'); ?>
856 - <div class="uwp-tooltip">
857 - <?php _e('Enter text for the error message if the field is required and has not fulfilled the requirements.', 'userswp'); ?>
858 - </div>
859 - </label>
860 - <div class="uwp-input-wrap">
861 - <input type="text" name="required_msg" id="required_msg"
862 - value="<?php echo esc_attr($value); ?>"/>
863 - </div>
864 - </li>
865 - <?php
1244 + <?php
1245 + // data_type
1246 + if ( has_filter( "uwp_builder_data_type_{$field_type}" ) ) {
1247 +
1248 + echo apply_filters( "uwp_builder_data_type_{$field_type}", '', $result_str, $cf, $field_info ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1249 +
1250 + } else {
1251 + $value = '';
1252 + if ( isset( $field_info->data_type ) ) {
1253 + $value = esc_attr( $field_info->data_type );
1254 + } elseif ( isset( $cf['defaults']['data_type'] ) && $cf['defaults']['data_type'] ) {
1255 + $value = $cf['defaults']['data_type'];
866 1256 }
1257 + ?>
1258 + <input type="hidden" name="data_type" id="data_type" value="<?php echo esc_attr( $value ); ?>"/>
1259 + <?php
1260 + }
867 1261
1262 + // site_title
1263 + if ( has_filter( "uwp_builder_site_title_{$field_type}" ) ) {
868 1264
869 - // required_msg
870 - if (has_filter("uwp_builder_validation_pattern_{$field_type}")) {
1265 + echo apply_filters( "uwp_builder_site_title_{$field_type}", '', $result_str, $cf, $field_info ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
871 1266
872 - echo apply_filters("uwp_builder_validation_pattern_{$field_type}", '', $result_str, $cf, $field_info);
873 -
1267 + } else {
1268 + $value = '';
1269 + if ( isset( $field_info->site_title ) ) {
1270 + $value = esc_attr( $field_info->site_title );
1271 + } elseif ( isset( $cf['defaults']['site_title'] ) && $cf['defaults']['site_title'] ) {
1272 + $value = $cf['defaults']['site_title'];
874 1273 }
875 1274
1275 + echo aui()->input(
1276 + array(
1277 + 'id' => 'site_title',
1278 + 'name' => 'site_title',
1279 + 'label_type' => 'top',
1280 + 'label' => esc_html__( 'Label', 'userswp' ) . uwp_help_tip( __( 'This will be the label for the field.', 'userswp' ) ), // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1281 + 'type' => 'text',
1282 + // 'wrap_class' => geodir_advanced_toggle_class(),
1283 + 'value' => $value,
1284 + )
1285 + );
1286 + }
876 1287
877 - // extra_fields
878 - if (has_filter("uwp_builder_extra_fields_{$field_type}")) {
1288 + // Input Label
1289 + if ( has_filter( "uwp_builder_form_label_{$field_type}" ) ) {
879 1290
880 - echo apply_filters("uwp_builder_extra_fields_{$field_type}", '', $result_str, $cf, $field_info);
1291 + echo apply_filters( "uwp_builder_form_label_{$field_type}", '', $result_str, $cf, $field_info ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
881 1292
1293 + } else {
1294 + $value = '';
1295 + if ( isset( $field_info->form_label ) ) {
1296 + $value = esc_attr( $field_info->form_label );
1297 + } elseif ( isset( $cf['defaults']['form_label'] ) && $cf['defaults']['form_label'] ) {
1298 + $value = $cf['defaults']['form_label'];
882 1299 }
883 1300
1301 + echo aui()->input(
1302 + array(
1303 + 'id' => 'form_label',
1304 + 'name' => 'form_label',
1305 + 'label_type' => 'top',
1306 + 'label' => esc_html__( 'Form Label: (Optional)', 'userswp' ) . uwp_help_tip( __( 'If your form label is different, then you can fill this field. Ex: You would like to display "What is your age?" in Form Field but would like to display "DOB" in site. In such cases "What is your age?" should be entered here and "DOB" should be entered in previous field. Note: If this field not filled, then the previous field will be used in Form.', 'userswp' ) ), // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1307 + 'type' => 'text',
1308 + 'wrap_class' => uwp_advanced_toggle_class(),
1309 + 'value' => $value,
1310 + )
1311 + );
1312 + }
884 1313
885 - // field_icon
886 - if (has_filter("uwp_builder_field_icon_{$field_type}")) {
1314 + // Input Description
1315 + if ( has_filter( "uwp_builder_field_description_{$field_type}" ) ) {
887 1316
888 - echo apply_filters("uwp_builder_field_icon_{$field_type}", '', $result_str, $cf, $field_info);
1317 + echo apply_filters( "uwp_builder_field_description_{$field_type}", '', $result_str, $cf, $field_info ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
889 1318
890 - } else {
891 - $value = '';
892 - if (isset($field_info->field_icon)) {
893 - $value = esc_attr($field_info->field_icon);
894 - }elseif (isset($cf['defaults']['field_icon']) && $cf['defaults']['field_icon']) {
895 - $value = $cf['defaults']['field_icon'];
896 - }
897 - ?>
898 - <li>
899 -
900 - <label for="field_icon" class="uwp-tooltip-wrap">
901 - <i class="fas fa-info-circle" aria-hidden="true"></i> <?php _e('Upload icon :', 'userswp'); ?>
902 - <div class="uwp-tooltip">
903 - <?php _e('Upload icon using media and enter its url path, or enter <a href="http://fortawesome.github.io/Font-Awesome/icons/" target="_blank" >font awesome </a>class eg:"fas fa-home"', 'userswp'); ?>
904 - </div>
905 - </label>
906 - <div class="uwp-input-wrap">
907 - <input type="text" name="field_icon" id="field_icon"
908 - value="<?php echo $value; ?>"/>
909 - </div>
910 -
911 - </li>
912 - <?php
1319 + } else {
1320 + $value = '';
1321 + if ( isset( $field_info->help_text ) ) {
1322 + $value = esc_attr( $field_info->help_text );
1323 + } elseif ( isset( $cf['defaults']['help_text'] ) && $cf['defaults']['help_text'] ) {
1324 + $value = $cf['defaults']['help_text'];
913 1325 }
1326 + $tip_text = ! empty( $cf['help_text_tip'] ) ? esc_attr( $cf['help_text_tip'] ) : __( 'This will be displayed below the field in the form.', 'userswp' );
1327 + echo aui()->input(
1328 + array(
1329 + 'id' => 'help_text',
1330 + 'name' => 'help_text',
1331 + 'label_type' => 'top',
1332 + 'label' => esc_html__( 'Field Description', 'userswp' ) . uwp_help_tip( $tip_text ), // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1333 + 'type' => 'text',
1334 + //'wrap_class' => uwp_advanced_toggle_class(),
1335 + 'value' => $value,
1336 + )
1337 + );
914 1338
1339 + }
915 1340
916 - // css_class
917 - if (has_filter("uwp_builder_css_class_{$field_type}")) {
1341 + // htmlvar_name
1342 + if ( has_filter( "uwp_builder_htmlvar_name_{$field_type}" ) ) {
918 1343
919 - echo apply_filters("uwp_builder_css_class_{$field_type}", '', $result_str, $cf, $field_info);
1344 + echo apply_filters( "uwp_builder_htmlvar_name_{$field_type}", '', $result_str, $cf, $field_info ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
920 1345
921 - } else {
922 - ?>
923 - <li>
924 -
925 - <label for="css_class" class="uwp-tooltip-wrap">
926 - <i class="fas fa-info-circle" aria-hidden="true"></i> <?php _e('Css class :', 'userswp'); ?>
927 - <div class="uwp-tooltip">
928 - <?php _e('Enter custom css class for field custom style.', 'userswp'); ?>
929 - <?php if ($field_type == 'multiselect') {_e('(Enter class `uwp-comma-list` to show list as comma separated)', 'userswp'); }?>
930 - </div>
931 - </label>
932 - <div class="uwp-input-wrap">
933 - <input type="text" name="css_class" id="css_class"
934 - value="<?php if (isset($field_info->css_class)) {
935 - echo esc_attr($field_info->css_class);
936 - }?>"/>
937 - </div>
938 - </li>
939 - <?php
1346 + } else {
1347 + $value = '';
1348 + if ( isset( $field_info->htmlvar_name ) ) {
1349 + $value = esc_attr( $field_info->htmlvar_name );
1350 + } elseif ( isset( $cf['defaults']['htmlvar_name'] ) && $cf['defaults']['htmlvar_name'] ) {
1351 + $value = $cf['defaults']['htmlvar_name'];
940 1352 }
941 1353
942 - // show_in
943 - if (has_filter("uwp_builder_show_in_{$field_type}")) {
1354 + $extra_attributes = array();
1355 + $class = '';
1356 + if ( isset( $field_info->id ) && substr( $field_info->id, 0, 4 ) === 'new-' && empty( $field_info->single_use ) ) {
1357 +} // New non single use predefined fields should have ability to change html_var
1358 + elseif ( ! empty( $value ) && $value != 'uwp_' ) {
1359 +$extra_attributes['readonly'] = 'readonly'; $class = 'bg-opacity-50 bg-gray'; }
944 1360
945 - echo apply_filters("uwp_builder_show_in_{$field_type}", '', $result_str, $cf, $field_info);
1361 + $extra_attributes['maxlength'] = 50;
1362 + $extra_attributes['pattern'] = '[a-zA-Z0-9]+';
946 1363
947 - } else {
948 - $value = '';
949 - if (isset($field_info->show_in)) {
950 - $value = esc_attr($field_info->show_in);
951 - }elseif (isset($cf['defaults']['show_in']) && $cf['defaults']['show_in']) {
952 - $value = esc_attr($cf['defaults']['show_in']);
953 - }
954 - ?>
955 - <li>
956 - <label for="show_in" class="uwp-tooltip-wrap"><i class="fas fa-info-circle" aria-hidden="true"></i> <?php _e('Show in what locations?:', 'userswp'); ?>
957 - <div class="uwp-tooltip">
958 - <?php _e('Select in what locations you want to display this field.', 'userswp'); ?>
959 - </div>
960 - </label>
961 - <div class="uwp-input-wrap">
1364 + echo aui()->input(
1365 + array(
1366 + 'id' => 'htmlvar_name',
1367 + 'name' => 'htmlvar_name',
1368 + 'title' => __( 'Must not contain spaces or special characters', 'userswp' ),
1369 + 'label_type' => 'top',
1370 + 'label' => __( 'Key', 'userswp' ) . uwp_help_tip( __( 'This is a unique identifier used in the HTML, it MUST NOT contain spaces or special characters.', 'userswp' ) ),
1371 + 'type' => 'text',
1372 + 'wrap_class' => uwp_advanced_toggle_class(),
1373 + 'value' => $value ? preg_replace( '/uwp_/', '', $value, 1 ) : '',
1374 + 'extra_attributes' => $extra_attributes,
1375 + 'class' => $class,
1376 + )
1377 + );
962 1378
963 - <?php
1379 + }
964 1380
965 - $show_in_locations = array(
966 - "[users]" => __("Users Page", 'userswp'),
967 - "[more_info]" => __("More info tab", 'userswp'),
968 - "[own_tab]" => __("Profile page own tab", 'userswp'),
969 - "[profile_side]" => __("Profile Side", 'userswp'),
970 - );
1381 + // Placeholder text
1382 + if ( has_filter( "uwp_builder_placeholder_value_{$field_type}" ) ) {
971 1383
972 - if ($field_type != 'fieldset') {
973 - $show_in_locations["[fieldset]"] = __("Fieldset", 'userswp');
974 - }
975 -
976 - $show_in_locations = apply_filters('uwp_show_in_locations', $show_in_locations, $field_info, $field_type);
1384 + echo apply_filters( "uwp_builder_placeholder_value_{$field_type}", '', $result_str, $cf, $field_info ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
977 1385
978 -
979 - if (in_array($field_type, array('text', 'datepicker', 'textarea', 'time', 'phone', 'email', 'select', 'multiselect', 'url', 'html', 'fieldset', 'radio', 'checkbox', 'file'))) {
980 - } else {
981 - unset($show_in_locations['[own_tab]']);
982 - }
983 -
984 - ?>
1386 + } else {
1387 + $value = '';
1388 + if ( isset( $field_info->placeholder_value ) ) {
1389 + $value = esc_attr( $field_info->placeholder_value );
1390 + } elseif ( isset( $cf['defaults']['placeholder_value'] ) && $cf['defaults']['placeholder_value'] ) {
1391 + $value = $cf['defaults']['placeholder_value'];
1392 + }
985 1393
986 - <select multiple="multiple" name="show_in[]"
987 - id="show_in"
988 - style="min-width:300px;"
989 - class="uwp_chosen_select"
990 - data-placeholder="<?php _e('Select locations', 'userswp'); ?>">
991 - <?php
1394 + echo aui()->input(
1395 + array(
1396 + 'id' => 'placeholder_value_' . esc_attr( $result_str ),
1397 + 'name' => 'placeholder_value',
1398 + 'title' => __( 'Enter placeholder text for this field.', 'userswp' ),
1399 + 'label_type' => 'top',
1400 + 'label' => esc_html__( 'Placeholder', 'userswp' ) . uwp_help_tip( __( 'Display placeholder text for this field.', 'userswp' ) ), // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1401 + 'type' => 'text',
1402 + 'wrap_class' => uwp_advanced_toggle_class(),
1403 + 'value' => $value,
1404 + )
1405 + );
992 1406
993 - $show_in_values = explode(',', $value);
1407 + }
994 1408
995 - foreach ($show_in_locations as $key => $val) {
996 - $selected = '';
1409 + // is_active
1410 + if ( has_filter( "uwp_builder_is_active_{$field_type}" ) ) {
997 1411
998 - if (is_array($show_in_values) && in_array($key, $show_in_values)) {
999 - $selected = 'selected';
1000 - }
1412 + echo apply_filters( "uwp_builder_is_active_{$field_type}", '', $result_str, $cf, $field_info ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1001 1413
1002 - ?>
1003 - <option value="<?php echo $key; ?>" <?php echo $selected; ?>><?php echo $val; ?></option>
1004 - <?php
1005 - }
1006 - ?>
1007 - </select>
1008 - </div>
1009 - </li>
1010 - <?php
1414 + } else {
1415 + $value = '';
1416 + if ( isset( $field_info->is_active ) ) {
1417 + $value = esc_attr( $field_info->is_active );
1418 + } elseif ( isset( $cf['defaults']['is_active'] ) && $cf['defaults']['is_active'] ) {
1419 + $value = $cf['defaults']['is_active'];
1011 1420 }
1012 1421
1422 + echo aui()->input(
1423 + array(
1424 + 'id' => 'is_active',
1425 + 'name' => 'is_active',
1426 + 'type' => 'checkbox',
1427 + 'label_type' => 'horizontal',
1428 + 'label_col' => '4',
1429 + 'label' => __( 'Is active', 'userswp' ),
1430 + 'checked' => $value,
1431 + 'value' => '1',
1432 + 'with_hidden' => '',
1433 + 'switch' => 'md',
1434 + 'label_force_left' => true,
1435 + 'help_text' => uwp_help_tip( __( 'If no is selected then the field will not be displayed anywhere.', 'userswp' ) ),
1436 + )
1437 + );
1013 1438
1439 + }
1014 1440
1015 - switch ($field_type):
1016 - default:
1017 - do_action('uwp_admin_extra_custom_fields', $field_info, $cf); ?>
1441 + // for_admin_use
1442 + if ( has_filter( "uwp_builder_for_admin_use_{$field_type}" ) ) {
1018 1443
1444 + echo apply_filters( "uwp_builder_for_admin_use_{$field_type}", '', $result_str, $cf, $field_info ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1019 1445
1020 - <?php endswitch; ?>
1446 + } else {
1447 + $value = '';
1448 + if ( isset( $field_info->for_admin_use ) ) {
1449 + $value = esc_attr( $field_info->for_admin_use );
1450 + } elseif ( isset( $cf['defaults']['for_admin_use'] ) && $cf['defaults']['for_admin_use'] ) {
1451 + $value = $cf['defaults']['for_admin_use'];
1452 + }
1021 1453
1454 + echo aui()->input(
1455 + array(
1456 + 'id' => 'for_admin_use',
1457 + 'name' => 'for_admin_use',
1458 + 'type' => 'checkbox',
1459 + 'label_type' => 'horizontal',
1460 + 'label_col' => '4',
1461 + 'label' => __( 'For admin use only?', 'userswp' ),
1462 + 'checked' => $value,
1463 + 'value' => '1',
1464 + 'switch' => 'md',
1465 + 'label_force_left' => true,
1466 + 'help_text' => uwp_help_tip( __( 'If yes is selected then only site admin can see and edit this field.', 'userswp' ) ),
1467 + // 'wrap_class' => uwp_advanced_toggle_class(),
1468 + )
1469 + );
1022 1470
1023 - <li>
1471 + }
1024 1472
1025 - <label for="save" class="uwp-tooltip-wrap">
1026 - </label>
1027 - <div class="uwp-input-wrap">
1028 - <input type="button" class="button button-primary" name="save" id="save" value="<?php echo esc_attr(__('Save', 'userswp')); ?>"
1029 - onclick="save_field('<?php echo esc_attr($result_str); ?>')"/>
1030 - <?php if (!$default): ?>
1031 - <a href="javascript:void(0)"><input type="button" name="delete" value="<?php echo esc_attr(__('Delete', 'userswp')); ?>"
1032 - onclick="delete_field('<?php echo esc_attr($result_str); ?>', '<?php echo $nonce; ?>')"
1033 - class="button"/></a>
1034 - <?php endif; ?>
1035 - </div>
1036 - </li>
1037 - </ul>
1038 - </div>
1039 - </form>
1040 - </li>
1041 - <?php
1042 - }
1473 + // is_public
1474 + if ( has_filter( "uwp_builder_is_public_{$field_type}" ) ) {
1043 1475
1044 - public function uwp_form_field_adminhtml($field_type, $result_str, $field_ins_upd = '', $field_type_key = '', $form_type = false)
1045 - {
1046 - global $wpdb;
1047 - $table_name = uwp_get_table_prefix() . 'uwp_form_fields';
1048 - $cf = $result_str;
1049 - if (!is_object($cf)) {
1476 + echo apply_filters( "uwp_builder_is_public_{$field_type}", '', $result_str, $cf, $field_info ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1050 1477
1051 - $field_info = $wpdb->get_row($wpdb->prepare("select * from " . $table_name . " where id= %d", array($cf)));
1478 + } else {
1479 + $value = '';
1480 + if ( isset( $field_info->is_public ) ) {
1481 + $value = esc_attr( $field_info->is_public );
1482 + } elseif ( isset( $cf['defaults']['is_public'] ) && $cf['defaults']['is_public'] ) {
1483 + $value = $cf['defaults']['is_public'];
1484 + }
1052 1485
1053 - } else {
1054 - $field_info = $cf;
1055 - $result_str = $cf->id;
1056 - }
1486 + echo aui()->select(
1487 + array(
1488 + 'id' => 'is_public',
1489 + 'name' => 'is_public',
1490 + 'label_type' => 'top',
1491 + 'multiple' => false,
1492 + 'class' => ' mw-100',
1493 + 'options' => array(
1494 + '1' => __( 'Yes', 'userswp' ),
1495 + '0' => __( 'No', 'userswp' ),
1496 + '2' => __( 'Let User Decide', 'userswp' ),
1497 + ),
1498 + 'label' => __( 'Is Public', 'userswp' ) . uwp_help_tip( __( 'If no is selected then the field will not be visible to other users.', 'userswp' ) ),
1499 + 'value' => $value,
1500 + 'wrap_class' => uwp_advanced_toggle_class(),
1501 + )
1502 + );
1057 1503
1058 - $this->uwp_admin_form_field_html($field_info, $field_type, $field_type_key, $field_ins_upd, $result_str, $form_type);
1504 + }
1059 1505
1060 - }
1061 -
1506 + // default_value
1507 + if ( has_filter( "uwp_builder_default_value_{$field_type}" ) ) {
1062 1508
1063 - public function uwp_admin_form_field_save($request_field = array())
1064 - {
1509 + echo apply_filters( "uwp_builder_default_value_{$field_type}", '', $result_str, $cf, $field_info ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1065 1510
1066 - global $wpdb;
1511 + } else {
1512 + $value = '';
1513 + if ( isset( $field_info->default_value ) ) {
1514 + $value = esc_attr( $field_info->default_value );
1515 + } elseif ( isset( $cf['defaults']['default_value'] ) && $cf['defaults']['default_value'] ) {
1516 + $value = $cf['defaults']['default_value'];
1517 + }
1067 1518
1519 + // tip text
1520 + if ( $field_type == 'checkbox' ) {
1521 + $tip = __( 'Should the checkbox be checked by default?', 'userswp' );
1522 + } elseif ( $field_type == 'email' ) {
1523 + $tip = __( 'A default value for the field, usually blank. Ex: info@mysite.com', 'userswp' );
1524 + } else {
1525 + $tip = __( 'A default value for the field, usually blank. (for links this will be used as the link text)', 'userswp' );
1526 + }
1068 1527
1069 - $table_name = uwp_get_table_prefix() . 'uwp_form_fields';
1528 + if ( $field_type == 'checkbox' ) {
1529 + echo aui()->select(
1530 + array(
1531 + 'id' => 'default_value',
1532 + 'name' => 'default_value',
1533 + 'label_type' => 'top',
1534 + 'multiple' => false,
1535 + 'class' => ' mw-100',
1536 + 'options' => array(
1537 + '' => __( 'Unchecked', 'userswp' ),
1538 + '1' => __( 'Checked', 'userswp' ),
1539 + ),
1540 + 'label' => __( 'Default value', 'userswp' ) . uwp_help_tip( $tip ),
1541 + 'value' => $value,
1542 + 'wrap_class' => uwp_advanced_toggle_class(),
1543 + )
1544 + );
1545 + } else {
1546 + echo aui()->input(
1547 + array(
1548 + 'id' => 'default_value',
1549 + 'name' => 'default_value',
1550 + 'label_type' => 'top',
1551 + 'label' => __( 'Default value', 'userswp' ) . uwp_help_tip( $tip ),
1552 + 'type' => 'text',
1553 + 'wrap_class' => uwp_advanced_toggle_class(),
1554 + 'value' => $value,
1555 + 'placeholder' => $field_type == 'email' ? __( 'info@mysite.com', 'userswp' ) : '',
1556 + )
1557 + );
1558 + }
1559 +}
1070 1560
1071 - $meta_table = get_usermeta_table_prefix() . 'uwp_usermeta';
1561 + // advanced_editor
1562 + if ( has_filter( "uwp_builder_advanced_editor_{$field_type}" ) ) {
1072 1563
1073 - $old_html_variable = '';
1564 + echo apply_filters( "uwp_builder_advanced_editor_{$field_type}", '', $result_str, $cf, $field_info ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1074 1565
1566 + }
1567 + ?>
1568 + <input type="hidden" readonly="readonly" name="sort_order" id="sort_order" value="<?php echo isset( $field_info->sort_order ) ? esc_attr( $field_info->sort_order ) : ''; ?>"/>
1569 + <?php
1075 1570
1076 - $result_str = isset($request_field['field_id']) ? trim($request_field['field_id']) : '';
1571 + // is_required
1572 + if ( has_filter( "uwp_builder_is_required_{$field_type}" ) ) {
1077 1573
1078 - $user_meta_info = null;
1574 + echo apply_filters( "uwp_builder_is_required_{$field_type}", '', $result_str, $cf, $field_info ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1079 1575
1080 - // some servers fail if a POST value is VARCHAR so we change it.
1081 - if (isset($request_field['data_type']) && $request_field['data_type'] == 'XVARCHAR') {
1082 - $request_field['data_type'] = 'VARCHAR';
1083 - }
1084 -
1085 - $cf = trim($result_str, '_');
1576 + } else {
1577 + $value = '';
1578 + if ( isset( $field_info->is_required ) ) {
1579 + $value = esc_attr( $field_info->is_required );
1580 + } elseif ( isset( $cf['defaults']['is_required'] ) && $cf['defaults']['is_required'] ) {
1581 + $value = $cf['defaults']['is_required'];
1582 + }
1086 1583
1584 + echo aui()->input(
1585 + array(
1586 + 'id' => 'is_required',
1587 + 'name' => 'is_required',
1588 + 'type' => 'checkbox',
1589 + 'label_type' => 'horizontal',
1590 + 'label_col' => '4',
1591 + 'label' => __( 'Is required', 'userswp' ),
1592 + 'checked' => $value,
1593 + 'value' => '1',
1594 + 'switch' => 'md',
1595 + 'label_force_left' => true,
1596 + 'help_text' => uwp_help_tip( __( 'Select yes to set field as required', 'userswp' ) ),
1597 + // 'wrap_class' => uwp_advanced_toggle_class(),
1598 + )
1599 + );
1087 1600
1088 - $cehhtmlvar_name = isset($request_field['htmlvar_name']) ? $request_field['htmlvar_name'] : '';
1089 - $form_type = $request_field['form_type'];
1601 + }
1090 1602
1091 - if ($request_field['field_type'] != 'fieldset') {
1092 - $cehhtmlvar_name = 'uwp_' . $form_type . '_' . $cehhtmlvar_name;
1093 - }
1603 + // required_msg
1604 + if ( has_filter( "uwp_builder_required_msg_{$field_type}" ) ) {
1094 1605
1095 - $check_html_variable = $wpdb->get_var(
1096 - $wpdb->prepare(
1097 - "select htmlvar_name from " . $table_name . " where id <> %d and htmlvar_name = %s and form_type = %s ",
1098 - array($cf, $cehhtmlvar_name, $form_type)
1099 - )
1100 - );
1606 + echo apply_filters( "uwp_builder_required_msg_{$field_type}", '', $result_str, $cf, $field_info ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1101 1607
1608 + } else {
1609 + $value = '';
1610 + if ( isset( $field_info->required_msg ) ) {
1611 + $value = esc_attr( $field_info->required_msg );
1612 + } elseif ( isset( $cf['defaults']['required_msg'] ) && $cf['defaults']['required_msg'] ) {
1613 + $value = $cf['defaults']['required_msg'];
1614 + }
1102 1615
1103 - if (!$check_html_variable || $request_field['field_type'] == 'fieldset') {
1616 + echo aui()->input(
1617 + array(
1618 + 'id' => 'required_msg',
1619 + 'name' => 'required_msg',
1620 + 'label_type' => 'top',
1621 + 'label' => __( 'Required message', 'userswp' ) . uwp_help_tip( __( 'Enter text for the error message if the field is required and has not fulfilled the requirements.', 'userswp' ) ),
1622 + 'type' => 'text',
1623 + 'wrap_class' => uwp_advanced_toggle_class(),
1624 + 'value' => $value,
1625 + 'element_require' => '[%is_required%:checked]',
1626 + )
1627 + );
1104 1628
1105 - if ($cf != '') {
1629 + }
1106 1630
1107 - $user_meta_info = $wpdb->get_row(
1108 - $wpdb->prepare(
1109 - "select * from " . $table_name . " where id = %d",
1110 - array($cf)
1111 - )
1112 - );
1631 + // validation pattern
1632 + if ( has_filter( "uwp_builder_validation_pattern_{$field_type}" ) ) {
1113 1633
1114 - }
1634 + echo apply_filters( "uwp_builder_validation_pattern_{$field_type}", '', $result_str, $cf, $field_info ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1115 1635
1116 - if (!empty($user_meta_info)) {
1117 - $old_html_variable = $user_meta_info->htmlvar_name;
1636 + }
1118 1637
1119 - }
1638 + // extra_fields
1639 + if ( has_filter( "uwp_builder_extra_fields_{$field_type}" ) ) {
1120 1640
1641 + echo apply_filters( "uwp_builder_extra_fields_{$field_type}", '', $result_str, $cf, $field_info ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1121 1642
1122 - $site_title = $request_field['site_title'];
1123 - $form_label = isset($request_field['form_label']) ? $request_field['form_label'] : '';
1124 - $field_type = $request_field['field_type'];
1125 - $data_type = $request_field['data_type'];
1126 - $field_type_key = isset($request_field['field_type_key']) ? $request_field['field_type_key'] : $field_type;
1127 - $htmlvar_name = isset($request_field['htmlvar_name']) ? $request_field['htmlvar_name'] : '';
1128 - $default_value = isset($request_field['default_value']) ? $request_field['default_value'] : '';
1129 - $sort_order = isset($request_field['sort_order']) ? $request_field['sort_order'] : '';
1130 - $is_active = isset($request_field['is_active']) ? $request_field['is_active'] : '';
1131 - $for_admin_use = isset($request_field['for_admin_use']) ? $request_field['for_admin_use'] : '';
1132 - $is_required = isset($request_field['is_required']) ? $request_field['is_required'] : '';
1133 - $is_dummy = isset($request_field['is_dummy']) ? $request_field['is_dummy'] : '';
1134 - $is_public = isset($request_field['is_public']) ? $request_field['is_public'] : '';
1135 - $is_register_field = isset($request_field['is_register_field']) ? $request_field['is_register_field'] : '';
1136 - $is_search_field = isset($request_field['is_search_field']) ? $request_field['is_search_field'] : '';
1137 - $is_register_only_field = isset($request_field['is_register_only_field']) ? $request_field['is_register_only_field'] : '';
1138 - $required_msg = isset($request_field['required_msg']) ? $request_field['required_msg'] : '';
1139 - $css_class = isset($request_field['css_class']) ? $request_field['css_class'] : '';
1140 - $field_icon = isset($request_field['field_icon']) ? $request_field['field_icon'] : '';
1141 - $show_in = isset($request_field['show_in']) ? $request_field['show_in'] : '';
1142 - $user_roles = isset($request_field['user_roles']) ? $request_field['user_roles'] : '';
1143 - $decimal_point = isset($request_field['decimal_point']) ? trim($request_field['decimal_point']) : ''; // decimal point for DECIMAL data type
1144 - $decimal_point = $decimal_point > 0 ? ($decimal_point > 10 ? 10 : $decimal_point) : '';
1145 - $validation_pattern = isset($request_field['validation_pattern']) ? $request_field['validation_pattern'] : '';
1146 - $validation_msg = isset($request_field['validation_msg']) ? $request_field['validation_msg'] : '';
1643 + }
1147 1644
1645 + // field_icon
1646 + if ( has_filter( "uwp_builder_field_icon_{$field_type}" ) ) {
1148 1647
1149 - if (is_array($show_in)) {
1150 - $show_in = implode(",", $request_field['show_in']);
1151 - }
1648 + echo apply_filters( "uwp_builder_field_icon_{$field_type}", '', $result_str, $cf, $field_info ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1152 1649
1153 - if (is_array($user_roles)) {
1154 - $user_roles = implode(",", $request_field['user_roles']);
1155 - }
1650 + } else {
1651 + $value = '';
1652 + if ( isset( $field_info->field_icon ) ) {
1653 + $value = esc_attr( $field_info->field_icon );
1654 + } elseif ( isset( $cf['defaults']['field_icon'] ) && $cf['defaults']['field_icon'] ) {
1655 + $value = $cf['defaults']['field_icon'];
1656 + }
1156 1657
1157 - // fieldset need htmlvar_name for register tab
1158 - $htmlvar_name = 'uwp_' . $form_type . '_' . $htmlvar_name;
1658 + echo aui()->input(
1659 + array(
1660 + 'id' => 'field_icon',
1661 + 'name' => 'field_icon',
1662 + 'label_type' => 'top',
1663 + 'label' => __( 'Icon', 'userswp' ) . uwp_help_tip( sprintf( __( 'Upload icon using media and enter its url path, or enter %1$sfont awesome%2$s class eg:"fas fa-home"', 'userswp' ), '<a href="http://fortawesome.github.io/Font-Awesome/icons/" target="_blank" >', '</a>' ) ),
1664 + 'type' => 'iconpicker',
1665 + 'wrap_class' => uwp_advanced_toggle_class(),
1666 + 'value' => $value,
1667 + 'extra_attributes' => defined( 'FAS_PRO' ) && FAS_PRO ? array(
1668 + 'data-fa-icons' => true,
1669 + 'data-bs-toggle' => 'tooltip',
1670 + 'data-bs-trigger' => 'focus',
1671 + 'title' => __( 'For pro icon variants (light, thin, duotone), paste the class here', 'userswp' ),
1672 + ) : array(),
1673 + )
1674 + );
1159 1675
1676 + }
1160 1677
1161 - $option_values = '';
1162 - if (isset($request_field['option_values']))
1163 - $option_values = $request_field['option_values'];
1678 + // css_class
1679 + if ( has_filter( "uwp_builder_css_class_{$field_type}" ) ) {
1164 1680
1165 - if (isset($request_field['extra']) && !empty($request_field['extra']))
1166 - $extra_fields = $request_field['extra'];
1681 + echo apply_filters( "uwp_builder_css_class_{$field_type}", '', $result_str, $cf, $field_info ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1167 1682
1168 - if (isset($request_field['is_default']) && $request_field['is_default'] != '')
1169 - $is_default = $request_field['is_default'];
1170 - else
1171 - $is_default = '0';
1683 + } else {
1172 1684
1173 - if ($is_active == '') $is_active = 1;
1174 - if ($for_admin_use == '') $for_admin_use = 0;
1175 - if ($is_required == '') $is_required = 0;
1176 - if ($is_dummy == '') $is_dummy = 0;
1177 - if ($is_public == '') $is_public = 0;
1178 - if ($is_register_field == '') $is_register_field = 0;
1179 - if ($is_search_field == '') $is_search_field = 0;
1180 - if ($is_register_only_field == '') $is_register_only_field = 0;
1685 + $value = '';
1686 + if ( isset( $field_info->css_class ) ) {
1687 + $value = esc_attr( $field_info->css_class );
1688 + } elseif ( isset( $cf['defaults']['css_class'] ) && $cf['defaults']['css_class'] ) {
1689 + $value = $cf['defaults']['css_class'];
1690 + }
1691 + $tip = __( 'Enter custom css class for field custom style.', 'userswp' );
1692 + if ( $field_type == 'multiselect' ) {
1693 + $tip .= __( '(Enter class `uwp-comma-list` to show list as comma separated)', 'userswp' );
1694 + }
1181 1695
1696 + echo aui()->input(
1697 + array(
1698 + 'id' => 'css_class',
1699 + 'name' => 'css_class',
1700 + 'label_type' => 'top',
1701 + 'label' => __( 'CSS class', 'userswp' ) . uwp_help_tip( $tip ),
1702 + 'type' => 'text',
1703 + 'wrap_class' => uwp_advanced_toggle_class(),
1704 + 'value' => $value,
1705 + )
1706 + );
1182 1707
1183 - if ($sort_order == '') {
1708 + }
1184 1709
1185 - $last_order = $wpdb->get_var("SELECT MAX(sort_order) as last_order FROM " . $table_name);
1710 + // show_in
1711 + if ( has_filter( "uwp_builder_show_in_{$field_type}" ) ) {
1712 + echo apply_filters( "uwp_builder_show_in_$field_type}", '', $result_str, $cf, $field_info ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1713 + echo apply_filters( "uwp_builder_show_in_$field_type}", '', $result_str, $cf, $field_info ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1186 1714
1187 - $sort_order = (int) $last_order + 1;
1188 - }
1189 -
1190 - if (!empty($user_meta_info)) {
1715 + echo apply_filters( "uwp_builder_show_in_$field_type}", '', $result_str, $cf, $field_info ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1191 1716
1192 - $excluded = uwp_get_excluded_fields();
1717 + } else {
1718 + $value = '';
1719 + if ( isset( $field_info->show_in ) ) {
1720 + $value = esc_attr( $field_info->show_in );
1721 + } elseif ( isset( $cf['defaults']['show_in'] ) && $cf['defaults']['show_in'] ) {
1722 + $value = esc_attr( $cf['defaults']['show_in'] );
1723 + }
1193 1724
1194 - $starts_with = "uwp_account_";
1725 + $show_in_locations = uwp_get_show_in_locations();
1195 1726
1196 - if ((substr($htmlvar_name, 0, strlen($starts_with)) === $starts_with) && !in_array($htmlvar_name, $excluded)) {
1197 - // Create custom columns
1198 - switch ($field_type):
1727 + if ( $field_type == 'fieldset' ) {
1728 + unset( $show_in_locations['[fieldset]'] );
1729 + }
1199 1730
1200 - case 'checkbox':
1201 - case 'multiselect':
1202 - case 'select':
1731 + if ( ! in_array(
1732 + $field_type,
1733 + array(
1734 + 'text',
1735 + 'datepicker',
1736 + 'textarea',
1737 + 'time',
1738 + 'phone',
1739 + 'email',
1740 + 'select',
1741 + 'multiselect',
1742 + 'url',
1743 + 'html',
1744 + 'fieldset',
1745 + 'radio',
1746 + 'checkbox',
1747 + 'file',
1748 + )
1749 + ) ) {
1750 + unset( $show_in_locations['[own_tab]'] );
1751 + }
1203 1752
1204 - $op_size = '500';
1753 + $show_in_values = $value ? explode( ',', $value ) : '';
1205 1754
1206 - // only make the field as big as it needs to be.
1207 - if (isset($option_values) && $option_values && $field_type == 'select') {
1208 - $option_values_arr = explode(',', $option_values);
1209 - if (is_array($option_values_arr)) {
1210 - $op_max = 0;
1211 - foreach ($option_values_arr as $op_val) {
1212 - if (strlen($op_val) && strlen($op_val) > $op_max) {$op_max = strlen($op_val); }
1213 - }
1214 - if ($op_max) {$op_size = $op_max; }
1215 - }
1216 - }elseif (isset($option_values) && $option_values && $field_type == 'multiselect') {
1217 - if (strlen($option_values)) {
1218 - $op_size = strlen($option_values);
1219 - }
1220 - }
1755 + echo aui()->select(
1756 + array(
1757 + 'id' => 'show_in',
1758 + 'name' => 'show_in[]',
1759 + 'label_type' => 'top',
1760 + 'multiple' => true,
1761 + 'select2' => true,
1762 + 'class' => ' mw-100',
1763 + 'options' => $show_in_locations,
1764 + 'label' => __( 'Show in what locations?', 'userswp' ) . uwp_help_tip( __( 'Select in what locations you want to display this field.', 'userswp' ) ),
1765 + 'value' => $show_in_values,
1766 + 'placeholder' => __( 'Select locations', 'userswp' ),
1767 + )
1768 + );
1221 1769
1222 - $meta_field_add = "ALTER TABLE " . $meta_table . " CHANGE `" . $old_html_variable . "` `" . $htmlvar_name . "`VARCHAR( $op_size ) NULL";
1770 + }
1223 1771
1224 - if ($default_value != '') {
1225 - $meta_field_add .= " DEFAULT '" . $default_value . "'";
1226 - }
1772 + do_action( 'uwp_admin_extra_custom_fields', $field_info, $cf );
1773 + ?>
1227 1774
1228 - $alter_result = $wpdb->query($meta_field_add);
1229 - if ($alter_result === false) {
1230 - return __('Column change failed, you may have too many columns.', 'userswp');
1231 - }
1232 1775
1233 - if (isset($request_field['cat_display_type']))
1234 - $extra_fields = $request_field['cat_display_type'];
1776 + <div class="uwp-input-wrap uwp-tab-actions" data-setting="save_button">
1235 1777
1236 - if (isset($request_field['multi_display_type']))
1237 - $extra_fields = $request_field['multi_display_type'];
1778 + <span class="text-left text-start float-left float-start">
1779 + <?php UsersWP_Settings_Page::toggle_advanced_button( 'btn btn-outline-primary text-left text-start uwp-advanced-toggle', false ); ?>
1780 + </span>
1238 1781
1782 + <a class=" btn btn-link text-muted" href="javascript:void(0);" onclick="uwp_tabs_close_settings(this); return false;"><?php _e( 'Close', 'userswp' ); ?></a>
1783 + <a href='javascript:void(0);' type="button" class="btn btn-primary" id="save"
1784 + onclick="save_field('<?php echo esc_attr( $result_str ); ?>');"><?php echo esc_attr( __( 'Save', 'userswp' ) ); ?></a>
1785 + </div>
1786 + </script>
1787 + </div>
1788 + </li>
1789 + <?php
1790 + }
1239 1791
1240 - break;
1792 + /**
1793 + * Add HTML5 validation pattern fields.
1794 + *
1795 + * @since 1.2.2.17
1796 + *
1797 + * @param string $output Html output.
1798 + * @param string $result_str Result string.
1799 + * @param array $cf Custom fields values.
1800 + * @param object $field_info Extra fields information.
1801 + * @return string $output.
1802 + */
1803 + public static function validation_pattern( $output, $result_str, $cf, $field_info ) {
1804 + ob_start();
1241 1805
1242 - case 'textarea':
1243 - case 'html':
1244 - case 'url':
1245 - case 'file':
1806 + $value = '';
1807 + if ( isset( $field_info->validation_pattern ) ) {
1808 + $value = esc_attr( $field_info->validation_pattern );
1809 + } elseif ( isset( $cf['defaults']['validation_pattern'] ) && $cf['defaults']['validation_pattern'] ) {
1810 + $value = $cf['defaults']['validation_pattern'];
1811 + }
1246 1812
1247 - $alter_result = $wpdb->query("ALTER TABLE " . $meta_table . " CHANGE `" . $old_html_variable . "` `" . $htmlvar_name . "` TEXT NULL");
1248 - if ($alter_result === false) {
1249 - return __('Column change failed, you may have too many columns.', 'userswp');
1250 - }
1251 - if (isset($request_field['advanced_editor']))
1252 - $extra_fields = $request_field['advanced_editor'];
1813 + echo aui()->input(
1814 + array(
1815 + 'id' => 'validation_pattern',
1816 + 'name' => 'validation_pattern',
1817 + 'label_type' => 'top',
1818 + 'label' => __( 'Validation Pattern', 'userswp' ) . uwp_help_tip( __( 'Enter regex expression for HTML5 pattern validation.', 'userswp' ) ),
1819 + 'type' => 'text',
1820 + 'wrap_class' => uwp_advanced_toggle_class(),
1821 + 'value' => addslashes_gpc( $value ), // Keep slashes
1822 + )
1823 + );
1253 1824
1254 - break;
1825 + $value = '';
1826 + if ( isset( $field_info->validation_msg ) ) {
1827 + $value = esc_attr( $field_info->validation_msg );
1828 + } elseif ( isset( $cf['defaults']['validation_msg'] ) && $cf['defaults']['validation_msg'] ) {
1829 + $value = $cf['defaults']['validation_msg'];
1830 + }
1255 1831
1256 - case 'fieldset':
1257 - // Nothing happened for fieldset
1258 - break;
1832 + echo aui()->input(
1833 + array(
1834 + 'id' => 'validation_msg',
1835 + 'name' => 'validation_msg',
1836 + 'label_type' => 'top',
1837 + 'label' => __( 'Validation Message', 'userswp' ) . uwp_help_tip( __( 'Enter a extra validation message to show to the user if validation fails.', 'userswp' ) ),
1838 + 'type' => 'text',
1839 + 'wrap_class' => uwp_advanced_toggle_class(),
1840 + 'value' => $value,
1841 + )
1842 + );
1259 1843
1260 - default:
1261 - if ($data_type != 'VARCHAR' && $data_type != '') {
1262 - if ($data_type == 'FLOAT' && $decimal_point > 0) {
1263 - $default_value_add = "ALTER TABLE " . $meta_table . " CHANGE `" . $old_html_variable . "` `" . $htmlvar_name . "` DECIMAL(11, " . (int) $decimal_point . ") NULL";
1264 - } else {
1265 - $default_value_add = "ALTER TABLE " . $meta_table . " CHANGE `" . $old_html_variable . "` `" . $htmlvar_name . "` " . $data_type . " NULL";
1266 - }
1844 + $output = ob_get_clean();
1267 1845
1268 - if (is_numeric($default_value) && $default_value != '') {
1269 - $default_value_add .= " DEFAULT '" . $default_value . "'";
1270 - }
1271 - } else {
1272 - $default_value_add = "ALTER TABLE " . $meta_table . " CHANGE `" . $old_html_variable . "` `" . $htmlvar_name . "` VARCHAR( 254 ) NULL";
1273 - if ($default_value != '') {
1274 - $default_value_add .= " DEFAULT '" . $default_value . "'";
1275 - }
1276 - }
1846 + return $output;
1847 + }
1277 1848
1278 - $alter_result = $wpdb->query($default_value_add);
1279 - if ($alter_result === false) {
1280 - return __('Column change failed, you may have too many columns.', 'userswp');
1281 - }
1282 - break;
1283 - endswitch;
1849 + public function register_selected_fields( $form_type ) {
1850 + global $wpdb;
1851 + $extras_table_name = uwp_get_table_prefix() . 'uwp_form_extras';
1852 + $form_id = self::get_form_id()
1853 + ?>
1854 + <input type="hidden" name="manage_field_type" class="manage_field_type" value="register">
1855 + <ul class="core uwp_form_extras uwp-tabs-selected ps-0 list-group ">
1856 + <?php
1857 +
1858 + $fields = $wpdb->get_results(
1859 + $wpdb->prepare(
1860 + 'select * from ' . $extras_table_name . ' where form_type = %s AND form_id = %d order by sort_order asc',
1861 + array( $form_type, $form_id )
1862 + )
1863 + );
1864 +
1865 + if ( ! empty( $fields ) ) {
1866 + foreach ( $fields as $field ) {
1867 + $result_str = $field;
1868 + $field_ins_upd = 'display';
1869 + $this->register_field_adminhtml( $result_str, $field_ins_upd, false );
1284 1870 }
1871 + }
1872 + ?>
1873 + </ul>
1874 + <?php
1875 + }
1285 1876
1286 - $extra_field_query = '';
1287 - if (!empty($extra_fields)) {
1288 - $extra_field_query = serialize($extra_fields);
1289 - }
1877 + public function register_field_adminhtml( $result_str, $field_ins_upd = '', $default = false, $request = array() ) {
1878 + global $wpdb;
1290 1879
1291 - $wpdb->query(
1880 + $table_name = uwp_get_table_prefix() . 'uwp_form_fields';
1881 + $extras_table_name = uwp_get_table_prefix() . 'uwp_form_extras';
1292 1882
1293 - $wpdb->prepare(
1883 + $cf = $result_str;
1884 + if ( ! is_object( $cf ) && ( is_int( $cf ) || ctype_digit( $cf ) ) ) {
1885 + $field_info = $wpdb->get_row( $wpdb->prepare( 'select * from ' . $extras_table_name . ' where id= %d', array( $cf ) ) );
1886 + } elseif ( is_object( $cf ) ) {
1887 + $result_str = $cf->id;
1888 + $field_info = $wpdb->get_row( $wpdb->prepare( 'select * from ' . $extras_table_name . ' where id= %d', array( (int) $cf->id ) ) );
1889 + } else {
1890 + $field_info = false;
1891 + }
1294 1892
1295 - "update " . $table_name . " set
1296 - form_type = %s,
1297 - site_title = %s,
1298 - form_label = %s,
1299 - field_type = %s,
1300 - data_type = %s,
1301 - decimal_point = %s,
1302 - field_type_key = %s,
1303 - htmlvar_name = %s,
1304 - default_value = %s,
1305 - sort_order = %s,
1306 - is_active = %s,
1307 - for_admin_use = %s,
1308 - is_default = %s,
1309 - is_required = %s,
1310 - is_dummy = %s,
1311 - is_public = %s,
1312 - is_register_field = %s,
1313 - is_search_field = %s,
1314 - is_register_only_field = %s,
1315 - required_msg = %s,
1316 - css_class = %s,
1317 - field_icon = %s,
1318 - field_icon = %s,
1319 - show_in = %s,
1320 - user_roles = %s,
1321 - option_values = %s,
1322 - extra_fields = %s,
1323 - validation_pattern = %s,
1324 - validation_msg = %s
1325 - where id = %d",
1893 + if ( isset( $request['field_type'] ) && $request['field_type'] != '' ) {
1894 + $field_type = esc_attr( $request['field_type'] );
1895 + } else {
1896 + $field_type = $field_info->field_type;
1897 + }
1326 1898
1327 - array(
1328 - $form_type,
1329 - $site_title,
1330 - $form_label,
1331 - $field_type,
1332 - $data_type,
1333 - $decimal_point,
1334 - $field_type_key,
1335 - $htmlvar_name,
1336 - $default_value,
1337 - $sort_order,
1338 - $is_active,
1339 - $for_admin_use,
1340 - $is_default,
1341 - $is_required,
1342 - $is_dummy,
1343 - $is_public,
1344 - $is_register_field,
1345 - $is_search_field,
1346 - $is_register_only_field,
1347 - $required_msg,
1348 - $css_class,
1349 - $field_icon,
1350 - $field_icon,
1351 - $show_in,
1352 - $user_roles,
1353 - $option_values,
1354 - $extra_field_query,
1355 - $validation_pattern,
1356 - $validation_msg,
1357 - $cf
1358 - )
1359 - )
1899 + $field_site_name = '';
1900 + if ( isset( $request['site_title'] ) ) {
1901 + $field_site_name = $request['site_title'];
1902 + }
1360 1903
1361 - );
1904 + if ( $field_info ) {
1905 + $account_field_info = uwp_get_custom_field_info( $field_info->site_htmlvar_name );
1906 + if ( isset( $account_field_info->site_title ) ) {
1907 + if ( $account_field_info->field_type == 'fieldset' ) {
1908 + $field_site_name = __( 'Fieldset:', 'userswp' ) . ' ' . $account_field_info->site_title;
1909 + } else {
1910 + $field_site_name = $account_field_info->site_title;
1911 + }
1912 + }
1913 + $field_info = stripslashes_deep( $field_info ); // strip slashes
1914 + }
1915 + $field_site_name = sanitize_title( $field_site_name );
1362 1916
1363 - $lastid = trim($cf);
1917 + if ( isset( $request['form_type'] ) ) {
1918 + $form_type = esc_attr( $request['form_type'] );
1919 + } else {
1920 + $form_type = $field_info->form_type;
1921 + }
1364 1922
1923 + if ( isset( $request['htmlvar_name'] ) && $request['htmlvar_name'] != '' ) {
1924 + $htmlvar_name = esc_attr( $request['htmlvar_name'] );
1925 + } else {
1926 + $htmlvar_name = $field_info->site_htmlvar_name;
1927 + }
1365 1928
1366 - do_action('uwp_after_custom_fields_updated', $lastid);
1929 + if ( isset( $htmlvar_name ) ) {
1930 + if ( ! is_object( $field_info ) ) {
1931 + $field_info = new stdClass();
1932 + }
1933 + $field_info->field_icon = $wpdb->get_var(
1934 + $wpdb->prepare( 'SELECT field_icon FROM ' . $table_name . ' WHERE htmlvar_name = %s', array( $htmlvar_name ) )
1935 + );
1936 + }
1367 1937
1368 - } else {
1938 + $icon = isset( $field_info->field_icon ) ? $field_info->field_icon : '';
1939 + if ( uwp_is_fa_icon( $icon ) ) {
1940 + $field_icon = '<i class="' . esc_attr( $icon ) . '" aria-hidden="true"></i>';
1941 + } elseif ( uwp_is_icon_url( $icon ) ) {
1942 + $field_icon = '<b style="background-image: url("' . esc_url( $icon ) . '")"></b>';
1943 + } elseif ( isset( $field_info->field_type ) && $field_info->field_type == 'fieldset' ) {
1944 + $field_icon = '<i class="fas fa-arrows-alt-h" aria-hidden="true"></i>';
1945 + } else {
1946 + $field_icon = '<i class="fas fa-cog" aria-hidden="true"></i>';
1947 + }
1369 1948
1370 - switch ($field_type):
1949 + $no_actions = array( 'email' );
1950 + $no_actions = apply_filters( 'uwp_register_fields_without_actions', $no_actions );
1951 + ?>
1952 + <li class="text li-settings" id="licontainer_<?php echo esc_attr( $result_str ); ?>">
1953 + <form>
1954 + <div class="title title<?php echo esc_attr( $result_str ); ?> uwp-fieldset hover-shadow dd-form d-flex justify-content-between rounded list-group-item border rounded-smx text-start bg-light">
1955 + <?php
1956 + $nonce = wp_create_nonce( 'uwp_form_extras_nonce' . $result_str );
1957 + ?>
1958 + <div class=" flex-fill font-weight-bold fw-bold">
1959 + <?php echo $field_icon; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
1960 + <b><?php echo esc_html( uwp_ucwords( ' ' . $field_site_name ) ); ?></b>
1961 + </div>
1962 + <div class="dd-handle ui-sortable-handle">
1963 + <?php if ( isset( $htmlvar_name ) && ! in_array( $htmlvar_name, $no_actions ) ) { ?>
1964 + <i class="far fa-trash-alt text-danger ml-2 ms-2 c-pointer" id="delete-16"
1965 + onclick="delete_field('<?php echo esc_js( $result_str ); ?>', '<?php echo esc_js( $nonce ); ?>','<?php echo esc_js( $htmlvar_name ); ?>', 'register')"
1966 + ></i>
1967 + <?php } ?>
1968 + <i class="fas fa-grip-vertical text-muted ml-2 ms-2" style="cursor: move" aria-hidden="true"></i>
1969 + </div>
1970 + </div>
1371 1971
1372 - case 'checkbox':
1373 - $data_type = 'TINYINT';
1972 + <div id="field_frm<?php echo esc_attr( $result_str ); ?>" class="field_frm" style="display:none;">
1973 + <input type="hidden" name="_wpnonce" value="<?php echo esc_attr( $nonce ); ?>"/>
1974 + <input type="hidden" name="field_id" id="field_id" value="<?php echo esc_attr( $result_str ); ?>"/>
1975 + <input type="hidden" name="form_type" id="form_type" value="<?php echo esc_attr( $form_type ); ?>"/>
1976 + <input type="hidden" name="field_type" id="field_type" value="<?php echo esc_attr( $field_type ); ?>"/>
1977 + <input type="hidden" name="is_active" id="is_active" value="1"/>
1978 + <ul class="widefat post fixed" style="width:100%;">
1374 1979
1375 - $meta_field_add = $data_type . "( 1 ) NOT NULL ";
1376 - if ((int) $default_value === 1) {
1377 - $meta_field_add .= " DEFAULT '1'";
1378 - }
1980 + <input type="hidden" name="site_htmlvar_name" value="<?php echo esc_attr( $htmlvar_name ); ?>"/>
1379 1981
1380 - $add_result = uwp_add_column_if_not_exist($meta_table, $htmlvar_name, $meta_field_add);
1381 - if ($add_result === false) {
1382 - return __('Column creation failed, you may have too many columns or the default value does not match with field data type.', 'userswp');
1383 - }
1384 - break;
1385 - case 'multiselect':
1386 - case 'select':
1387 - $data_type = 'VARCHAR';
1388 - $op_size = '500';
1982 + <li>
1983 + <div class="uwp-input-wrap">
1984 + <p><?php esc_html_e( 'No options available', 'userswp' ); ?></p>
1985 + </div>
1986 + </li>
1389 1987
1390 - // only make the field as big as it needs to be.
1391 - if (isset($option_values) && $option_values && $field_type == 'select') {
1392 - $option_values_arr = explode(',', $option_values);
1988 + <li>
1989 + <div class="uwp-input-wrap">
1990 + <?php if ( isset( $htmlvar_name ) && ! in_array( $htmlvar_name, $no_actions ) ) { ?>
1991 + <input type="button" class="button button-primary" name="save" id="save"
1992 + value="<?php esc_attr_e( 'Save', 'userswp' ); ?>"
1993 + onclick="save_field('<?php echo esc_js( $result_str ); ?>', 'register')"
1994 + style="display: none;"/>
1995 + <input type="button" name="delete"
1996 + value="<?php esc_attr_e( 'Delete', 'userswp' ); ?>"
1997 + onclick="delete_field('<?php echo esc_js( $result_str ); ?>', '<?php echo esc_js( $nonce ); ?>','<?php echo esc_js( $htmlvar_name ); ?>', 'register')"
1998 + class="button"/>
1999 + <?php } ?>
1393 2000
1394 - if (is_array($option_values_arr)) {
1395 - $op_max = 0;
2001 + </div>
2002 + </li>
2003 + </ul>
1396 2004
1397 - foreach ($option_values_arr as $op_val) {
1398 - if (strlen($op_val) && strlen($op_val) > $op_max) {
1399 - $op_max = strlen($op_val);
1400 - }
1401 - }
2005 + </div>
2006 + </form>
2007 + </li>
2008 + <?php
2009 + }
1402 2010
1403 - if ($op_max) {
1404 - $op_size = $op_max;
1405 - }
1406 - }
1407 - } elseif (isset($option_values) && $option_values && $field_type == 'multiselect') {
1408 - if (strlen($option_values)) {
1409 - $op_size = strlen($option_values);
1410 - }
2011 + public function builder_extra_fields_smr( $output, $result_str, $cf, $field_info ) {
1411 2012
1412 - if (isset($request_field['multi_display_type'])) {
1413 - $extra_fields = $request_field['multi_display_type'];
1414 - }
1415 - }
2013 + ob_start();
1416 2014
1417 - $meta_field_add = $data_type . "( $op_size ) NULL ";
1418 - if ($default_value != '') {
1419 - $meta_field_add .= " DEFAULT '" . $default_value . "'";
1420 - }
2015 + $value = '';
2016 + if ( isset( $field_info->option_values ) ) {
2017 + $value = esc_attr( $field_info->option_values );
2018 + } elseif ( isset( $cf['defaults']['option_values'] ) && $cf['defaults']['option_values'] ) {
2019 + $value = esc_attr( $cf['defaults']['option_values'] );
2020 + }
1421 2021
1422 - $add_result = uwp_add_column_if_not_exist($meta_table, $htmlvar_name, $meta_field_add);
1423 - if ($add_result === false) {
1424 - return __('Column creation failed, you may have too many columns or the default value does not match with field data type.', 'userswp');
1425 - }
1426 - break;
1427 - case 'textarea':
1428 - case 'html':
1429 - case 'url':
1430 - case 'file':
2022 + $field_type = isset( $field_info->field_type ) ? $field_info->field_type : $cf['field_type'];
2023 + $field_type_key = isset( $field_info->field_type_key ) ? $field_info->field_type_key : '';
2024 + if ( ! $field_type_key ) {
2025 + $field_type_key = isset( $_REQUEST['field_type_key'] ) ? esc_html( $_REQUEST['field_type_key'] ) : '';
2026 + }
2027 + ?>
2028 + <div class="uwp-setting-name mb-3">
2029 + <label for="option_values" class=" form-label">
2030 + <?php
2031 + $tip = __( 'Option Values should be separated by comma.', 'userswp' );
2032 + if ( $field_type != 'multiselect' ) {
2033 + $tip .= '<br/><small>' . __( 'If using for a tick filter place a / and then either a 1 for true or 0 for false', 'userswp' );
2034 + $tip .= '<br/>' . __( 'eg: No Dogs Allowed/0,Dogs Allowed/1', 'userswp' ) . '</small>';
2035 + }
2036 + if ( $field_type == 'multiselect' || $field_type == 'select' ) {
2037 + $tip .= '<br/><small>' . __( 'Like: Apple,Bannana,Pear,Peach', 'userswp' );
2038 + $tip .= '<br/>' . __( 'Or you can show Selection/Value shown: Pets Allowed/Yes,Pets not Allowed/No', 'userswp' );
2039 + $tip .= '<br/>' . __( '- If using OPTGROUP tag to grouping options, use {optgroup}OPTGROUP-LABEL|OPTION-1,OPTION-2{/optgroup}', 'userswp' );
2040 + $tip .= '<br/>' . __( 'eg: {optgroup}Pets Allowed|No Dogs Allowed/0,Dogs Allowed/1{/optgroup},{optgroup}Sports|Cricket/Cricket,Football/Football,Hockey{/optgroup}', 'userswp' ) . '</small>';
2041 + }
2042 + ?>
2043 + <?php
2044 + echo uwp_help_tip( $tip ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
2045 + esc_html_e( 'Option Values :', 'userswp' );
2046 + ?>
2047 + </label>
2048 + <div class="uwp-input-wrap">
1431 2049
1432 - $data_type = 'TEXT';
2050 + <?php
2051 + if ( isset( $field_type_key ) && $field_type_key == 'uwp_country' ) {
2052 + // @todo here we should show a multiselect to either include or exclude countries
2053 + echo aui()->alert(
2054 + array(
2055 + 'type' => 'info',
2056 + 'content' => esc_html__( 'A full country list will be shown', 'userswp' ),
2057 + )
2058 + );
1433 2059
1434 - $meta_field_add = $data_type . " NULL ";
2060 + } elseif ( isset( $field_type_key ) && $field_type_key == 'uwp_language' ) {
2061 + echo aui()->alert(
2062 + array(
2063 + 'type' => 'info',
2064 + 'content' => esc_html__( 'Available translation languages list will be shown', 'userswp' ),
2065 + )
2066 + );
2067 + } else {
2068 + ?>
2069 + <input type="text" name="option_values" id="option_values" class="form-control" value="<?php echo esc_attr( $value ); ?>"/>
2070 + <?php } ?>
1435 2071
1436 - $add_result = uwp_add_column_if_not_exist($meta_table, $htmlvar_name, $meta_field_add);
1437 - if ($add_result === false) {
1438 - return __('Column creation failed, you may have too many columns or the default value does not match with field data type.', 'userswp');
1439 - }
2072 + <br/>
1440 2073
1441 - break;
2074 + </div>
2075 + </div>
2076 + <?php
1442 2077
1443 - case 'datepicker':
2078 + $html = ob_get_clean();
1444 2079
1445 - $data_type = 'DATE';
2080 + return $output . $html;
2081 + }
1446 2082
1447 - $meta_field_add = $data_type . " NULL ";
2083 + public function builder_extra_fields_datepicker( $output, $result_str, $cf, $field_info ) {
2084 + ob_start();
2085 + $extra = array();
2086 + if ( isset( $field_info->extra_fields ) && $field_info->extra_fields != '' ) {
2087 + $extra = unserialize( $field_info->extra_fields );
2088 + }
2089 + ?>
2090 + <div class="uwp-setting-name uwp-advanced-setting mb-3">
2091 + <label for="date_format" class=" form-label">
2092 + <?php
2093 + echo uwp_help_tip( __( 'Select the date format.', 'userswp' ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
2094 + esc_html_e( 'Date Format :', 'userswp' );
2095 + ?>
2096 + </label>
2097 + <div class="uwp-input-wrap" style="overflow:inherit;">
2098 + <?php
2099 + $date_formats = array(
2100 + 'm/d/Y',
2101 + 'd/m/Y',
2102 + 'Y/m/d',
2103 + 'm-d-Y',
2104 + 'd-m-Y',
2105 + 'Y-m-d',
2106 + 'F j, Y',
2107 + );
1448 2108
1449 - $add_result = uwp_add_column_if_not_exist($meta_table, $htmlvar_name, $meta_field_add);
1450 - if ($add_result === false) {
1451 - return __('Column creation failed, you may have too many columns or the default value must have in valid date format.', 'userswp');
1452 - }
2109 + $date_formats = apply_filters( 'uwp_date_formats', $date_formats );
2110 + ?>
2111 + <select name="extra[date_format]" id="date_format" class="aui-selectx2 form-select mw-100" >
2112 + <?php
2113 + foreach ( $date_formats as $format ) {
2114 + $selected = false;
2115 + if ( ! empty( $extra ) && esc_attr( $extra['date_format'] ) == $format ) {
2116 + $selected = true;
2117 + }
2118 + echo '<option ' . selected( $selected, true, false ) . " value='" . esc_attr( $format ) . "'>" . esc_html( $format . ' (' . date_i18n( $format, time() ) . ')' ) . '</option>';
2119 + }
2120 + ?>
2121 + </select>
1453 2122
1454 - break;
2123 + </div>
2124 + </div>
2125 + <?php
1455 2126
1456 - case 'time':
2127 + $html = ob_get_clean();
1457 2128
1458 - $data_type = 'TIME';
2129 + return $output . $html;
2130 + }
1459 2131
1460 - $meta_field_add = $data_type . " NULL ";
2132 + public function builder_extra_fields_password( $output, $result_str, $cf, $field_info ) {
2133 + ob_start();
1461 2134
1462 - $add_result = uwp_add_column_if_not_exist($meta_table, $htmlvar_name, $meta_field_add);
1463 - if ($add_result === false) {
1464 - return __('Column creation failed, you may have too many columns or the default value must have in valid time format.', 'userswp');
1465 - }
2135 + //confirm password field
2136 + $extra = array();
2137 + if ( isset( $field_info->extra_fields ) && $field_info->extra_fields != '' ) {
2138 + $extra = unserialize( $field_info->extra_fields );
2139 + }
2140 + $value = isset( $extra['confirm_password'] ) ? $extra['confirm_password'] : '1';
2141 + if ( isset( $field_info->htmlvar_name ) && $field_info->htmlvar_name == 'password' ) {
1466 2142
1467 - break;
2143 + echo '<div class="' . uwp_advanced_toggle_class() . '">';
2144 + echo aui()->input(
2145 + array(
2146 + 'id' => 'extra_confirm_password',
2147 + 'name' => 'extra[confirm_password]',
2148 + 'type' => 'checkbox',
2149 + 'label_type' => 'horizontal',
2150 + 'label_col' => '4',
2151 + 'label' => __( 'Display confirm password field', 'userswp' ),
2152 + 'checked' => $value,
2153 + 'value' => '1',
2154 + 'switch' => 'md',
2155 + 'label_force_left' => true,
2156 + 'help_text' => uwp_help_tip( __( 'Lets you display confirm password form field.', 'userswp' ) ),
2157 + )
2158 + );
2159 + echo '</div>';
1468 2160
1469 - default:
2161 + }
2162 + $html = ob_get_clean();
1470 2163
1471 - if ($data_type != 'VARCHAR' && $data_type != '') {
1472 - $meta_field_add = $data_type . " NULL ";
2164 + return $output . $html;
2165 + }
1473 2166
1474 - if ($data_type == 'FLOAT' && $decimal_point > 0) {
1475 - $meta_field_add = "DECIMAL(11, " . (int) $decimal_point . ") NULL ";
1476 - }
2167 + public function builder_extra_fields_email( $output, $result_str, $cf, $field_info ) {
2168 + ob_start();
2169 + //confirm email field
2170 + $extra = array();
2171 + if ( isset( $field_info->extra_fields ) && $field_info->extra_fields != '' ) {
2172 + $extra = unserialize( $field_info->extra_fields );
2173 + }
2174 + $value = isset( $extra['confirm_email'] ) ? $extra['confirm_email'] : '0';
1477 2175
1478 - if (is_numeric($default_value) && $default_value != '') {
1479 - $meta_field_add .= " DEFAULT '" . $default_value . "'";
1480 - }
1481 - } else {
1482 - $meta_field_add = " VARCHAR( 254 ) NULL ";
2176 + if ( isset( $field_info->htmlvar_name ) && $field_info->htmlvar_name == 'email' ) {
1483 2177
1484 - if ($default_value != '') {
1485 - $meta_field_add .= " DEFAULT '" . $default_value . "'";
1486 - }
1487 - }
2178 + echo '<div class="' . uwp_advanced_toggle_class() . '">';
2179 + echo aui()->input(
2180 + array(
2181 + 'id' => 'extra_confirm_email',
2182 + 'name' => 'extra[confirm_email]',
2183 + 'type' => 'checkbox',
2184 + 'label_type' => 'horizontal',
2185 + 'label_col' => '4',
2186 + 'label' => __( 'Display confirm email field', 'userswp' ),
2187 + 'checked' => $value,
2188 + 'value' => '1',
2189 + 'switch' => 'md',
2190 + 'label_force_left' => true,
2191 + 'help_text' => uwp_help_tip( __( 'Lets you display confirm email form field.', 'userswp' ) ),
2192 + )
2193 + );
2194 + echo '</div>';
1488 2195
1489 - $add_result = uwp_add_column_if_not_exist($meta_table, $htmlvar_name, $meta_field_add);
1490 - if ($add_result === false) {
1491 - return __('Column creation failed, you may have too many columns or the default value does not match with field data type.', 'userswp');
1492 - }
1493 - break;
1494 - endswitch;
2196 + }
2197 + $html = ob_get_clean();
1495 2198
1496 - $extra_field_query = '';
1497 - if (!empty($extra_fields)) {
1498 - $extra_field_query = serialize($extra_fields);
1499 - }
2199 + return $output . $html;
2200 + }
1500 2201
1501 - $wpdb->query(
2202 + public function builder_extra_fields_file( $output, $result_str, $cf, $field_info ) {
2203 + ob_start();
1502 2204
1503 - $wpdb->prepare(
2205 + $file_obj = new UsersWP_Files();
2206 + $allowed_file_types = $file_obj->allowed_mime_types();
1504 2207
1505 - "insert into " . $table_name . " set
1506 - form_type = %s,
1507 - site_title = %s,
1508 - form_label = %s,
1509 - field_type = %s,
1510 - data_type = %s,
1511 - decimal_point = %s,
1512 - field_type_key = %s,
1513 - htmlvar_name = %s,
1514 - default_value = %s,
1515 - sort_order = %d,
1516 - is_active = %s,
1517 - for_admin_use = %s,
1518 - is_default = %s,
1519 - is_required = %s,
1520 - is_dummy = %s,
1521 - is_public = %s,
1522 - is_register_field = %s,
1523 - is_search_field = %s,
1524 - is_register_only_field = %s,
1525 - required_msg = %s,
1526 - css_class = %s,
1527 - field_icon = %s,
1528 - show_in = %s,
1529 - user_roles = %s,
1530 - option_values = %s,
1531 - extra_fields = %s,
1532 - validation_pattern = %s,
1533 - validation_msg = %s ",
2208 + $extra_fields = isset( $field_info->extra_fields ) && $field_info->extra_fields != '' ? maybe_unserialize( $field_info->extra_fields ) : '';
2209 + $uwp_file_types = ! empty( $extra_fields ) && ! empty( $extra_fields['uwp_file_types'] ) ? $extra_fields['uwp_file_types'] : array( '*' );
2210 + ?>
2211 + <div class="uwp-setting-name uwp-advanced-setting mb-3">
2212 + <label for="uwp_file_types" class="form-label">
2213 + <?php
2214 + echo uwp_help_tip( __( 'Select file types to allowed for file uploading. (Select multiple file types by holding down "Ctrl" key.)', 'userswp' ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
2215 + esc_html_e( 'Allowed file types :', 'userswp' );
2216 + ?>
2217 + </label>
2218 + <div class="uwp-input-wrap">
2219 + <select name="extra[uwp_file_types][]" id="uwp_file_types" multiple="multiple" class="aui-select2 form-select mw-100" >
2220 + <option value="*" <?php selected( true, in_array( '*', $uwp_file_types ) ); ?>><?php esc_html_e( 'All types', 'userswp' ); ?></option>
2221 + <?php foreach ( $allowed_file_types as $format => $types ) { ?>
2222 + <optgroup
2223 + label="<?php echo esc_attr( wp_sprintf( __( '%s formats', 'userswp' ), __( $format, 'userswp' ) ) ); ?>">
2224 + <?php foreach ( $types as $ext => $type ) { ?>
2225 + <option value="<?php echo esc_attr( $ext ); ?>" <?php selected( true, in_array( $ext, $uwp_file_types ) ); ?>><?php echo '.' . esc_html( $ext ); ?></option>
2226 + <?php } ?>
2227 + </optgroup>
2228 + <?php } ?>
2229 + </select>
2230 + </div>
2231 + </div>
2232 + <?php
1534 2233
1535 - array(
1536 - $form_type,
1537 - $site_title,
1538 - $form_label,
1539 - $field_type,
1540 - $data_type,
1541 - $decimal_point,
1542 - $field_type_key,
1543 - $htmlvar_name,
1544 - $default_value,
1545 - $sort_order,
1546 - $is_active,
1547 - $for_admin_use,
1548 - $is_default,
1549 - $is_required,
1550 - $is_dummy,
1551 - $is_public,
1552 - $is_register_field,
1553 - $is_search_field,
1554 - $is_register_only_field,
1555 - $required_msg,
1556 - $css_class,
1557 - $field_icon,
1558 - $show_in,
1559 - $user_roles,
1560 - $option_values,
1561 - $extra_field_query,
1562 - $validation_pattern,
1563 - $validation_msg
1564 - )
2234 + $html = ob_get_clean();
1565 2235
1566 - )
2236 + return $output . $html;
2237 + }
1567 2238
1568 - );
2239 + public function builder_data_type_text( $output, $result_str, $cf, $field_info ) {
2240 + ob_start();
1569 2241
1570 - $lastid = $wpdb->insert_id;
2242 + $dt_value = '';
2243 + if ( isset( $field_info->data_type ) ) {
2244 + $dt_value = esc_attr( $field_info->data_type );
2245 + } elseif ( isset( $cf['defaults']['data_type'] ) && $cf['defaults']['data_type'] ) {
2246 + $dt_value = $cf['defaults']['data_type'];
2247 + }
1571 2248
1572 - $lastid = trim($lastid);
2249 + // fix some values
2250 + if ( $dt_value == 'VARCHAR' ) {
2251 + $dt_value = 'XVARCHAR';
2252 + }
1573 2253
1574 - }
2254 + echo aui()->select(
2255 + array(
2256 + 'id' => 'data_type',
2257 + 'name' => 'data_type',
2258 + 'label_type' => 'top',
2259 + 'multiple' => false,
2260 + 'wrap_class' => uwp_advanced_toggle_class(),
2261 + 'class' => 'mw-100',
2262 + 'options' => array(
2263 + 'XVARCHAR' => __( 'CHARACTER', 'userswp' ),
2264 + 'INT' => __( 'NUMBER', 'userswp' ),
2265 + 'FLOAT' => __( 'DECIMAL', 'userswp' ),
2266 + ),
2267 + 'label' => __( 'Data Type', 'userswp' ) . uwp_help_tip( __( 'Select Custom Field type', 'userswp' ) ),
2268 + 'value' => $dt_value,
2269 + 'extra_attributes' => array(
2270 + 'onchange' => "javascript:uwp_data_type_changed(this, '$result_str');",
2271 + ),
2272 + )
2273 + );
1575 2274
1576 - return (int) $lastid;
2275 + $value = '';
2276 + if ( isset( $field_info->decimal_point ) ) {
2277 + $value = esc_attr( $field_info->decimal_point );
2278 + } elseif ( isset( $cf['defaults']['decimal_point'] ) && $cf['defaults']['decimal_point'] ) {
2279 + $value = $cf['defaults']['decimal_point'];
2280 + }
1577 2281
2282 + echo aui()->select(
2283 + array(
2284 + 'id' => 'decimal_point',
2285 + 'name' => 'decimal_point',
2286 + 'label_type' => 'top',
2287 + 'multiple' => false,
2288 + 'class' => ' mw-100',
2289 + 'options' => array(
2290 + '' => __( 'Select', 'userswp' ),
2291 + '1' => '1',
2292 + '2' => '2',
2293 + '3' => '3',
2294 + '4' => '4',
2295 + '5' => '5',
2296 + '6' => '6',
2297 + '7' => '7',
2298 + '8' => '8',
2299 + '9' => '9',
2300 + '10' => '10',
2301 + ),
2302 + 'label' => __( 'Decimal points', 'userswp' ) . uwp_help_tip( __( 'Decimals to display after point.', 'userswp' ) ),
2303 + 'value' => $value,
2304 + 'element_require' => '[%data_type%] == "FLOAT"',
2305 + )
2306 + );
1578 2307
1579 - } else {
1580 - return __('HTML Variable Name should be a unique name', 'userswp');
1581 - }
2308 + $output = ob_get_clean();
1582 2309
1583 - }
2310 + return $output;
2311 + }
1584 2312
1585 - public function uwp_set_field_order($field_ids = array())
1586 - {
2313 + public function advance_admin_custom_fields( $field_info, $cf ) {
2314 + $hide_register_field = ( isset( $cf['defaults']['is_register_field'] ) && $cf['defaults']['is_register_field'] === false ) ? "style='display:none;'" : '';
2315 + $hide_register_field = ( isset( $field_info->for_admin_use ) && $field_info->for_admin_use == '1' ) ? "style='display:none;'" : $hide_register_field;
2316 + $hide_user_sort = ( isset( $cf['defaults']['user_sort'] ) && $cf['defaults']['user_sort'] === false ) ? "style='display:none;'" : '';
1587 2317
1588 - global $wpdb;
2318 + $value = 0;
2319 + if ( isset( $field_info->is_register_field ) ) {
2320 + $value = (int) $field_info->is_register_field;
2321 + } elseif ( isset( $cf['defaults']['is_register_field'] ) && $cf['defaults']['is_register_field'] ) {
2322 + $value = ( $cf['defaults']['is_register_field'] ) ? 1 : 0;
2323 + }
1589 2324
1590 - $table_name = uwp_get_table_prefix() . 'uwp_form_fields';
2325 + if ( isset( $field_info->htmlvar_name ) ) {
2326 + $htmlvar_name = $field_info->htmlvar_name;
2327 + } elseif ( isset( $cf['defaults']['htmlvar_name'] ) && $cf['defaults']['htmlvar_name'] ) {
2328 + $htmlvar_name = ( $cf['defaults']['htmlvar_name'] ) ? $cf['defaults']['htmlvar_name'] : '';
2329 + }
1591 2330
1592 - $count = 0;
1593 - if (!empty($field_ids)):
1594 - $user_meta_info = false;
1595 - foreach ($field_ids as $id) {
2331 + //register only field
2332 + $hide_register_only_field = ( isset( $cf['defaults']['is_register_only_field'] ) && $cf['defaults']['is_register_only_field'] === false ) ? "style='display:none;'" : '';
2333 + $hide_register_only_field = ( isset( $field_info->for_admin_use ) && $field_info->for_admin_use == '1' ) ? "style='display:none;'" : $hide_register_only_field;
2334 + $register_only_value = 0;
2335 + if ( isset( $field_info->is_register_only_field ) ) {
2336 + $register_only_value = (int) $field_info->is_register_only_field;
2337 + } elseif ( isset( $cf['defaults']['is_register_only_field'] ) && $cf['defaults']['is_register_only_field'] ) {
2338 + $register_only_value = ( $cf['defaults']['is_register_only_field'] ) ? 1 : 0;
2339 + }
1596 2340
1597 - $cf = trim($id, '_');
2341 + $user_sort_value = 0;
2342 + if ( isset( $field_info->user_sort ) ) {
2343 + $user_sort_value = (int) $field_info->user_sort;
2344 + } elseif ( isset( $cf['defaults']['user_sort'] ) && $cf['defaults']['user_sort'] ) {
2345 + $user_sort_value = ( $cf['defaults']['user_sort'] ) ? 1 : 0;
2346 + }
1598 2347
1599 - $user_meta_info = $wpdb->query(
1600 - $wpdb->prepare(
1601 - "update " . $table_name . " set
1602 - sort_order=%d
1603 - where id= %d",
1604 - array($count, $cf)
2348 + ?>
2349 + <div <?php echo $hide_register_field; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> class="cf-incin-reg-form uwp-setting-name mb-3">
2350 +
2351 + <?php
2352 + $reg_only_fields = uwp_get_register_only_fields();
2353 + if ( isset( $htmlvar_name ) && in_array( $htmlvar_name, $reg_only_fields ) ) {
2354 + ?>
2355 + <label for="is_register_field" class=" form-label">
2356 + <?php
2357 + echo uwp_help_tip( __( 'Lets you use this field as register form field, set from register tab above.', 'userswp' ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
2358 + esc_html_e( 'Include this field in register form:', 'userswp' );
2359 + ?>
2360 + </label>
2361 + <input type="hidden" name="is_register_field" value="1"/>
2362 + <p><?php esc_html_e( 'This is mandatory register form field.', 'userswp' ); ?></p>
2363 + <?php
2364 + } else {
2365 + echo aui()->input(
2366 + array(
2367 + 'id' => 'is_register_field',
2368 + 'name' => 'is_register_field',
2369 + 'type' => 'checkbox',
2370 + 'label_type' => 'horizontal',
2371 + 'label_col' => '4',
2372 + 'label' => __( 'Include this field in register form', 'userswp' ),
2373 + 'checked' => $value,
2374 + 'value' => '1',
2375 + 'switch' => 'md',
2376 + 'label_force_left' => true,
2377 + 'help_text' => uwp_help_tip( __( 'Lets you use this field as register form field, set from register tab above.', 'userswp' ) ),
1605 2378 )
1606 2379 );
1607 - $count++;
1608 2380 }
2381 + ?>
2382 + </div>
1609 2383
1610 - return $user_meta_info;
1611 - else:
1612 - return false;
1613 - endif;
1614 - }
2384 + <div <?php echo $hide_register_only_field; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> class="cf-inconlyin-reg-form uwp-setting-name uwp-advanced-setting">
1615 2385
1616 - public function uwp_admin_form_field_delete($field_id = '') {
1617 - global $wpdb;
1618 2386
1619 - $table_name = uwp_get_table_prefix() . 'uwp_form_fields';
1620 - $extras_table_name = uwp_get_table_prefix() . 'uwp_form_extras';
2387 + <?php
2388 + if ( isset( $htmlvar_name ) && in_array( $htmlvar_name, $reg_only_fields ) ) {
2389 + ?>
2390 + <label for="is_register_only_field" class="form-label">
2391 + <?php
2392 + echo uwp_help_tip( __( 'Lets you use this field as register ONLY form field.', 'userswp' ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
2393 + esc_html_e( 'Include this field ONLY in register form:', 'userswp' );
2394 + ?>
2395 + </label>
2396 + <input type="hidden" name="is_register_only_field" class="form-control" value="1"/>
2397 + <p><?php esc_html_e( 'This field is applicable only for register form.', 'userswp' ); ?></p>
2398 + <?php
2399 + } else {
2400 + echo aui()->input(
2401 + array(
2402 + 'id' => 'is_register_only_field',
2403 + 'name' => 'is_register_only_field',
2404 + 'type' => 'checkbox',
2405 + 'label_type' => 'horizontal',
2406 + 'label_col' => '4',
2407 + 'label' => __( 'Include this field ONLY in register form', 'userswp' ),
2408 + 'checked' => $register_only_value,
2409 + 'value' => '1',
2410 + 'switch' => 'md',
2411 + 'label_force_left' => true,
2412 + 'help_text' => uwp_help_tip( __( 'Lets you use this field as register ONLY form field.', 'userswp' ) ),
1621 2413
1622 - if ($field_id != '') {
1623 - $cf = trim($field_id, '_');
2414 + )
2415 + );
1624 2416
1625 - if ($field = $wpdb->get_row($wpdb->prepare("select * from " . $table_name . " where id= %d", array($cf)))) {
2417 + }
2418 + ?>
2419 + </div>
1626 2420
1627 - $wpdb->query($wpdb->prepare("delete from " . $table_name . " where id= %d ", array($cf)));
2421 + <div <?php echo $hide_user_sort; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> class="cf-incin-reg-form uwp-setting-name uwp-advanced-setting">
2422 + <?php
1628 2423
1629 - $form_type = $field->form_type;
2424 + echo aui()->input(
2425 + array(
2426 + 'id' => 'user_sort',
2427 + 'name' => 'user_sort',
2428 + 'type' => 'checkbox',
2429 + 'label_type' => 'horizontal',
2430 + 'label_col' => '4',
2431 + 'label' => __( 'Include this field in sorting options', 'userswp' ),
2432 + 'checked' => $user_sort_value,
2433 + 'value' => '1',
2434 + 'switch' => 'md',
2435 + 'label_force_left' => true,
2436 + 'help_text' => uwp_help_tip( __( 'Lets you use this field as sorting in the users listing page, set from user sorting tab above.', 'userswp' ) ),
1630 2437
1631 - // Also delete register form field
1632 - $wpdb->query($wpdb->prepare("delete from " . $extras_table_name . " where site_htmlvar_name= %s ", array($field->htmlvar_name)));
2438 + )
2439 + );
1633 2440
1634 - do_action('uwp_after_custom_field_deleted', $cf, $field->htmlvar_name, $form_type);
2441 + ?>
1635 2442
1636 - return $field_id;
1637 - } else
1638 - return 0;
1639 - } else
1640 - return 0;
1641 - }
2443 + </div>
1642 2444
1643 - public function uwp_builder_extra_fields_smr($output, $result_str, $cf, $field_info) {
2445 + <?php
2446 + }
1644 2447
1645 - ob_start();
2448 + public function return_empty_string() {
2449 + return '';
2450 + }
1646 2451
1647 - $value = '';
1648 - if (isset($field_info->option_values)) {
1649 - $value = esc_attr($field_info->option_values);
1650 - }elseif (isset($cf['defaults']['option_values']) && $cf['defaults']['option_values']) {
1651 - $value = esc_attr($cf['defaults']['option_values']);
1652 - }
2452 + public function register_available_fields_head( $heading, $form_type ) {
2453 + switch ( $form_type ) {
2454 + case 'register':
2455 + $heading = __( 'Available register form fields.', 'userswp' );
2456 + break;
2457 + }
1653 2458
1654 - $field_type = isset($field_info->field_type) ? $field_info->field_type : $cf['field_type'];
1655 - $field_type_key = isset($field_info->field_type_key) ? $field_info->field_type_key : '';
1656 - if(!$field_type_key){
1657 - $field_type_key = isset($_REQUEST['field_type_key']) ? esc_html($_REQUEST['field_type_key']) : '';
1658 - }
1659 - ?>
1660 - <li>
1661 - <label for="option_values" class="uwp-tooltip-wrap">
1662 - <i class="fas fa-info-circle" aria-hidden="true"></i> <?php _e('Option Values :', 'userswp'); ?>
1663 - <div class="uwp-tooltip">
1664 - <span><?php _e('Option Values should be separated by comma.', 'userswp'); ?></span>
1665 - <br/>
1666 - <small>
2459 + return $heading;
2460 + }
1667 2461
1668 - <?php if($field_type != 'multiselect'){?>
1669 - <span><?php _e('If using for a "tick filter" place a / and then either a 1 for true or 0 for false', 'userswp'); ?></span>
1670 - <br/>
1671 - <span><?php _e('eg: "No Dogs Allowed/0,Dogs Allowed/1"', 'userswp'); ?></span>
1672 - <?php }?>
2462 + public function register_available_fields_note( $note, $form_type ) {
2463 + switch ( $form_type ) {
2464 + case 'register':
2465 + $note = __( "Click on any box below to make it appear in register form. To make a field available here, go to account tab and expand any field from selected fields panel and tick the checkbox saying 'Include this field in register form'.", 'userswp' );
2466 + break;
2467 + }
1673 2468
1674 - <?php if ($field_type == 'multiselect' || $field_type == 'select') { ?>
1675 - <span><?php _e('Like: Apple,Bannana,Pear,Peach', 'userswp'); ?></span>
1676 - <br/>
2469 + return $note;
2470 + }
1677 2471
1678 - <span><?php _e('Or you can show Selection/Value shown: Pets Allowed/Yes,Pets not Allowed/No', 'userswp'); ?></span>
2472 + public function register_selected_fields_head( $heading, $form_type ) {
2473 + switch ( $form_type ) {
2474 + case 'register':
2475 + $heading = __( 'List of fields that will appear in the register form.', 'userswp' );
2476 + break;
1679 2477
1680 - <br/>
1681 - <span><?php _e('- If using OPTGROUP tag to grouping options, use "{optgroup}OPTGROUP-LABEL|OPTION-1,OPTION-2{/optgroup}"', 'userswp'); ?></span>
1682 - <br/>
1683 - <span><?php _e('eg: "{optgroup}Pets Allowed|No Dogs Allowed/0,Dogs Allowed/1{/optgroup},{optgroup}Sports|Cricket/Cricket,Football/Football,Hockey{/optgroup}"', 'userswp'); ?></span>
1684 - <?php } ?></small>
1685 - </div>
1686 - </label>
1687 - <div class="uwp-input-wrap">
2478 + }
1688 2479
1689 - <?php if(isset($field_type_key) && $field_type_key == 'country' ){
2480 + return $heading;
2481 + }
1690 2482
1691 - // @todo here we should show a multiselect to either include or exclude countries
1692 - _e('A full country list will be shown','userswp');
1693 - ?>
2483 + public function register_selected_fields_note( $note, $form_type ) {
2484 + switch ( $form_type ) {
2485 + case 'register':
2486 + $note = __( 'Click to expand and view field related settings. You may drag and drop to arrange fields order in register form.', 'userswp' );
2487 + break;
1694 2488
1695 - <?php }else{?>
1696 - <input type="text" name="option_values" id="option_values" value="<?php echo $value; ?>"/>
1697 - <?php }?>
2489 + }
1698 2490
1699 - <br/>
2491 + return $note;
2492 + }
1700 2493
1701 - </div>
1702 - </li>
1703 - <?php
2494 + /**
2495 + * Handles the create custom field ajax request.
2496 + *
2497 + * @since 1.0.0
2498 + * @package userswp
2499 + * @return void
2500 + */
2501 + public function create_field() {
1704 2502
1705 - $html = ob_get_clean();
1706 - return $output . $html;
1707 - }
2503 + if ( ! current_user_can( 'manage_options' ) ) {
2504 + wp_die( -1 );
2505 + }
1708 2506
1709 - public function uwp_builder_extra_fields_datepicker($output, $result_str, $cf, $field_info) {
1710 - ob_start();
1711 - $extra = array();
1712 - if (isset($field_info->extra_fields) && $field_info->extra_fields != '') {
1713 - $extra = unserialize($field_info->extra_fields);
1714 - }
1715 - ?>
1716 - <li>
1717 - <label for="date_format" class="uwp-tooltip-wrap">
1718 - <i class="fas fa-info-circle" aria-hidden="true"></i> <?php _e('Date Format :', 'userswp'); ?>
1719 - <div class="uwp-tooltip">
1720 - <?php _e('Select the date format.', 'userswp'); ?>
1721 - </div>
1722 - </label>
1723 - <div class="uwp-input-wrap" style="overflow:inherit;">
1724 - <?php
1725 - $date_formats = array(
1726 - 'm/d/Y',
1727 - 'd/m/Y',
1728 - 'Y/m/d',
1729 - 'm-d-Y',
1730 - 'd-m-Y',
1731 - 'Y-m-d',
1732 - 'F j, Y',
1733 - );
1734 -
1735 - $date_formats = apply_filters('uwp_date_formats', $date_formats);
1736 - ?>
1737 - <select name="extra[date_format]" id="date_format">
1738 - <?php
1739 - foreach ($date_formats as $format) {
1740 - $selected = '';
1741 - if (!empty($extra) && esc_attr($extra['date_format']) == $format) {
1742 - $selected = "selected='selected'";
1743 - }
1744 - echo "<option $selected value='$format'>$format (" . date_i18n($format, time()) . ")</option>";
1745 - }
1746 - ?>
1747 - </select>
2507 + $form_type = isset( $_REQUEST['form_type'] ) ? sanitize_text_field( $_REQUEST['form_type'] ) : '';
2508 + $field_type = isset( $_REQUEST['field_type'] ) ? sanitize_text_field( $_REQUEST['field_type'] ) : '';
2509 + $field_type_key = isset( $_REQUEST['field_type_key'] ) ? sanitize_text_field( $_REQUEST['field_type_key'] ) : '';
2510 + $field_action = isset( $_REQUEST['field_ins_upd'] ) ? sanitize_text_field( $_REQUEST['field_ins_upd'] ) : '';
2511 + $field_id = isset( $_REQUEST['field_id'] ) ? sanitize_text_field( $_REQUEST['field_id'] ) : '';
2512 + $form_id = isset( $_REQUEST['form_id'] ) ? absint( $_REQUEST['form_id'] ) : 1;
1748 2513
1749 - </div>
1750 - </li>
1751 - <?php
2514 + $field_id = $field_id != '' ? trim( $field_id, '_' ) : $field_id;
1752 2515
1753 - $html = ob_get_clean();
1754 - return $output . $html;
1755 - }
2516 + $field_ids = array();
2517 + if ( ! empty( $_REQUEST['licontainer'] ) && is_array( $_REQUEST['licontainer'] ) ) {
2518 + foreach ( $_REQUEST['licontainer'] as $lic_id ) {
2519 + $field_ids[] = sanitize_text_field( $lic_id );
2520 + }
2521 + }
1756 2522
1757 - public function uwp_builder_extra_fields_password($output, $result_str, $cf, $field_info) {
1758 - ob_start();
1759 - $radio_id = (isset($field_info->htmlvar_name)) ? $field_info->htmlvar_name : rand(5, 500);
1760 -
1761 - //confirm password field
1762 - $extra = array();
1763 - if (isset($field_info->extra_fields) && $field_info->extra_fields != '') {
1764 - $extra = unserialize($field_info->extra_fields);
1765 - }
1766 - $value = isset($extra['confirm_password']) ? $extra['confirm_password'] : '1';
1767 - if (isset($field_info->htmlvar_name) && $field_info->htmlvar_name == 'uwp_account_password') {
1768 - ?>
1769 - <li>
1770 - <label for="cat_sort" class="uwp-tooltip-wrap">
1771 - <i class="fas fa-info-circle"
1772 - aria-hidden="true"></i> <?php _e('Display confirm password field?:', 'userswp'); ?>
1773 - <div class="uwp-tooltip">
1774 - <?php _e('Lets you display confirm password form field.', 'userswp'); ?>
1775 - </div>
1776 - </label>
2523 + /* ------- check nonce field ------- */
2524 + if ( isset( $_REQUEST['update'] ) && $_REQUEST['update'] == 'update' && isset( $_REQUEST['create_field'] ) && isset( $_REQUEST['manage_field_type'] ) && $_REQUEST['manage_field_type'] == 'custom_fields' ) {
2525 + echo $this->set_field_order( $field_ids, $form_id ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
2526 + }
1777 2527
1778 - <div class="uwp-input-wrap uwp-switch">
1779 - <input type="radio" id="confirm_password_yes<?php echo $radio_id; ?>" name="extra[confirm_password]"
1780 - class="uwp-ri-enabled" value="1" <?php checked(1, $value); ?> />
1781 - <label for="confirm_password_yes<?php echo $radio_id; ?>"
1782 - class="uwp-cb-enable"><span><?php _e('Yes', 'userswp'); ?></span></label>
2528 + /* ---- Show field form in admin ---- */
2529 + if ( $field_type != '' && $field_id != '' && $field_action == 'new' && isset( $_REQUEST['create_field'] ) && isset( $_REQUEST['manage_field_type'] ) && $_REQUEST['manage_field_type'] == 'custom_fields' ) {
2530 + $this->form_field_adminhtml( $field_type, $field_id, $field_action, $field_type_key, $form_type );
2531 + }
1783 2532
1784 - <input type="radio" id="confirm_password_no<?php echo $radio_id; ?>" name="extra[confirm_password]"
1785 - class="uwp-ri-disabled" value="0" <?php checked(0, $value); ?> />
1786 - <label for="confirm_password_no<?php echo $radio_id; ?>"
1787 - class="uwp-cb-disable"><span><?php _e('No', 'userswp'); ?></span></label>
1788 - </div>
1789 - </li>
1790 - <?php
1791 - }
1792 - $html = ob_get_clean();
1793 - return $output . $html;
1794 - }
2533 + /* ---- Delete field ---- */
2534 + if ( $field_id != '' && $field_action == 'delete' && isset( $_REQUEST['_wpnonce'] ) && isset( $_REQUEST['create_field'] ) && isset( $_REQUEST['manage_field_type'] ) && $_REQUEST['manage_field_type'] == 'custom_fields' ) {
2535 + if ( ! wp_verify_nonce( $_REQUEST['_wpnonce'], 'custom_fields_delete_' . $field_id ) ) {
2536 + return;
2537 + }
1795 2538
1796 - public function uwp_builder_extra_fields_email($output, $result_str, $cf, $field_info) {
1797 - ob_start();
1798 - $radio_id = (isset($field_info->htmlvar_name)) ? $field_info->htmlvar_name : rand(5, 500);
2539 + echo $this->admin_form_field_delete( $field_id, true, $form_id ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
2540 + }
1799 2541
1800 - //confirm email field
1801 - $extra = array();
1802 - if (isset($field_info->extra_fields) && $field_info->extra_fields != '') {
1803 - $extra = unserialize($field_info->extra_fields);
1804 - }
1805 - $value = isset($extra['confirm_email']) ? $extra['confirm_email'] : '0';
2542 + /* ---- Save field ---- */
2543 + if ( $field_id != '' && $field_action == 'submit' && isset( $_REQUEST['_wpnonce'] ) && isset( $_REQUEST['create_field'] ) && isset( $_REQUEST['manage_field_type'] ) && $_REQUEST['manage_field_type'] == 'custom_fields' ) {
2544 + if ( ! wp_verify_nonce( $_REQUEST['_wpnonce'], 'custom_fields_' . $field_id ) ) {
2545 + return;
2546 + }
1806 2547
1807 - if (isset($field_info->htmlvar_name) && $field_info->htmlvar_name == 'uwp_account_email') {
1808 - ?>
1809 - <li>
1810 - <label for="cat_sort" class="uwp-tooltip-wrap">
1811 - <i class="fas fa-info-circle"
1812 - aria-hidden="true"></i> <?php _e('Display confirm email field?:', 'userswp'); ?>
1813 - <div class="uwp-tooltip">
1814 - <?php _e('Lets you display confirm email form field.', 'userswp'); ?>
1815 - </div>
1816 - </label>
2548 + foreach ( $_REQUEST as $pkey => $pval ) {
2549 + if ( isset( $_REQUEST[ $pkey ] ) && is_array( $_REQUEST[ $pkey ] ) ) {
2550 + $tags = 'skip_field';
2551 + } else {
2552 + $tags = '';
2553 + }
1817 2554
1818 - <div class="uwp-input-wrap uwp-switch">
1819 - <input type="radio" id="confirm_email_yes<?php echo $radio_id; ?>" name="extra[confirm_email]"
1820 - class="uwp-ri-enabled" value="1" <?php checked(1, $value); ?> />
1821 - <label for="confirm_email_yes<?php echo $radio_id; ?>"
1822 - class="uwp-cb-enable"><span><?php _e('Yes', 'userswp'); ?></span></label>
2555 + if ( $tags != 'skip_field' ) {
2556 + $_REQUEST[ $pkey ] = strip_tags( $_REQUEST[ $pkey ], $tags );
2557 + }
2558 + }
1823 2559
1824 - <input type="radio" id="confirm_email_no<?php echo $radio_id; ?>" name="extra[confirm_email]"
1825 - class="uwp-ri-disabled" value="0" <?php checked(0, $value); ?> />
1826 - <label for="confirm_email_no<?php echo $radio_id; ?>"
1827 - class="uwp-cb-disable"><span><?php _e('No', 'userswp'); ?></span></label>
1828 - </div>
1829 - </li>
1830 - <?php
1831 - }
1832 - $html = ob_get_clean();
1833 - return $output . $html;
1834 - }
2560 + $return = $this->admin_form_field_save( $_REQUEST );
1835 2561
1836 - public function uwp_builder_extra_fields_file($output, $result_str, $cf, $field_info) {
1837 - ob_start();
2562 + if ( is_int( $return ) ) {
2563 + $lastid = $return;
2564 + $this->form_field_adminhtml( $field_type, $lastid, 'submit', $field_type_key, $form_type );
2565 + } else {
2566 + echo $return; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
2567 + }
2568 + }
1838 2569
1839 - $file_obj = new UsersWP_Files();
1840 - $allowed_file_types = $file_obj->allowed_mime_types();
2570 + wp_die();
2571 + }
1841 2572
1842 - $extra_fields = isset($field_info->extra_fields) && $field_info->extra_fields != '' ? maybe_unserialize($field_info->extra_fields) : '';
1843 - $uwp_file_types = !empty($extra_fields) && !empty($extra_fields['uwp_file_types']) ? $extra_fields['uwp_file_types'] : array('*');
1844 - ?>
1845 - <li>
1846 - <label for="uwp_file_types" class="uwp-tooltip-wrap">
1847 - <i class="fas fa-info-circle" aria-hidden="true"></i> <?php _e('Allowed file types :', 'userswp'); ?>
1848 - <div class="uwp-tooltip">
1849 - <?php _e('Select file types to allowed for file uploading. (Select multiple file types by holding down "Ctrl" key.)', 'userswp'); ?>
1850 - </div>
1851 - </label>
1852 - <div class="uwp-input-wrap">
1853 - <select name="extra[uwp_file_types][]" id="uwp_file_types" multiple="multiple" style="height:100px;width:90%;">
1854 - <option value="*" <?php selected(true, in_array('*', $uwp_file_types)); ?>><?php _e('All types', 'userswp'); ?></option>
1855 - <?php foreach ($allowed_file_types as $format => $types) { ?>
1856 - <optgroup label="<?php echo esc_attr(wp_sprintf(__('%s formats', 'userswp'), __($format, 'userswp'))); ?>">
1857 - <?php foreach ($types as $ext => $type) { ?>
1858 - <option value="<?php echo esc_attr($ext); ?>" <?php selected(true, in_array($ext, $uwp_file_types)); ?>><?php echo '.' . $ext; ?></option>
1859 - <?php } ?>
1860 - </optgroup>
1861 - <?php } ?>
1862 - </select>
1863 - </div>
1864 - </li>
1865 - <?php
2573 + public function set_field_order( $field_ids = array(), $form_id = 1 ) {
1866 2574
1867 - $html = ob_get_clean();
1868 - return $output . $html;
1869 - }
1870 -
1871 - public function uwp_builder_data_type_text($output, $result_str, $cf, $field_info) {
1872 - ob_start();
2575 + global $wpdb;
1873 2576
1874 - $dt_value = '';
1875 - if (isset($field_info->data_type)) {
1876 - $dt_value = esc_attr($field_info->data_type);
1877 - }elseif (isset($cf['defaults']['data_type']) && $cf['defaults']['data_type']) {
1878 - $dt_value = $cf['defaults']['data_type'];
1879 - }
1880 - ?>
1881 - <li>
1882 - <label for="data_type" class="uwp-tooltip-wrap">
1883 - <i class="fas fa-info-circle" aria-hidden="true"></i> <?php _e('Field Data Type ? :', 'userswp'); ?>
1884 - <div class="uwp-tooltip">
1885 - <?php _e('Select Custom Field type', 'userswp'); ?>
1886 - </div>
1887 - </label>
1888 - <div class="uwp-input-wrap">
2577 + $table_name = uwp_get_table_prefix() . 'uwp_form_fields';
1889 2578
1890 - <select name="data_type" id="data_type"
1891 - onchange="uwp_data_type_changed(this, '<?php echo $result_str; ?>');">
1892 - <option
1893 - value="XVARCHAR" <?php if ($dt_value == 'VARCHAR') {
1894 - echo 'selected="selected"';
1895 - } ?>><?php _e('Text Field', 'userswp'); ?></option>
1896 - <option
1897 - value="INT" <?php if ($dt_value == 'INT') {
1898 - echo 'selected="selected"';
1899 - } ?>><?php _e('Number Field', 'userswp'); ?></option>
1900 - <option
1901 - value="FLOAT" <?php if ($dt_value == 'FLOAT') {
1902 - echo 'selected="selected"';
1903 - } ?>><?php _e('Decimal Field', 'userswp'); ?></option>
1904 - </select>
2579 + $count = 0;
2580 + if ( ! empty( $field_ids ) ) :
2581 + $user_meta_info = false;
2582 + foreach ( $field_ids as $id ) {
1905 2583
1906 - </div>
1907 - </li>
2584 + $cf = trim( $id, '_' );
1908 2585
1909 - <?php
1910 - $value = '';
1911 - if (isset($field_info->decimal_point)) {
1912 - $value = esc_attr($field_info->decimal_point);
1913 - }elseif (isset($cf['defaults']['decimal_point']) && $cf['defaults']['decimal_point']) {
1914 - $value = $cf['defaults']['decimal_point'];
1915 - }
1916 - ?>
2586 + $user_meta_info = $wpdb->query(
2587 + $wpdb->prepare(
2588 + 'update ' . $table_name . ' set
2589 + sort_order=%d
2590 + where id= %d and form_id = %d',
2591 + array( $count, $cf, $form_id )
2592 + )
2593 + );
2594 + ++$count;
2595 + }
1917 2596
1918 - <li class="decimal-point-wrapper"
1919 - style="<?php echo ($dt_value == 'FLOAT') ? '' : 'display:none' ?>">
1920 - <label for="decimal_point" class="uwp-tooltip-wrap">
1921 - <i class="fas fa-info-circle" aria-hidden="true"></i> <?php _e('Select decimal precision:', 'userswp'); ?>
1922 - <div class="uwp-tooltip">
1923 - <?php _e('Decimal places to display after point', 'userswp'); ?>
1924 - </div>
1925 - </label>
1926 - <div class="uwp-input-wrap">
1927 - <select name="decimal_point" id="decimal_point">
1928 - <option value=""><?php echo __('Select', 'userswp'); ?></option>
1929 - <?php for ($i = 1; $i <= 10; $i++) {
1930 - $selected = $i == $value ? 'selected="selected"' : ''; ?>
1931 - <option value="<?php echo $i; ?>" <?php echo $selected; ?>><?php echo $i; ?></option>
1932 - <?php } ?>
1933 - </select>
1934 - </div>
1935 - </li>
1936 - <?php
2597 + return $user_meta_info;
2598 + else :
2599 + return false;
2600 + endif;
2601 + }
1937 2602
1938 - $output = ob_get_clean();
1939 - return $output;
1940 - }
2603 + public function admin_form_field_delete( $field_id = '', $delete_meta = true, $form_id = 1 ) {
1941 2604
1942 - public function uwp_advance_admin_custom_fields($field_info, $cf) {
1943 - $radio_id = (isset($field_info->htmlvar_name)) ? $field_info->htmlvar_name : rand(5, 500);
1944 - $hide_register_field = (isset($cf['defaults']['is_register_field']) && $cf['defaults']['is_register_field'] === false) ? "style='display:none;'" : '';
1945 - $hide_register_field = (isset($field_info->for_admin_use) && $field_info->for_admin_use == '1') ? "style='display:none;'" : $hide_register_field;
2605 + global $wpdb;
1946 2606
1947 - $value = 0;
1948 - if (isset($field_info->is_register_field)) {
1949 - $value = (int) $field_info->is_register_field;
1950 - } else if (isset($cf['defaults']['is_register_field']) && $cf['defaults']['is_register_field']) {
1951 - $value = ($cf['defaults']['is_register_field']) ? 1 : 0;
1952 - }
2607 + $table_name = uwp_get_table_prefix() . 'uwp_form_fields';
2608 + $extras_table_name = uwp_get_table_prefix() . 'uwp_form_extras';
2609 + $meta_table = get_usermeta_table_prefix() . 'uwp_usermeta';
1953 2610
1954 - //register only field
1955 - $hide_register_only_field = (isset($cf['defaults']['is_register_only_field']) && $cf['defaults']['is_register_only_field'] === false) ? "style='display:none;'" : '';
1956 - $hide_register_only_field = (isset($field_info->for_admin_use) && $field_info->for_admin_use == '1') ? "style='display:none;'" : $hide_register_only_field;
1957 - $register_only_value = 0;
1958 - if (isset($field_info->is_register_only_field)) {
1959 - $register_only_value = (int) $field_info->is_register_only_field;
1960 - } else if (isset($cf['defaults']['is_register_only_field']) && $cf['defaults']['is_register_only_field']) {
1961 - $register_only_value = ($cf['defaults']['is_register_only_field']) ? 1 : 0;
1962 - }
1963 - ?>
1964 - <li <?php echo $hide_register_field; ?> class="cf-incin-reg-form">
1965 - <label for="cat_sort" class="uwp-tooltip-wrap">
1966 - <i class="fas fa-info-circle" aria-hidden="true"></i> <?php _e('Include this field in register form:', 'userswp'); ?>
1967 - <div class="uwp-tooltip">
1968 - <?php _e('Lets you use this field as register form field, set from register tab above.', 'userswp'); ?>
1969 - </div>
1970 - </label>
2611 + if ( $field_id != '' ) {
2612 + $cf = trim( $field_id, '_' );
1971 2613
1972 - <?php
1973 - if (isset($field_info->htmlvar_name) && $field_info->htmlvar_name == 'uwp_account_username') {
1974 - ?>
1975 - <div>
1976 - <input type="hidden" name="is_register_field" value="1" />
1977 - <p><?php _e('This is mandatory register form field.', 'userswp'); ?></p>
1978 - </div>
1979 - <?php
1980 - } else {
1981 - ?>
1982 - <div class="uwp-input-wrap uwp-switch">
1983 - <input type="radio" id="is_register_field_yes<?php echo $radio_id; ?>" name="is_register_field" class="uwp-ri-enabled" value="1" <?php checked(1, $value); ?> />
1984 - <label for="is_register_field_yes<?php echo $radio_id; ?>" class="uwp-cb-enable"><span><?php _e('Yes', 'userswp'); ?></span></label>
2614 + if ( $field = $wpdb->get_row( $wpdb->prepare( 'select id, htmlvar_name FROM ' . $table_name . ' WHERE id= %d AND form_id = %d', array( (int) $cf, (int) $form_id ) ) ) ) {
1985 2615
1986 - <input type="radio" id="is_register_field_no<?php echo $radio_id; ?>" name="is_register_field" class="uwp-ri-disabled" value="0" <?php checked(0, $value); ?> />
1987 - <label for="is_register_field_no<?php echo $radio_id; ?>" class="uwp-cb-disable"><span><?php _e('No', 'userswp'); ?></span></label>
1988 - </div>
1989 - <?php } ?>
1990 - </li>
2616 + $excluded_delete = array( 'email' );
2617 + $excluded_delete = apply_filters( 'uwp_register_fields_exculde_delete', $excluded_delete );
1991 2618
1992 - <li <?php echo $hide_register_only_field; ?> class="cf-inconlyin-reg-form">
1993 - <label for="cat_sort" class="uwp-tooltip-wrap">
1994 - <i class="fas fa-info-circle" aria-hidden="true"></i> <?php _e('Include this field ONLY in register form:', 'userswp'); ?>
1995 - <div class="uwp-tooltip">
1996 - <?php _e('Lets you use this field as register ONLY form field.', 'userswp'); ?>
1997 - </div>
1998 - </label>
2619 + if ( isset( $field->htmlvar_name ) && in_array( $field->htmlvar_name, $excluded_delete ) ) {
2620 + return $field_id;
2621 + }
1999 2622
2000 - <?php
2001 - if (isset($field_info->htmlvar_name) && $field_info->htmlvar_name == 'uwp_account_username') {
2002 - ?>
2003 - <div>
2004 - <input type="hidden" name="is_register_only_field" value="1" />
2005 - <p><?php _e('This field is applicable only for register form.', 'userswp'); ?></p>
2006 - </div>
2007 - <?php
2008 - } else {
2009 - ?>
2010 - <div class="uwp-input-wrap uwp-switch">
2011 - <input type="radio" id="is_register_only_field_yes<?php echo $radio_id; ?>" name="is_register_only_field" class="uwp-ri-enabled" value="1" <?php checked(1, $register_only_value); ?> />
2012 - <label for="is_register_only_field_yes<?php echo $radio_id; ?>" class="uwp-cb-enable"><span><?php _e('Yes', 'userswp'); ?></span></label>
2623 + // delete the meta column
2624 + if ( isset( $field->htmlvar_name ) && $delete_meta ) {
2625 + $register_forms = uwp_get_option( 'multiple_registration_forms' );
2626 + $custom_fields = array();
2013 2627
2014 - <input type="radio" id="is_register_only_field_no<?php echo $radio_id; ?>" name="is_register_only_field" class="uwp-ri-disabled" value="0" <?php checked(0, $register_only_value); ?> />
2015 - <label for="is_register_only_field_no<?php echo $radio_id; ?>" class="uwp-cb-disable"><span><?php _e('No', 'userswp'); ?></span></label>
2016 - </div>
2017 - <?php } ?>
2018 - </li>
2019 - <?php
2020 - }
2628 + if ( ! empty( $register_forms ) && is_array( $register_forms ) ) {
2629 + foreach ( $register_forms as $key => $register_form ) {
2630 + $form_ids[] = (int) $register_form['id'];
2631 + }
2021 2632
2022 - public function uwp_return_empty_string() {
2023 - return "";
2024 - }
2633 + if ( isset( $form_ids ) && count( $form_ids ) > 0 ) {
2634 + $form_ids_placeholder = array_fill( 0, count( $form_ids ), '%d' );
2635 + $form_ids_placeholder = implode( ', ', $form_ids_placeholder );
2636 + $query = $wpdb->prepare( 'SELECT id FROM ' . $table_name . " WHERE form_type = 'account' AND htmlvar_name = '" . $field->htmlvar_name . "' AND form_id IN (" . $form_ids_placeholder . ') ORDER BY sort_order ASC', $form_ids );
2637 + $custom_fields = $wpdb->get_results( $query );
2638 + }
2639 + }
2025 2640
2026 - public function uwp_register_available_fields_head($heading, $form_type)
2027 - {
2028 - switch ($form_type)
2029 - {
2030 - case 'register':
2031 - $heading = __('Available register form fields.', 'userswp');
2032 - break;
2033 - }
2034 - return $heading;
2035 - }
2641 + if ( isset( $custom_fields ) && ! empty( $custom_fields ) && count( $custom_fields ) > 1 ) {
2642 + // Do not delete user meta column if field used in more than one form.
2643 + } else {
2644 + $col_name = sanitize_sql_orderby( $field->htmlvar_name );
2645 + $wpdb->query( "ALTER TABLE `{$meta_table}` DROP COLUMN `{$col_name}`" );
2646 + }
2647 + }
2036 2648
2649 + $wpdb->query( $wpdb->prepare( 'delete from ' . $table_name . ' where id= %d AND form_id = %d', array( $cf, $form_id ) ) );
2037 2650
2038 - public function uwp_register_available_fields_note($note, $form_type)
2039 - {
2040 - switch ($form_type)
2041 - {
2042 - case 'register':
2043 - $note = __("Click on any box below to make it appear in register form. To make a field available here, go to account tab and expand any field from selected fields panel and tick the checkbox saying 'Include this field in register form'.", 'userswp');
2044 - break;
2045 - }
2046 - return $note;
2047 - }
2651 + // Also delete register form field
2652 + $wpdb->query( $wpdb->prepare( 'delete from ' . $extras_table_name . ' where site_htmlvar_name= %s AND form_id = %d ', array( $field->htmlvar_name, $form_id ) ) );
2048 2653
2654 + do_action( 'uwp_after_custom_field_deleted', $cf, $field );
2049 2655
2050 - public function uwp_register_selected_fields_head($heading, $form_type)
2051 - {
2052 - switch ($form_type)
2053 - {
2054 - case 'register':
2055 - $heading = __('List of fields those will appear in register form.', 'userswp');
2056 - break;
2656 + return $field_id;
2657 + } else {
2658 + return 0;
2659 + }
2660 + } else {
2661 + return 0;
2662 + }
2663 + }
2057 2664
2058 - }
2059 - return $heading;
2060 - }
2665 + public function admin_form_field_save( $request_field = array() ) {
2061 2666
2667 + global $wpdb;$wpdb->show_errors();
2062 2668
2063 - public function uwp_register_selected_fields_note($note, $form_type)
2064 - {
2065 - switch ($form_type)
2066 - {
2067 - case 'register':
2068 - $note = __('Click to expand and view field related settings. You may drag and drop to arrange fields order in register form.', 'userswp');
2069 - break;
2669 + $table_name = uwp_get_table_prefix() . 'uwp_form_fields';
2070 2670
2071 - }
2072 - return $note;
2073 - }
2671 + $meta_table = get_usermeta_table_prefix() . 'uwp_usermeta';
2074 2672
2673 + $old_html_variable = '';
2075 2674
2076 - public function uwp_manage_register_available_fields($form_type)
2077 - {
2078 - switch ($form_type) {
2079 - case 'register':
2080 - $this->uwp_register_available_fields($form_type);
2081 - break;
2082 - }
2083 - }
2675 + $result_str = isset( $request_field['field_id'] ) ? trim( $request_field['field_id'] ) : '';
2676 + $form_id = isset( $request_field['form_id'] ) ? (int) $request_field['form_id'] : 1;
2084 2677
2085 - public function uwp_manage_register_selected_fields($form_type)
2086 - {
2087 - switch ($form_type) {
2088 - case 'register':
2089 - $this->uwp_register_selected_fields($form_type);
2090 - break;
2091 - }
2092 - }
2678 + $user_meta_info = null;
2093 2679
2094 - public function uwp_register_available_fields($form_type)
2095 - {
2096 - global $wpdb;
2680 + // some servers fail if a POST value is VARCHAR so we change it.
2681 + if ( isset( $request_field['data_type'] ) && $request_field['data_type'] == 'XVARCHAR' ) {
2682 + $request_field['data_type'] = 'VARCHAR';
2683 + }
2097 2684
2098 - $extras_table_name = uwp_get_table_prefix() . 'uwp_form_extras';
2685 + $cf = trim( $result_str, '_' );
2099 2686
2100 - $existing_fields = $wpdb->get_results("select site_htmlvar_name from " . $extras_table_name . " where form_type ='" . $form_type . "'");
2687 + $cehhtmlvar_name = isset( $request_field['htmlvar_name'] ) ? $request_field['htmlvar_name'] : '';
2688 + $form_type = $request_field['form_type'];
2101 2689
2102 - $existing_field_ids = array();
2103 - if (!empty($existing_fields)) {
2104 - foreach ($existing_fields as $existing_field) {
2105 - $existing_field_ids[] = $existing_field->site_htmlvar_name;
2106 - }
2107 - }
2108 - ?>
2109 - <input type="hidden" name="form_type" id="form_type" value="<?php echo $form_type; ?>"/>
2110 - <input type="hidden" name="manage_field_type" class="manage_field_type" value="register">
2111 - <ul>
2112 - <?php
2690 + $old_html_variable_name = 'uwp_account_' . $cehhtmlvar_name;
2691 + $check_old_html_variable = $wpdb->get_var(
2692 + $wpdb->prepare(
2693 + 'select htmlvar_name from ' . $table_name . ' where id <> %d and htmlvar_name = %s and form_type = %s and form_id = %d',
2694 + array( $cf, $old_html_variable_name, $form_type, $form_id )
2695 + )
2696 + );
2113 2697
2114 - $fields = $this->uwp_register_fields($form_type);
2698 + $check_html_variable = $wpdb->get_var(
2699 + $wpdb->prepare(
2700 + 'select htmlvar_name from ' . $table_name . ' where id <> %d and htmlvar_name = %s and form_type = %s and form_id = %d',
2701 + array( $cf, $cehhtmlvar_name, $form_type, $form_id )
2702 + )
2703 + );
2115 2704
2116 - if (!empty($fields)) {
2117 - foreach ($fields as $field) {
2118 - $field = stripslashes_deep($field); // strip slashes
2705 + if ( ( ! $check_old_html_variable && ! $check_html_variable ) || $request_field['field_type'] == 'fieldset' ) {
2119 2706
2707 + if ( $cf != '' ) {
2120 2708
2121 - $fieldset_width = '';
2122 - if ($field['field_type'] == 'fieldset') {
2123 - $fieldset_width = 'width:100%;';
2124 - }
2709 + $user_meta_info = $wpdb->get_row(
2710 + $wpdb->prepare(
2711 + 'select * from ' . $table_name . ' where id = %d',
2712 + array( $cf )
2713 + )
2714 + );
2125 2715
2126 - $display = '';
2127 - if (in_array($field['htmlvar_name'], $existing_field_ids))
2128 - $display = 'display:none;';
2716 + }
2129 2717
2130 - $style = 'style="' . $display . $fieldset_width . '"';
2131 - ?>
2132 - <li <?php echo $style; ?> >
2718 + if ( ! empty( $user_meta_info ) ) {
2719 + $old_html_variable = $user_meta_info->htmlvar_name;
2133 2720
2134 - <a id="uwp-<?php echo $field['htmlvar_name']; ?>"
2135 - class="uwp-draggable-form-items uwp-<?php echo $field['field_type']; ?>"
2136 - href="javascript:void(0);" data-type="<?php echo $field['field_type']; ?>">
2721 + }
2137 2722
2138 - <?php if ($icon = uwp_get_field_icon($field['field_icon'])) {
2139 - echo $icon;
2140 - } else {
2141 - echo '<i class="fas fa-cog" aria-hidden="true"></i>';
2142 - }?>
2723 + $site_title = sanitize_text_field( $request_field['site_title'] );
2724 + $form_label = isset( $request_field['form_label'] ) ? sanitize_text_field( $request_field['form_label'] ) : '';
2725 + $help_text = isset( $request_field['help_text'] ) ? sanitize_text_field( $request_field['help_text'] ) : '';
2726 + $field_type = sanitize_text_field( $request_field['field_type'] );
2727 + $data_type = sanitize_text_field( $request_field['data_type'] );
2728 + $field_type_key = isset( $request_field['field_type_key'] ) ? sanitize_text_field( $request_field['field_type_key'] ) : $field_type;
2729 + $htmlvar_name = isset( $request_field['htmlvar_name'] ) ? str_replace(
2730 + array(
2731 + '-',
2732 + ' ',
2733 + '"',
2734 + "'",
2735 + ),
2736 + array( '_', '', '', '' ),
2737 + sanitize_title_with_dashes( $request_field['htmlvar_name'] )
2738 + ) : null;
2739 + $default_value = isset( $request_field['default_value'] ) ? sanitize_text_field( $request_field['default_value'] ) : '';
2740 + $sort_order = isset( $request_field['sort_order'] ) ? absint( $request_field['sort_order'] ) : '';
2741 + $is_active = isset( $request_field['is_active'] ) ? absint( $request_field['is_active'] ) : 1;
2742 + $placeholder_value = isset( $request_field['placeholder_value'] ) ? $request_field['placeholder_value'] : '';
2743 + $for_admin_use = isset( $request_field['for_admin_use'] ) ? absint( $request_field['for_admin_use'] ) : 0;
2744 + $is_required = isset( $request_field['is_required'] ) ? absint( $request_field['is_required'] ) : 0;
2745 + $is_dummy = isset( $request_field['is_dummy'] ) ? absint( $request_field['is_dummy'] ) : 0;
2746 + $is_public = isset( $request_field['is_public'] ) ? absint( $request_field['is_public'] ) : 0;
2747 + $is_default = isset( $request_field['is_default'] ) ? absint( $request_field['is_default'] ) : 0;
2748 + $is_register_field = isset( $request_field['is_register_field'] ) ? absint( $request_field['is_register_field'] ) : 0;
2749 + $is_search_field = isset( $request_field['is_search_field'] ) ? absint( $request_field['is_search_field'] ) : 0;
2750 + $is_register_only_field = isset( $request_field['is_register_only_field'] ) ? absint( $request_field['is_register_only_field'] ) : 0;
2751 + $required_msg = isset( $request_field['required_msg'] ) ? sanitize_text_field( $request_field['required_msg'] ) : '';
2752 + $css_class = isset( $request_field['css_class'] ) ? sanitize_text_field( $request_field['css_class'] ) : '';
2753 + $field_icon = isset( $request_field['field_icon'] ) ? sanitize_text_field( $request_field['field_icon'] ) : '';
2754 + $show_in = isset( $request_field['show_in'] ) ? $request_field['show_in'] : '';
2755 + $user_roles = isset( $request_field['user_roles'] ) ? $request_field['user_roles'] : '';
2756 + $decimal_point = isset( $request_field['decimal_point'] ) ? absint( $request_field['decimal_point'] ) : ''; // decimal point for DECIMAL data type
2757 + $decimal_point = $decimal_point > 0 ? ( $decimal_point > 10 ? 10 : $decimal_point ) : '';
2758 + $validation_pattern = isset( $request_field['validation_pattern'] ) ? sanitize_text_field( $request_field['validation_pattern'] ) : '';
2759 + $validation_msg = isset( $request_field['validation_msg'] ) ? sanitize_text_field( $request_field['validation_msg'] ) : '';
2760 + $user_sort = isset( $request_field['user_sort'] ) ? absint( $request_field['user_sort'] ) : 0;
2143 2761
2144 - <?php echo $field['site_title']; ?>
2762 + if ( empty( $htmlvar_name ) ) {
2763 + $htmlvar_name = sanitize_key(
2764 + str_replace(
2765 + array( '-', ' ', '"', "'" ),
2766 + array(
2767 + '_',
2768 + '_',
2769 + '',
2770 + '',
2771 + ),
2772 + $request_field['site_title']
2773 + )
2774 + );
2775 + if ( str_replace( '_', '', $htmlvar_name ) != '' ) {
2776 + $htmlvar_name = substr( $htmlvar_name, 0, 50 );
2777 + } else {
2778 + $htmlvar_name = time();
2779 + }
2780 + }
2145 2781
2782 + if ( is_array( $show_in ) ) {
2783 + $show_in = implode( ',', $request_field['show_in'] );
2784 + $show_in = sanitize_text_field( $show_in );
2785 + }
2146 2786
2147 - </a>
2148 - </li>
2787 + if ( is_array( $user_roles ) ) {
2788 + $user_roles = implode( ',', $request_field['user_roles'] );
2789 + $user_roles = sanitize_text_field( $user_roles );
2790 + }
2149 2791
2792 + $option_values = '';
2793 + if ( isset( $request_field['option_values'] ) ) {
2794 + $option_values = $request_field['option_values'];
2795 + }
2150 2796
2151 - <?php
2152 - }
2153 - }
2154 - ?>
2155 - </ul>
2156 - <?php
2157 - }
2797 + if ( isset( $request_field['extra'] ) && ! empty( $request_field['extra'] ) ) {
2798 + $extra_fields = $request_field['extra'];
2799 + }
2158 2800
2159 - public function uwp_register_fields($form_type)
2160 - {
2161 - $fields = array();
2801 + if ( $sort_order == '' ) {
2162 2802
2163 - return apply_filters('uwp_register_fields', $fields, $form_type);
2164 - }
2165 -
2166 - public function uwp_register_extra_fields($fields, $form_type)
2167 - {
2168 - global $wpdb;
2803 + $last_order = $wpdb->get_var( 'SELECT MAX(sort_order) as last_order FROM ' . $table_name );
2169 2804
2170 - $table_name = uwp_get_table_prefix() . 'uwp_form_fields';
2171 - $records = $wpdb->get_results($wpdb->prepare("select * from " . $table_name . " where form_type = %s and is_register_field=%s order by sort_order asc", array('account', '1')));
2805 + $sort_order = (int) $last_order + 1;
2806 + }
2172 2807
2173 - foreach ($records as $row) {
2174 - $field_type = $row->field_type;
2175 - $fields[] = array(
2176 - 'field_type' => $field_type,
2177 - 'site_title' => $row->site_title,
2178 - 'htmlvar_name' => $row->htmlvar_name,
2179 - 'field_icon' => $row->field_icon
2180 - );
2181 - }
2182 - return $fields;
2183 - }
2808 + if ( ! empty( $user_meta_info ) ) {
2184 2809
2185 - public function uwp_register_selected_fields($form_type)
2186 - {
2187 - global $wpdb;
2188 - $extras_table_name = uwp_get_table_prefix() . 'uwp_form_extras';
2189 - ?>
2190 - <input type="hidden" name="manage_field_type" class="manage_field_type" value="register">
2191 - <ul class="uwp_form_extras"><?php
2810 + $excluded = uwp_get_excluded_fields();
2192 2811
2193 - $fields = $wpdb->get_results(
2194 - $wpdb->prepare(
2195 - "select * from " . $extras_table_name . " where form_type = %s order by sort_order asc",
2196 - array($form_type)
2197 - )
2198 - );
2812 + if ( ! in_array( $htmlvar_name, $excluded ) ) {
2813 + // Create custom columns
2814 + switch ( $field_type ) :
2199 2815
2200 - if (!empty($fields)) {
2201 - foreach ($fields as $field) {
2202 - $result_str = $field;
2203 - $field_ins_upd = 'display';
2816 + case 'checkbox':
2817 + case 'multiselect':
2818 + case 'select':
2819 + $op_size = '500';
2204 2820
2205 - $default = false;
2821 + // only make the field as big as it needs to be.
2822 + if ( isset( $option_values ) && $option_values && $field_type == 'select' ) {
2823 + $option_values_arr = explode( ',', $option_values );
2824 + if ( isset( $option_values_arr ) && is_array( $option_values_arr ) ) {
2825 + $op_max = 0;
2826 + foreach ( $option_values_arr as $op_val ) {
2827 + if ( strlen( $op_val ) && strlen( $op_val ) > $op_max ) {
2828 + $op_max = strlen( $op_val );
2829 + }
2830 + }
2831 + if ( $op_max ) {
2832 + $op_size = $op_max;
2833 + }
2834 + }
2835 + } elseif ( isset( $option_values ) && $option_values && $field_type == 'multiselect' ) {
2836 + if ( strlen( $option_values ) ) {
2837 + $op_size = strlen( $option_values );
2838 + }
2839 + }
2206 2840
2207 - $this->uwp_register_field_adminhtml($result_str, $field_ins_upd, $default);
2208 - }
2209 - }?>
2210 - </ul>
2211 - <?php
2212 - }
2841 + $meta_field_add = 'ALTER TABLE ' . $meta_table . ' CHANGE `' . $old_html_variable . '` `' . $htmlvar_name . "`VARCHAR( $op_size ) NULL";
2213 2842
2214 - public function uwp_register_field_adminhtml($result_str, $field_ins_upd = '', $default = false, $request = array())
2215 - {
2216 - global $wpdb;
2843 + if ( $default_value != '' ) {
2844 + $meta_field_add .= " DEFAULT '" . $default_value . "'";
2845 + }
2217 2846
2218 - $table_name = uwp_get_table_prefix() . 'uwp_form_fields';
2219 - $extras_table_name = uwp_get_table_prefix() . 'uwp_form_extras';
2847 + $alter_result = $wpdb->query( $meta_field_add );
2848 + if ( $alter_result === false ) {
2849 + return __( 'Column change failed, you may have too many columns.', 'userswp' );
2850 + }
2220 2851
2221 - $cf = $result_str;
2222 - if (!is_object($cf) && (is_int($cf) || ctype_digit($cf))) {
2223 - $field_info = $wpdb->get_row($wpdb->prepare("select * from " . $extras_table_name . " where id= %d", array($cf)));
2224 - } elseif (is_object($cf)) {
2225 - //$field_info = $cf;
2226 - $result_str = $cf->id;
2227 - $field_info = $wpdb->get_row($wpdb->prepare("select * from " . $extras_table_name . " where id= %d", array((int) $cf->id)));
2228 - } else {
2229 - $field_info = false;
2230 - }
2852 + if ( isset( $request_field['cat_display_type'] ) ) {
2853 + $extra_fields = $request_field['cat_display_type'];
2854 + }
2231 2855
2856 + if ( isset( $request_field['multi_display_type'] ) ) {
2857 + $extra_fields = $request_field['multi_display_type'];
2858 + }
2232 2859
2233 - if (isset($request['field_type']) && $request['field_type'] != '')
2234 - $field_type = esc_attr($request['field_type']);
2235 - else
2236 - $field_type = $field_info->field_type;
2860 + break;
2237 2861
2862 + case 'textarea':
2863 + case 'editor':
2864 + case 'url':
2865 + case 'file':
2866 + $alter_result = $wpdb->query( 'ALTER TABLE ' . $meta_table . ' CHANGE `' . $old_html_variable . '` `' . $htmlvar_name . '` TEXT NULL' );
2867 + if ( $alter_result === false ) {
2868 + return __( 'Column change failed, you may have too many columns.', 'userswp' );
2869 + }
2870 + if ( isset( $request_field['advanced_editor'] ) ) {
2871 + $extra_fields = $request_field['advanced_editor'];
2872 + }
2238 2873
2239 - $field_site_name = '';
2240 - if (isset($request['site_title'])) {
2241 - $field_site_name = $request['site_title'];
2242 - }
2874 + break;
2243 2875
2244 - if ($field_info) {
2245 - $account_field_info = $wpdb->get_row($wpdb->prepare("select * from " . $table_name . " where htmlvar_name= %s", array($field_info->site_htmlvar_name)));
2246 - if (isset($account_field_info->site_title)) {
2247 - if ($account_field_info->field_type == 'fieldset') {
2248 - $field_site_name = __('Fieldset:', 'userswp') . ' ' . $account_field_info->site_title;
2249 - } else {
2250 - $field_site_name = $account_field_info->site_title;
2251 - }
2252 - }
2253 - $field_info = stripslashes_deep($field_info); // strip slashes
2254 - }
2255 - $field_site_name = sanitize_title($field_site_name);
2876 + case 'fieldset':
2877 + // Nothing happened for fieldset
2878 + break;
2256 2879
2257 - if (isset($request['form_type'])) {
2258 - $form_type = esc_attr($request['form_type']);
2259 - } else {
2260 - $form_type = $field_info->form_type;
2261 - }
2880 + default:
2881 + if ( $data_type != 'VARCHAR' && $data_type != '' ) {
2882 + if ( $data_type == 'FLOAT' && $decimal_point > 0 ) {
2883 + $default_value_add = 'ALTER TABLE ' . $meta_table . ' CHANGE `' . $old_html_variable . '` `' . $htmlvar_name . '` DECIMAL(11, ' . (int) $decimal_point . ') NULL';
2884 + } else {
2885 + $default_value_add = 'ALTER TABLE ' . $meta_table . ' CHANGE `' . $old_html_variable . '` `' . $htmlvar_name . '` ' . $data_type . ' NULL';
2886 + }
2262 2887
2263 - if (isset($request['is_default']) && $request['is_default'] != '') {
2264 - $default = esc_attr($request['is_default']);
2265 - } else {
2266 - $default = $field_info->is_default;
2267 - }
2888 + if ( is_numeric( $default_value ) && $default_value != '' ) {
2889 + $default_value_add .= " DEFAULT '" . $default_value . "'";
2890 + }
2891 + } else {
2892 + $default_value_add = 'ALTER TABLE ' . $meta_table . ' CHANGE `' . $old_html_variable . '` `' . $htmlvar_name . '` VARCHAR( 254 ) NULL';
2893 + if ( $default_value != '' ) {
2894 + $default_value_add .= " DEFAULT '" . $default_value . "'";
2895 + }
2896 + }
2268 2897
2269 - if (isset($request['htmlvar_name']) && $request['htmlvar_name'] != '') {
2270 - $htmlvar_name = esc_attr($request['htmlvar_name']);
2271 - } else {
2272 - $htmlvar_name = $field_info->site_htmlvar_name;
2273 - }
2898 + $alter_result = $wpdb->query( $default_value_add );
2899 + if ( $alter_result === false ) {
2900 + return __( 'Column change failed, you may have too many columns.', 'userswp' );
2901 + }
2902 + break;
2903 + endswitch;
2904 + }
2274 2905
2275 - if (isset($htmlvar_name)) {
2276 - if (!is_object($field_info)) {$field_info = new stdClass(); }
2277 - $field_info->field_icon = $wpdb->get_var(
2278 - $wpdb->prepare("SELECT field_icon FROM " . $table_name . " WHERE htmlvar_name = %s", array($htmlvar_name))
2279 - );
2280 - }
2906 + $extra_field_query = '';
2907 + if ( ! empty( $extra_fields ) ) {
2908 + $extra_field_query = serialize( $extra_fields );
2909 + }
2281 2910
2282 - if (isset($field_info->field_icon) && strpos($field_info->field_icon, ' fa-') !== false) {
2283 - $field_icon = '<i class="' . $field_info->field_icon . '" aria-hidden="true"></i>';
2284 - }elseif (isset($field_info->field_icon) && $field_info->field_icon) {
2285 - $field_icon = '<b style="background-image: url("' . $field_info->field_icon . '")"></b>';
2286 - }
2287 - elseif (isset($field_info->field_type) && $field_info->field_type == 'fieldset') {
2288 - $field_icon = '<i class="fas fa-arrows-alt-h" aria-hidden="true"></i>';
2289 - } else {
2290 - $field_icon = '<i class="fas fa-cog" aria-hidden="true"></i>';
2291 - }
2911 + $wpdb->query(
2912 + $wpdb->prepare(
2913 + 'update ' . $table_name . ' set
2914 + form_type = %s,
2915 + site_title = %s,
2916 + form_label = %s,
2917 + help_text = %s,
2918 + field_type = %s,
2919 + data_type = %s,
2920 + decimal_point = %s,
2921 + field_type_key = %s,
2922 + htmlvar_name = %s,
2923 + default_value = %s,
2924 + sort_order = %s,
2925 + is_active = %s,
2926 + placeholder_value = %s,
2927 + for_admin_use = %s,
2928 + is_default = %s,
2929 + is_required = %s,
2930 + is_dummy = %s,
2931 + is_public = %s,
2932 + is_register_field = %s,
2933 + is_search_field = %s,
2934 + is_register_only_field = %s,
2935 + required_msg = %s,
2936 + css_class = %s,
2937 + field_icon = %s,
2938 + show_in = %s,
2939 + user_roles = %s,
2940 + option_values = %s,
2941 + extra_fields = %s,
2942 + validation_pattern = %s,
2943 + validation_msg = %s,
2944 + form_id = %d,
2945 + user_sort = %s
2946 + where id = %d',
2947 + array(
2948 + $form_type,
2949 + $site_title,
2950 + $form_label,
2951 + $help_text,
2952 + $field_type,
2953 + $data_type,
2954 + $decimal_point,
2955 + $field_type_key,
2956 + $htmlvar_name,
2957 + $default_value,
2958 + $sort_order,
2959 + $is_active,
2960 + $placeholder_value,
2961 + $for_admin_use,
2962 + $is_default,
2963 + $is_required,
2964 + $is_dummy,
2965 + $is_public,
2966 + $is_register_field,
2967 + $is_search_field,
2968 + $is_register_only_field,
2969 + $required_msg,
2970 + $css_class,
2971 + $field_icon,
2972 + $show_in,
2973 + $user_roles,
2974 + $option_values,
2975 + $extra_field_query,
2976 + $validation_pattern,
2977 + $validation_msg,
2978 + $form_id,
2979 + $user_sort,
2980 + $cf,
2981 + )
2982 + )
2983 + );
2292 2984
2293 - ?>
2294 - <li class="text" id="licontainer_<?php echo $result_str; ?>">
2295 - <form><!-- we need to wrap in a fom so we can use radio buttons with same name -->
2296 - <div class="title title<?php echo $result_str; ?> gt-fieldset"
2297 - title="<?php _e('Double Click to toggle and drag-drop to sort', 'userswp'); ?>"
2298 - ondblclick="uwp_show_hide_register('field_frm<?php echo $result_str; ?>')">
2299 - <?php
2985 + $lastid = trim( $cf );
2300 2986
2301 - $nonce = wp_create_nonce('uwp_form_extras_nonce' . $result_str);
2302 - ?>
2987 + do_action( 'uwp_after_custom_fields_updated', $lastid );
2303 2988
2304 - <?php if ($default == '1'): ?>
2305 - <?php else: ?>
2306 - <div title="<?php _e('Click to remove field', 'userswp'); ?>"
2307 - onclick="delete_register_field('<?php echo $result_str; ?>', '<?php echo $nonce; ?>','<?php echo $htmlvar_name; ?>')"
2308 - class="handlediv close"><i class="fas fa-times" aria-hidden="true"></i></div>
2309 - <?php endif;
2310 - echo $field_icon;
2311 - ?>
2312 - <b style="cursor:pointer;"
2313 - onclick="uwp_show_hide_register('field_frm<?php echo $result_str; ?>')"><?php echo uwp_ucwords(' ' . $field_site_name); ?></b>
2989 + } else {
2314 2990
2315 - </div>
2991 + switch ( $field_type ) :
2316 2992
2317 - <div id="field_frm<?php echo $result_str; ?>" class="field_frm"
2318 - style="display:<?php if ($field_ins_upd == 'submit') {
2319 - echo 'block;';
2320 - } else {
2321 - echo 'none;';
2322 - } ?>">
2323 - <input type="hidden" name="_wpnonce" value="<?php echo $nonce; ?>"/>
2324 - <input type="hidden" name="field_id" id="field_id" value="<?php echo esc_attr($result_str); ?>"/>
2325 - <input type="hidden" name="form_type" id="form_type" value="<?php echo $form_type; ?>"/>
2326 - <input type="hidden" name="field_type" id="field_type" value="<?php echo $field_type; ?>"/>
2327 - <input type="hidden" name="is_active" id="is_active" value="1"/>
2328 - <ul class="widefat post fixed" style="width:100%;">
2993 + case 'checkbox':
2994 + $data_type = 'TINYINT';
2329 2995
2330 - <input type="hidden" name="site_htmlvar_name" value="<?php echo $htmlvar_name ?>"/>
2996 + $meta_field_add = $data_type . '( 1 ) NOT NULL ';
2997 + if ( (int) $default_value === 1 ) {
2998 + $meta_field_add .= " DEFAULT '1'";
2999 + }
2331 3000
2332 - <li>
2333 - <div class="uwp-input-wrap">
2334 - <p>No options available</p>
2335 - </div>
2336 - </li>
3001 + $add_result = uwp_add_column_if_not_exist( $meta_table, $htmlvar_name, $meta_field_add );
3002 + if ( $add_result === false ) {
3003 + return __( 'Column creation failed, you may have too many columns or the default value does not match with field data type.', 'userswp' );
3004 + }
3005 + break;
3006 + case 'multiselect':
3007 + case 'select':
3008 + $data_type = 'VARCHAR';
3009 + $op_size = '500';
2337 3010
2338 - <li>
2339 - <div class="uwp-input-wrap">
2340 - <?php if ($default != '1' || $field_info->site_htmlvar_name == 'uwp_account_password') { ?>
2341 - <input type="button" class="button button-primary" name="save" id="save"
2342 - value="<?php esc_attr_e('Save', 'userswp'); ?>"
2343 - onclick="save_register_field('<?php echo $result_str; ?>')"/>
2344 - <input type="button" name="delete" value="<?php esc_attr_e('Delete', 'userswp'); ?>"
2345 - onclick="delete_register_field('<?php echo $result_str; ?>', '<?php echo $nonce; ?>','<?php echo $htmlvar_name ?>')"
2346 - class="button"/>
2347 - <?php } ?>
3011 + // only make the field as big as it needs to be.
3012 + if ( isset( $option_values ) && $option_values && $field_type == 'select' ) {
3013 + $option_values_arr = explode( ',', $option_values );
2348 3014
2349 - </div>
2350 - </li>
2351 - </ul>
3015 + if ( isset( $option_values_arr ) && is_array( $option_values_arr ) ) {
3016 + $op_max = 0;
2352 3017
2353 - </div>
2354 - </form>
2355 - </li>
2356 - <?php
2357 - }
3018 + foreach ( $option_values_arr as $op_val ) {
3019 + if ( strlen( $op_val ) && strlen( $op_val ) > $op_max ) {
3020 + $op_max = strlen( $op_val );
3021 + }
3022 + }
2358 3023
2359 - public function uwp_register_ajax_handler()
2360 - {
2361 - if (isset($_REQUEST['create_field'])) {
2362 - $field_id = isset($_REQUEST['field_id']) ? trim(sanitize_text_field($_REQUEST['field_id']), '_') : '';
2363 - $field_action = isset($_REQUEST['field_ins_upd']) ? sanitize_text_field($_REQUEST['field_ins_upd']) : '';
3024 + if ( $op_max ) {
3025 + $op_size = $op_max;
3026 + }
3027 + }
3028 + } elseif ( isset( $option_values ) && $option_values && $field_type == 'multiselect' ) {
3029 + if ( strlen( $option_values ) ) {
3030 + $op_size = strlen( $option_values );
3031 + }
2364 3032
2365 - /* ------- check nonce field ------- */
2366 - if (isset($_REQUEST['update']) && $_REQUEST['update'] == 'update') {
2367 - $field_ids = array();
2368 - if (!empty($_REQUEST['licontainer']) && is_array($_REQUEST['licontainer'])) {
2369 - foreach ($_REQUEST['licontainer'] as $lic_id) {
2370 - $field_ids[] = sanitize_text_field($lic_id);
2371 - }
2372 - }
3033 + if ( isset( $request_field['multi_display_type'] ) ) {
3034 + $extra_fields = $request_field['multi_display_type'];
3035 + }
3036 + }
2373 3037
2374 - $return = uwp_form_extras_field_order($field_ids, "register");
3038 + $meta_field_add = $data_type . "( $op_size ) NULL ";
3039 + if ( $default_value != '' ) {
3040 + $meta_field_add .= " DEFAULT '" . $default_value . "'";
3041 + }
2375 3042
2376 - if (is_array($return)) {
2377 - $return = json_encode($return);
2378 - }
3043 + $add_result = uwp_add_column_if_not_exist( $meta_table, $htmlvar_name, $meta_field_add );
3044 + if ( $add_result === false ) {
3045 + return __( 'Column creation failed, you may have too many columns or the default value does not match with field data type.', 'userswp' );
3046 + }
3047 + break;
3048 + case 'textarea':
3049 + case 'editor':
3050 + case 'url':
3051 + case 'file':
3052 + $data_type = 'TEXT';
2379 3053
2380 - echo $return;
2381 - }
3054 + $meta_field_add = $data_type . ' NULL ';
2382 3055
2383 - /* ---- Show field form in admin ---- */
2384 - if ($field_action == 'new') {
2385 - $form_type = isset($_REQUEST['form_type']) ? sanitize_text_field($_REQUEST['form_type']) : '';
2386 - $fields = $this->uwp_register_fields($form_type);
3056 + $add_result = uwp_add_column_if_not_exist( $meta_table, $htmlvar_name, $meta_field_add );
3057 + if ( $add_result === false ) {
3058 + return __( 'Column creation failed, you may have too many columns or the default value does not match with field data type.', 'userswp' );
3059 + }
2387 3060
3061 + break;
2388 3062
2389 - $_REQUEST['site_field_id'] = isset($_REQUEST['field_id']) ? sanitize_text_field($_REQUEST['field_id']) : '';
2390 - $_REQUEST['is_default'] = '0';
3063 + case 'datepicker':
3064 + $data_type = 'DATE';
2391 3065
2392 - if (!empty($fields)) {
2393 - foreach ($fields as $val) {
2394 - $val = stripslashes_deep($val);
3066 + $meta_field_add = $data_type . ' NULL ';
2395 3067
2396 - if ($val['htmlvar_name'] == $_REQUEST['htmlvar_name']) {
2397 - $_REQUEST['field_type'] = $val['field_type'];
2398 - $_REQUEST['site_title'] = $val['site_title'];
2399 - }
2400 - }
2401 - }
3068 + $add_result = uwp_add_column_if_not_exist( $meta_table, $htmlvar_name, $meta_field_add );
3069 + if ( $add_result === false ) {
3070 + return __( 'Column creation failed, you may have too many columns or the default value must have in valid date format.', 'userswp' );
3071 + }
2402 3072
3073 + break;
2403 3074
2404 - $htmlvar_name = isset($_REQUEST['htmlvar_name']) ? sanitize_text_field($_REQUEST['htmlvar_name']) : '';
3075 + case 'time':
3076 + $data_type = 'TIME';
2405 3077
2406 - $this->uwp_register_field_adminhtml($htmlvar_name, $field_action, false, $_REQUEST);
2407 - }
3078 + $meta_field_add = $data_type . ' NULL ';
2408 3079
2409 - /* ---- Delete field ---- */
2410 - if ($field_id != '' && $field_action == 'delete' && isset($_REQUEST['_wpnonce'])) {
2411 - if (!wp_verify_nonce($_REQUEST['_wpnonce'], 'uwp_form_extras_nonce' . $field_id))
2412 - return;
3080 + $add_result = uwp_add_column_if_not_exist( $meta_table, $htmlvar_name, $meta_field_add );
3081 + if ( $add_result === false ) {
3082 + return __( 'Column creation failed, you may have too many columns or the default value must have in valid time format.', 'userswp' );
3083 + }
2413 3084
2414 - echo $this->uwp_register_field_delete($field_id);
2415 - }
3085 + break;
2416 3086
2417 - /* ---- Save field ---- */
2418 - if ($field_id != '' && $field_action == 'submit' && isset($_REQUEST['_wpnonce'])) {
2419 - if (!wp_verify_nonce($_REQUEST['_wpnonce'], 'uwp_form_extras_nonce' . $field_id))
2420 - return;
3087 + default:
3088 + if ( $data_type != 'VARCHAR' && $data_type != '' ) {
3089 + $meta_field_add = $data_type . ' NULL ';
2421 3090
2422 - foreach ($_REQUEST as $pkey => $pval) {
2423 - $tags = is_array($_REQUEST[$pkey]) ? 'skip_field' : '';
3091 + if ( $data_type == 'FLOAT' && $decimal_point > 0 ) {
3092 + $meta_field_add = 'DECIMAL(11, ' . (int) $decimal_point . ') NULL ';
3093 + }
2424 3094
2425 - if ($tags != 'skip_field') {
2426 - $_REQUEST[$pkey] = strip_tags(sanitize_text_field($_REQUEST[$pkey]), $tags);
2427 - }
2428 - }
3095 + if ( is_numeric( $default_value ) && $default_value != '' ) {
3096 + $meta_field_add .= " DEFAULT '" . $default_value . "'";
3097 + }
3098 + } else {
3099 + $meta_field_add = ' VARCHAR( 254 ) NULL ';
2429 3100
3101 + if ( $default_value != '' ) {
3102 + $meta_field_add .= " DEFAULT '" . $default_value . "'";
3103 + }
3104 + }
2430 3105
2431 - $return = $this->uwp_register_field_save($_REQUEST);
3106 + $add_result = uwp_add_column_if_not_exist( $meta_table, $htmlvar_name, $meta_field_add );
3107 + if ( $add_result === false ) {
3108 + return __( 'Column creation failed, you may have too many columns or the default value does not match with field data type.', 'userswp' );
3109 + }
3110 + break;
3111 + endswitch;
2432 3112
2433 - if (is_int($return)) {
2434 - $lastid = $return;
3113 + $extra_field_query = '';
3114 + if ( ! empty( $extra_fields ) ) {
3115 + $extra_field_query = serialize( $extra_fields );
3116 + }
2435 3117
2436 - $this->uwp_register_field_adminhtml($lastid, 'submit');
2437 - } else {
2438 - echo $return;
2439 - }
2440 - }
2441 - }
2442 - die();
2443 - }
3118 + $wpdb->query(
3119 + $wpdb->prepare(
3120 + 'insert into ' . $table_name . ' set
3121 + form_type = %s,
3122 + site_title = %s,
3123 + form_label = %s,
3124 + help_text = %s,
3125 + field_type = %s,
3126 + data_type = %s,
3127 + decimal_point = %s,
3128 + field_type_key = %s,
3129 + htmlvar_name = %s,
3130 + default_value = %s,
3131 + sort_order = %d,
3132 + is_active = %s,
3133 + placeholder_value = %s,
3134 + for_admin_use = %s,
3135 + is_default = %s,
3136 + is_required = %s,
3137 + is_dummy = %s,
3138 + is_public = %s,
3139 + is_register_field = %s,
3140 + is_search_field = %s,
3141 + is_register_only_field = %s,
3142 + required_msg = %s,
3143 + css_class = %s,
3144 + field_icon = %s,
3145 + show_in = %s,
3146 + user_roles = %s,
3147 + option_values = %s,
3148 + extra_fields = %s,
3149 + validation_pattern = %s,
3150 + validation_msg = %s,
3151 + form_id = %d,
3152 + user_sort = %s ',
3153 + array(
3154 + $form_type,
3155 + $site_title,
3156 + $form_label,
3157 + $help_text,
3158 + $field_type,
3159 + $data_type,
3160 + $decimal_point,
3161 + $field_type_key,
3162 + $htmlvar_name,
3163 + $default_value,
3164 + $sort_order,
3165 + $is_active,
3166 + $placeholder_value,
3167 + $for_admin_use,
3168 + $is_default,
3169 + $is_required,
3170 + $is_dummy,
3171 + $is_public,
3172 + $is_register_field,
3173 + $is_search_field,
3174 + $is_register_only_field,
3175 + $required_msg,
3176 + $css_class,
3177 + $field_icon,
3178 + $show_in,
3179 + $user_roles,
3180 + $option_values,
3181 + $extra_field_query,
3182 + $validation_pattern,
3183 + $validation_msg,
3184 + $form_id,
3185 + $user_sort,
3186 + )
3187 + )
3188 + );
2444 3189
2445 - public function uwp_register_field_save($request_field = array())
2446 - {
2447 - global $wpdb;
2448 - $extras_table_name = uwp_get_table_prefix() . 'uwp_form_extras';
3190 + $lastid = $wpdb->insert_id;
2449 3191
2450 - $result_str = isset($request_field['field_id']) ? trim($request_field['field_id']) : '';
3192 + $lastid = trim( $lastid );
2451 3193
2452 - $cf = trim($result_str, '_');
3194 + }
2453 3195
2454 - /*-------- check duplicate validation --------*/
3196 + return (int) $lastid;
2455 3197
2456 - $site_htmlvar_name = isset($request_field['htmlvar_name']) ? $request_field['htmlvar_name'] : '';
2457 - $form_type = $request_field['form_type'];
2458 - $field_type = $request_field['field_type'];
3198 + } else {
3199 + return 'invalid_key';
3200 + }
3201 + }
2459 3202
2460 - $check_html_variable = $wpdb->get_var($wpdb->prepare("select site_htmlvar_name from " . $extras_table_name . " where id <> %d and site_htmlvar_name = %s and form_type = %s ",
2461 - array($cf, $site_htmlvar_name, $form_type)));
3203 + public function register_ajax_handler() {
3204 + if ( isset( $_REQUEST['create_field'] ) ) {
2462 3205
3206 + if ( ! current_user_can( 'manage_options' ) ) {
3207 + wp_die( -1 );
3208 + }
2463 3209
2464 - if (!$check_html_variable) {
3210 + $form_id = isset( $_REQUEST['form_id'] ) ? sanitize_text_field( $_REQUEST['form_id'] ) : 1;
3211 + $field_id = isset( $_REQUEST['field_id'] ) ? trim( sanitize_text_field( $_REQUEST['field_id'] ), '_' ) : '';
3212 + $field_action = isset( $_REQUEST['field_ins_upd'] ) ? sanitize_text_field( $_REQUEST['field_ins_upd'] ) : '';
2465 3213
2466 - if ($cf != '') {
3214 + /* ------- check nonce field ------- */
3215 + if ( isset( $_REQUEST['update'] ) && $_REQUEST['update'] == 'update' ) {
3216 + $field_ids = array();
3217 + if ( ! empty( $_REQUEST['licontainer'] ) && is_array( $_REQUEST['licontainer'] ) ) {
3218 + foreach ( $_REQUEST['licontainer'] as $lic_id ) {
3219 + $field_ids[] = sanitize_text_field( $lic_id );
3220 + }
3221 + }
2467 3222
2468 - $user_meta_info = $wpdb->get_row(
2469 - $wpdb->prepare(
2470 - "select * from " . $extras_table_name . " where id = %d",
2471 - array($cf)
2472 - )
2473 - );
3223 + $return = uwp_form_extras_field_order( $field_ids, 'register', $form_id );
2474 3224
2475 - }
3225 + if ( is_array( $return ) ) {
3226 + $return = json_encode( $return );
3227 + }
2476 3228
2477 - if ($form_type == '') $form_type = 'register';
3229 + echo $return; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
3230 + }
2478 3231
3232 + /* ---- Show field form in admin ---- */
3233 + if ( $field_action == 'new' ) {
3234 + $form_type = isset( $_REQUEST['form_type'] ) ? sanitize_text_field( $_REQUEST['form_type'] ) : '';
3235 + $fields = $this->register_fields( $form_type, $form_id );
2479 3236
2480 - $site_htmlvar_name = $request_field['site_htmlvar_name'];
2481 - $field_id = (isset($request_field['field_id']) && $request_field['field_id']) ? str_replace('new', '', $request_field['field_id']) : '';
2482 -
3237 + $_REQUEST['site_field_id'] = isset( $_REQUEST['field_id'] ) ? sanitize_text_field( $_REQUEST['field_id'] ) : '';
3238 + $_REQUEST['is_default'] = '0';
2483 3239
2484 - if (!empty($user_meta_info)) {
3240 + if ( ! empty( $fields ) ) {
3241 + foreach ( $fields as $val ) {
3242 + $val = stripslashes_deep( $val );
2485 3243
2486 - $wpdb->query(
2487 - $wpdb->prepare(
2488 - "update " . $extras_table_name . " set
2489 - form_type = %s,
2490 - field_type = %s,
2491 - site_htmlvar_name = %s,
2492 - sort_order = %s
2493 - where id = %d",
2494 - array(
2495 - $form_type,
2496 - $field_type,
2497 - $site_htmlvar_name,
2498 - $field_id,
2499 - $cf
2500 - )
3244 + if ( $val['htmlvar_name'] == $_REQUEST['htmlvar_name'] ) {
3245 + $_REQUEST['field_type'] = $val['field_type'];
3246 + $_REQUEST['site_title'] = $val['site_title'];
3247 + }
3248 + }
3249 + }
2501 3250
2502 - )
3251 + $htmlvar_name = isset( $_REQUEST['htmlvar_name'] ) ? sanitize_text_field( $_REQUEST['htmlvar_name'] ) : '';
2503 3252
2504 - );
3253 + $this->register_field_adminhtml( $htmlvar_name, $field_action, false, $_REQUEST );
3254 + }
2505 3255
2506 - $lastid = trim($cf);
3256 + /* ---- Delete field ---- */
3257 + if ( $field_id != '' && $field_action == 'delete' && isset( $_REQUEST['_wpnonce'] ) ) {
3258 + if ( ! wp_verify_nonce( $_REQUEST['_wpnonce'], 'uwp_form_extras_nonce' . $field_id ) ) {
3259 + return;
3260 + }
2507 3261
3262 + echo $this->register_field_delete( $field_id ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
3263 + }
2508 3264
2509 - } else {
3265 + /* ---- Save field ---- */
3266 + if ( $field_id != '' && $field_action == 'submit' && isset( $_REQUEST['_wpnonce'] ) ) {
3267 + if ( ! wp_verify_nonce( $_REQUEST['_wpnonce'], 'uwp_form_extras_nonce' . $field_id ) ) {
3268 + return;
3269 + }
2510 3270
3271 + foreach ( $_REQUEST as $pkey => $pval ) {
3272 + $tags = is_array( $_REQUEST[ $pkey ] ) ? 'skip_field' : '';
2511 3273
2512 - $wpdb->query(
2513 - $wpdb->prepare(
3274 + if ( $tags != 'skip_field' ) {
3275 + $_REQUEST[ $pkey ] = strip_tags( sanitize_text_field( $_REQUEST[ $pkey ] ), $tags );
3276 + }
3277 + }
2514 3278
2515 - "insert into " . $extras_table_name . " set
2516 - form_type = %s,
2517 - field_type = %s,
2518 - site_htmlvar_name = %s,
2519 - sort_order = %s",
2520 - array($form_type,
2521 - $field_type,
2522 - $site_htmlvar_name,
2523 - $field_id
2524 - )
2525 - )
2526 - );
2527 - $lastid = $wpdb->insert_id;
2528 - $lastid = trim($lastid);
2529 - }
3279 + $return = $this->register_field_save( $_REQUEST );
2530 3280
2531 - return (int) $lastid;
3281 + if ( is_int( $return ) ) {
3282 + $lastid = $return;
2532 3283
3284 + $this->register_field_adminhtml( $lastid, 'submit' );
3285 + } else {
3286 + echo $return; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
3287 + }
3288 + }
3289 + }
3290 + die();
3291 + }
2533 3292
2534 - } else {
2535 - return 'HTML Variable Name should be a unique name';
2536 - }
2537 - }
3293 + public function register_field_delete( $field_id = '' ) {
2538 3294
2539 - public function uwp_register_field_delete($field_id = '')
2540 - {
3295 + global $wpdb;
3296 + $extras_table_name = uwp_get_table_prefix() . 'uwp_form_extras';
2541 3297
2542 - global $wpdb;
2543 - $extras_table_name = uwp_get_table_prefix() . 'uwp_form_extras';
3298 + if ( $field_id != '' ) {
3299 + $cf = trim( $field_id, '_' );
2544 3300
2545 - if ($field_id != '') {
2546 - $cf = trim($field_id, '_');
3301 + $wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $extras_table_name . ' WHERE id= %d ', array( $cf ) ) );
2547 3302
2548 - $wpdb->query($wpdb->prepare("delete from " . $extras_table_name . " where id= %d ", array($cf)));
3303 + return $field_id;
2549 3304
2550 - return $field_id;
3305 + } else {
3306 + return 0;
3307 + }
3308 + }
2551 3309
2552 - } else
2553 - return 0;
3310 + public function register_field_save( $request_field = array() ) {
2554 3311
3312 + if ( ! current_user_can( 'manage_options' ) ) {
3313 + wp_die( -1 );
3314 + }
2555 3315
2556 - }
2557 -
2558 - public function uwp_form_builder_dummy_fields() {
2559 - global $wpdb;
3316 + global $wpdb;
3317 + $extras_table_name = uwp_get_table_prefix() . 'uwp_form_extras';
2560 3318
2561 - $table_name = uwp_get_table_prefix() . 'uwp_form_fields';
2562 - $extras_table_name = uwp_get_table_prefix() . 'uwp_form_extras';
2563 - // This function is intended for testing purpose
2564 - if (isset($_GET['uwp_dummy'])
2565 - && is_admin()
2566 - && is_user_logged_in()
2567 - && current_user_can('manage_options')) {
3319 + $form_id = isset( $request_field['form_id'] ) ? (int) $request_field['form_id'] : '';
3320 + $result_str = isset( $request_field['field_id'] ) ? trim( $request_field['field_id'] ) : '';
2568 3321
2569 - if ($_GET['uwp_dummy'] == 'create') {
2570 - // Account
2571 - $fields = $this->uwp_dummy_custom_fields();
3322 + $cf = trim( $result_str, '_' );
2572 3323
2573 - foreach ($fields as $field_index => $field) {
2574 - $this->uwp_admin_form_field_save($field);
2575 - }
3324 + /*-------- check duplicate validation --------*/
2576 3325
2577 - // Register
2578 - foreach ($fields as $field) {
2579 - $last_order = $wpdb->get_var("SELECT MAX(sort_order) as last_order FROM " . $extras_table_name);
2580 - $sort_order = (int) $last_order + 1;
2581 - $wpdb->query(
2582 - $wpdb->prepare(
3326 + $site_htmlvar_name = isset( $request_field['site_htmlvar_name'] ) ? sanitize_text_field( $request_field['site_htmlvar_name'] ) : sanitize_text_field( $request_field['htmlvar_name'] );
3327 + $form_type = $request_field['form_type'];
3328 + $field_type = $request_field['field_type'];
2583 3329
2584 - "insert into " . $extras_table_name . " set
2585 - form_type = %s,
2586 - field_type = %s,
2587 - is_dummy = %s,
2588 - site_htmlvar_name = %s,
2589 - sort_order = %s",
2590 - array(
2591 - 'register',
2592 - $field['field_type'],
2593 - $field['is_dummy'],
2594 - 'uwp_account_' . $field['htmlvar_name'],
2595 - $sort_order
2596 - )
2597 - )
2598 - );
2599 - }
2600 -
2601 - wp_redirect(admin_url('admin.php?page=uwp_form_builder'));
2602 - exit;
2603 - }
2604 -
2605 -
2606 - if ($_GET['uwp_dummy'] == 'delete') {
2607 -
2608 - $wpdb->query($wpdb->prepare("delete from " . $table_name . " where is_dummy= %s ", array('1')));
2609 - $wpdb->query($wpdb->prepare("delete from " . $extras_table_name . " where is_dummy= %s ", array('1')));
2610 - wp_redirect(admin_url('admin.php?page=uwp_form_builder'));
2611 - exit;
2612 - }
2613 -
2614 - }
2615 -
2616 -
2617 - }
2618 -
2619 - public function uwp_dummy_custom_fields() {
2620 -
2621 - $fields = array();
2622 -
2623 - //Fieldset
2624 - $fields[] = array(
2625 - 'form_type' => 'account',
2626 - 'field_type' => 'fieldset',
2627 - 'site_title' => __('Dummy Fieldset', 'userswp'),
2628 - 'htmlvar_name' => 'dummy_fieldset',
2629 - 'default_value' => '',
2630 - 'option_values' => '',
2631 - 'is_dummy' => '1',
2632 - 'is_public' => '1',
2633 - 'is_active' => '1',
2634 - 'is_register_field' => '1',
2635 - 'is_search_field' => '1',
3330 + $check_html_variable = $wpdb->get_var(
3331 + $wpdb->prepare(
3332 + 'select site_htmlvar_name from ' . $extras_table_name . ' where id <> %d and site_htmlvar_name = %s and form_type = %s and form_id=%d',
3333 + array( $cf, $site_htmlvar_name, $form_type, $form_id )
3334 + )
2636 3335 );
2637 3336
2638 - //Text
2639 - $fields[] = array(
2640 - 'form_type' => 'account',
2641 - 'field_type' => 'text',
2642 - 'site_title' => __('Dummy Text', 'userswp'),
2643 - 'htmlvar_name' => 'dummy_text',
2644 - 'default_value' => '',
2645 - 'option_values' => '',
2646 - 'is_dummy' => '1',
2647 - 'is_public' => '1',
2648 - 'is_active' => '1',
2649 - 'is_register_field' => '1',
2650 - 'is_search_field' => '1',
2651 - );
3337 + if ( ! $check_html_variable ) {
2652 3338
2653 - //Textarea
2654 - $fields[] = array(
2655 - 'form_type' => 'account',
2656 - 'field_type' => 'textarea',
2657 - 'site_title' => __('Dummy Textarea', 'userswp'),
2658 - 'htmlvar_name' => 'dummy_textarea',
2659 - 'default_value' => '',
2660 - 'option_values' => '',
2661 - 'is_dummy' => '1',
2662 - 'is_public' => '1',
2663 - 'is_active' => '1',
2664 - 'is_register_field' => '1',
2665 - 'is_search_field' => '1',
2666 - );
3339 + if ( $cf != '' ) {
2667 3340
2668 - //Checkbox
2669 - $fields[] = array(
2670 - 'form_type' => 'account',
2671 - 'field_type' => 'checkbox',
2672 - 'site_title' => __('Dummy Checkbox', 'userswp'),
2673 - 'htmlvar_name' => 'dummy_checkbox',
2674 - 'default_value' => '',
2675 - 'option_values' => '',
2676 - 'is_dummy' => '1',
2677 - 'is_public' => '1',
2678 - 'is_active' => '1',
2679 - 'is_register_field' => '1',
2680 - 'is_search_field' => '1',
2681 - );
3341 + $user_meta_info = $wpdb->get_row(
3342 + $wpdb->prepare(
3343 + 'select * from ' . $extras_table_name . ' where id = %d',
3344 + array( $cf )
3345 + )
3346 + );
2682 3347
2683 - //Radio
2684 - $fields[] = array(
2685 - 'form_type' => 'account',
2686 - 'field_type' => 'radio',
2687 - 'site_title' => __('Dummy Radio', 'userswp'),
2688 - 'htmlvar_name' => 'dummy_radio',
2689 - 'default_value' => '',
2690 - 'option_values' => __('Value1,Value2,Value3', 'userswp'),
2691 - 'is_dummy' => '1',
2692 - 'is_public' => '1',
2693 - 'is_active' => '1',
2694 - 'is_register_field' => '1',
2695 - 'is_search_field' => '1',
2696 - );
3348 + }
2697 3349
2698 - //Select
2699 - $fields[] = array(
2700 - 'form_type' => 'account',
2701 - 'field_type' => 'select',
2702 - 'site_title' => __('Dummy Select', 'userswp'),
2703 - 'htmlvar_name' => 'dummy_select',
2704 - 'default_value' => '',
2705 - 'option_values' => __('Select Option/,Value1,Value2,Value3', 'userswp'),
2706 - 'is_dummy' => '1',
2707 - 'is_public' => '1',
2708 - 'is_active' => '1',
2709 - 'is_register_field' => '1',
2710 - 'is_search_field' => '1',
2711 - );
3350 + if ( $form_type == '' ) {
3351 + $form_type = 'register';
3352 + }
2712 3353
2713 - //URL
2714 - $fields[] = array(
2715 - 'form_type' => 'account',
2716 - 'field_type' => 'url',
2717 - 'site_title' => __('Dummy URL', 'userswp'),
2718 - 'htmlvar_name' => 'dummy_url',
2719 - 'default_value' => '',
2720 - 'option_values' => '',
2721 - 'is_dummy' => '1',
2722 - 'is_public' => '1',
2723 - 'is_active' => '1',
2724 - 'is_register_field' => '1',
2725 - 'is_search_field' => '1',
2726 - );
3354 + $site_htmlvar_name = sanitize_text_field( $request_field['site_htmlvar_name'] );
3355 + $field_id = ( isset( $request_field['field_id'] ) && $request_field['field_id'] ) ? str_replace( 'new', '', $request_field['field_id'] ) : '';
2727 3356
2728 - //Date
2729 - $fields[] = array(
2730 - 'form_type' => 'account',
2731 - 'field_type' => 'datepicker',
2732 - 'site_title' => __('Dummy Date', 'userswp'),
2733 - 'htmlvar_name' => 'dummy_datepicker',
2734 - 'default_value' => '',
2735 - 'option_values' => '',
2736 - 'is_dummy' => '1',
2737 - 'is_public' => '1',
2738 - 'is_active' => '1',
2739 - 'is_register_field' => '1',
2740 - 'is_search_field' => '1',
2741 - 'extra' => array(
2742 - 'date_format' => 'F j, Y'
2743 - )
2744 - );
3357 + if ( ! empty( $user_meta_info ) ) {
2745 3358
2746 - //Time
2747 - $fields[] = array(
2748 - 'form_type' => 'account',
2749 - 'field_type' => 'time',
2750 - 'site_title' => __('Dummy Time', 'userswp'),
2751 - 'htmlvar_name' => 'dummy_time',
2752 - 'default_value' => '',
2753 - 'option_values' => '',
2754 - 'is_dummy' => '1',
2755 - 'is_public' => '1',
2756 - 'is_active' => '1',
2757 - 'is_register_field' => '1',
2758 - 'is_search_field' => '1',
2759 - );
3359 + $wpdb->query(
3360 + $wpdb->prepare(
3361 + 'update ' . $extras_table_name . ' set
3362 + form_type = %s,
3363 + field_type = %s,
3364 + site_htmlvar_name = %s,
3365 + sort_order = %s,
3366 + form_id = %d
3367 + where id = %d',
3368 + array(
3369 + $form_type,
3370 + $field_type,
3371 + $site_htmlvar_name,
3372 + $field_id,
3373 + $form_id,
3374 + $cf,
3375 + )
3376 + )
3377 + );
2760 3378
2761 - //Phone
2762 - $fields[] = array(
2763 - 'form_type' => 'account',
2764 - 'field_type' => 'phone',
2765 - 'site_title' => __('Dummy Phone', 'userswp'),
2766 - 'htmlvar_name' => 'dummy_phone',
2767 - 'default_value' => '',
2768 - 'option_values' => '',
2769 - 'is_dummy' => '1',
2770 - 'is_public' => '1',
2771 - 'is_active' => '1',
2772 - 'is_register_field' => '1',
2773 - 'is_search_field' => '1',
2774 - );
3379 + $lastid = trim( $cf );
2775 3380
2776 - //Email
2777 - $fields[] = array(
2778 - 'form_type' => 'account',
2779 - 'field_type' => 'email',
2780 - 'site_title' => __('Dummy Email', 'userswp'),
2781 - 'htmlvar_name' => 'dummy_email',
2782 - 'default_value' => '',
2783 - 'option_values' => '',
2784 - 'is_dummy' => '1',
2785 - 'is_public' => '1',
2786 - 'is_active' => '1',
2787 - 'is_register_field' => '1',
2788 - 'is_search_field' => '1',
2789 - );
3381 + } else {
2790 3382
2791 - //Multiselect
2792 - $fields[] = array(
2793 - 'form_type' => 'account',
2794 - 'field_type' => 'multiselect',
2795 - 'site_title' => __('Dummy Multiselect', 'userswp'),
2796 - 'htmlvar_name' => 'dummy_multiselect',
2797 - 'default_value' => '',
2798 - 'option_values' => __('Select Option/,Value1,Value2,Value3', 'userswp'),
2799 - 'is_dummy' => '1',
2800 - 'is_public' => '1',
2801 - 'is_active' => '1',
2802 - 'is_register_field' => '1',
2803 - 'is_search_field' => '1',
2804 - );
3383 + $wpdb->query(
3384 + $wpdb->prepare(
3385 + 'insert into ' . $extras_table_name . ' set
3386 + form_type = %s,
3387 + field_type = %s,
3388 + site_htmlvar_name = %s,
3389 + sort_order = %s,
3390 + form_id = %s',
3391 + array(
3392 + $form_type,
3393 + $field_type,
3394 + $site_htmlvar_name,
3395 + $field_id,
3396 + $form_id,
3397 + )
3398 + )
3399 + );
3400 + $lastid = $wpdb->insert_id;
3401 + $lastid = trim( $lastid );
3402 + }
2805 3403
2806 - //File Upload
2807 - $fields[] = array(
2808 - 'form_type' => 'account',
2809 - 'field_type' => 'file',
2810 - 'site_title' => __('Dummy File', 'userswp'),
2811 - 'htmlvar_name' => 'dummy_file',
2812 - 'default_value' => '',
2813 - 'option_values' => '',
2814 - 'is_dummy' => '1',
2815 - 'is_public' => '1',
2816 - 'is_active' => '1',
2817 - 'is_register_field' => '1',
2818 - 'is_search_field' => '1',
2819 - );
3404 + return (int) $lastid;
2820 3405
2821 - $fields = apply_filters('uwp_dummy_custom_fields', $fields);
2822 -
2823 - return $fields;
2824 - }
2825 -
2826 -}
3406 + } else {
3407 + return 'invalid_key';
3408 + }
3409 + }
3410 +}