PluginProbe
User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor / 4.0.3
User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor v4.0.3
4.0.3 4.0.2 4.0.1 4.0.0 3.16.6 3.16.5 3.16.4 3.16.3 3.16.2 3.16.1 3.16.0 3.15.9 3.9.9 3.9.5 3.9.6 3.9.7 3.9.8 1.1.7 1.1.8 1.1.9 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 All 341 releases
profile-builder / assets / misc / elementor / widgets / class-pb-widget-rf-epf.php

class-pb-widget-rf-epf.php in User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor 4.0.3, at assets/misc/elementor/widgets/class-pb-widget-rf-epf.php

980 lines 44.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 // Exit if accessed directly
4 if ( ! defined( 'ABSPATH' ) ) exit;
5
6 require_once "class-pb-widget-base.php";
7
8 /**
9 * Base class for the Profile Builder Elementor Registration and Edit Profile widgets
10 */
11 abstract class PB_Elementor_Register_Edit_Profile_Widget extends PB_Elementor_Widget {
12
13 /**
14 * Register scripts and styles needed in the Visual Editor.
15 */
16 protected function register_pb_scripts_styles() {
17 //Select2
18 // wp_enqueue_script('wppb_sl2_lib_js', WPPB_PLUGIN_URL . 'assets/js/select2/select2.min.js', array('jquery'));
19 // wp_enqueue_style('wppb_sl2_lib_css', WPPB_PLUGIN_URL . 'assets/css/select2/select2.min.css');
20
21
22 //Upload
23 wp_register_style( 'profile-builder-upload-css', WPPB_PLUGIN_URL.'front-end/default-fields/upload/upload.css', false, PROFILE_BUILDER_VERSION );
24
25 if( defined( 'WPPB_PAID_PLUGIN_URL' ) ){
26 //SelectCPT
27 wp_register_style( 'wppb-select-cpt-style', WPPB_PAID_PLUGIN_URL.'front-end/extra-fields/select-cpt/style-front-end.css', array(), PROFILE_BUILDER_VERSION );
28
29 //Multi-Step Forms compatibility
30 wp_register_style( 'wppb-msf-style-frontend', WPPB_PAID_PLUGIN_URL.'add-ons-advanced/multi-step-forms/assets/css/frontend-multi-step-forms.css', array(), PROFILE_BUILDER_VERSION );
31 }
32 }
33
34 public function get_script_depends() {
35 if ( defined( 'WPPB_PAID_PLUGIN_DIR' ) && file_exists(WPPB_PAID_PLUGIN_DIR . '/front-end/extra-fields/extra-fields.php') ) {
36 return [
37 'wppb_sl2_lib_js',
38 'wppb_select2_js',
39 ];
40 }
41 return [];
42 }
43
44 public function get_style_depends() {
45 $styles = [];
46 if ( defined( 'WPPB_PAID_PLUGIN_DIR' ) && file_exists(WPPB_PAID_PLUGIN_DIR . '/front-end/extra-fields/extra-fields.php') ) {
47 $styles = [
48 'wppb_sl2_lib_css',
49 'wppb_sl2_css',
50 'profile-builder-upload-css',
51 'wppb_select2_css',
52 'wppb-select-cpt-style',
53 ];
54 }
55
56 if ( wppb_check_if_add_on_is_active( 'multi-step-forms' ) ) {
57 $styles[] = 'wppb-msf-style-frontend';
58 }
59
60 return $styles;
61 }
62
63 /**
64 * Add the controls for the Edit Profile and Registration widgets.
65 * @param $form_type
66 */
67 protected function register_rf_epf_controls( $form_type ) {
68 switch ( $form_type ){
69 case 'rf':
70 $section_id_prefix = 'pb_register';
71 $post_type = 'wppb-rf-cpt';
72 $fields_post_meta_key = 'wppb_rf_fields';
73 break;
74 case 'epf':
75 $section_id_prefix = 'pb_edit_profile';
76 $post_type = 'wppb-epf-cpt';
77 $fields_post_meta_key = 'wppb_epf_fields';
78 break;
79 default:
80 return;
81 }
82
83 $wppb_module_settings = get_option( 'wppb_module_settings', 'not_found' );
84
85 $this->start_controls_section(
86 sprintf( '%s_settings_section', $section_id_prefix ),
87 array(
88 'label' => __( 'Form Settings', 'profile-builder' ),
89 'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
90 )
91 );
92
93 $edit_form_links = array(
94 'default' => ''
95 );
96 $form_titles = array(
97 '' => __( 'Default', 'profile-builder' )
98 );
99 $page_titles = $this->get_all_pages();
100 $form_fields = array(
101 'default' => get_option( 'wppb_manage_fields' )
102 );
103 $social_connect_settings = get_option( 'wppb_social_connect_settings' );
104 if ( is_array($social_connect_settings) ) {
105 $social_connect_settings = reset($social_connect_settings);
106 }
107 $social_connect = [];
108
109 if ( !( ( $wppb_module_settings !== 'not_found' && ( (
110 $form_type === 'rf' && (
111 !isset( $wppb_module_settings['wppb_multipleRegistrationForms'] ) ||
112 $wppb_module_settings['wppb_multipleRegistrationForms'] !== 'show'
113 )
114 ) || (
115 $form_type === 'epf' && (
116 !isset( $wppb_module_settings['wppb_multipleEditProfileForms'] ) ||
117 $wppb_module_settings['wppb_multipleEditProfileForms'] !== 'show'
118 )
119 ) )
120 ) ||
121 $wppb_module_settings === 'not_found'
122 )
123 ){
124 $args = array(
125 'post_type' => $post_type,
126 'posts_per_page' => -1
127 );
128
129 $the_query = new WP_Query( $args );
130
131 if ( $the_query->have_posts() ) {
132 foreach ( $the_query->posts as $post ) {
133 $form_titles ['-'.Wordpress_Creation_Kit_PB::wck_generate_slug( $post->post_title )] = $post->post_title ;
134 $edit_form_links [ Wordpress_Creation_Kit_PB::wck_generate_slug( $post->post_title )] = get_edit_post_link($post->ID);
135 $form_fields [ Wordpress_Creation_Kit_PB::wck_generate_slug( $post->post_title )] = get_post_meta($post->ID, $fields_post_meta_key, true);
136 $social_connect [ Wordpress_Creation_Kit_PB::wck_generate_slug( $post->post_title )] = get_post_meta($post->ID, 'wppb_sc_rf_epf_active', true);
137 $msf_break_points [ Wordpress_Creation_Kit_PB::wck_generate_slug( $post->post_title )] = get_post_meta($post->ID, 'wppb_msf_break_points', true);
138 }
139 wp_reset_postdata();
140 }
141 }
142
143 $this->add_control(
144 'pb_form_name',
145 array(
146 'label' => __('Form', 'profile-builder' ),
147 'type' => \Elementor\Controls_Manager::SELECT,
148 'options' => $form_titles,
149 'default' => '',
150 )
151 );
152
153 if ( $form_type === 'rf' ) {
154 if (!function_exists('get_editable_roles')) {
155 require_once ABSPATH . 'wp-admin/includes/user.php';
156 }
157 $user_roles = get_editable_roles();
158 foreach ($user_roles as $key => $role) {
159 $user_roles[$key] = $role['name'];
160 }
161
162 $this->add_control(
163 'pb_role',
164 array(
165 'label' => __('Assigned Role', 'profile-builder'),
166 'type' => \Elementor\Controls_Manager::SELECT,
167 'options' => $user_roles,
168 'default' => get_option('default_role'),
169 'condition' => [
170 'pb_form_name' => '',
171 ],
172 )
173 );
174
175 $this->add_control(
176 'pb_automatic_login',
177 array(
178 'label' => __('Automatic Login', 'profile-builder'),
179 'type' => \Elementor\Controls_Manager::SWITCHER,
180 'label_on' => __('Yes', 'profile-builder'),
181 'label_off' => __('No', 'profile-builder'),
182 'return_value' => 'yes',
183 'default' => '',
184 'condition' => [
185 'pb_form_name' => '',
186 ],
187 )
188 );
189 }
190
191 if( defined( 'WPPB_PAID_PLUGIN_DIR' ) ) {
192 $this->add_control(
193 'pb_ajax',
194 array(
195 'label' => __( 'AJAX Validation', 'profile-builder' ),
196 'type' => \Elementor\Controls_Manager::SWITCHER,
197 'label_on' => __( 'Yes', 'profile-builder' ),
198 'label_off' => __( 'No', 'profile-builder' ),
199 'return_value' => 'true',
200 'default' => 'false',
201 'condition' => [
202 'pb_form_name' => '',
203 ],
204 )
205 );
206 }
207
208 foreach ( $edit_form_links as $form_slug => $edit_form_link ){
209 foreach ($form_fields[$form_slug] as $key_1 => $form_field) {
210 if ($form_slug === 'default') {
211 $form_fields['default'][$key_1]['control_group_conditions']['pb_form_name'][] = '';
212 continue;
213 }
214 foreach ($form_fields['default'] as $key_2 => $form_field_default) {
215 if ($form_field_default['id'] == $form_field['id']) {
216 $form_fields['default'][$key_2]['control_group_conditions']['pb_form_name'][] = '-'.$form_slug;
217 }
218 }
219 }
220 if( $form_slug === 'default' ){
221 continue;
222 }
223
224 // Edit form links
225 $this->add_control(
226 'pb_form_'.$form_slug.'_edit_link' ,
227 array(
228 'type' => \Elementor\Controls_Manager::RAW_HTML,
229 'raw' => sprintf( __( 'Edit the Settings for this form %1$shere%2$s' , 'profile-builder' ), '<a href="'. ( $edit_form_link ? esc_url( $edit_form_link ) : '').'" target="_blank">', '</a>'),
230 'condition'=> [
231 'pb_form_name' => [ '-'.$form_slug ],
232 ],
233 )
234 );
235 }
236
237 $this->end_controls_section();
238
239 $params = [
240 'label' => __( 'Redirects', 'profile-builder' ),
241 'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
242 ];
243 if ( $form_type === 'epf' ){
244 $params['condition'] = [ 'pb_form_name' => '' ];
245 }
246
247 $this->start_controls_section( $section_id_prefix.'_redirects_section', $params );
248
249 unset($params);
250 $params = [
251 'type' => \Elementor\Controls_Manager::SELECT,
252 'options' => $page_titles,
253 'default' => '',
254 'condition' => [
255 'pb_form_name' => '',
256 ],
257 ];
258 if ( $form_type === 'rf' ){
259 $params['label'] = __( 'Redirect after Registration', 'profile-builder' );
260 } else {
261 $params['label'] = __( 'Redirect after Edit Profile', 'profile-builder' );
262 }
263
264 $this->add_control( 'pb_redirect_url', $params );
265
266 if ( $form_type === 'rf' ) {
267 $this->add_control(
268 'pb_logout_redirect_url',
269 array(
270 'label' => __('Redirect after Logout', 'profile-builder'),
271 'type' => \Elementor\Controls_Manager::SELECT,
272 'options' => $page_titles,
273 'default' => '',
274 )
275 );
276 }
277
278 $this->end_controls_section();
279
280 // Style controls for the form fields
281 $this->add_fields_styling( $form_fields['default'], $form_type );
282
283 // Style controls for the 'Send these credentials via email' checkbox
284 if ( $form_type === 'rf' ) {
285 $this->add_styling_control_group(
286 'Send Credentials Checkbox',
287 '',
288 'pb_register_' . $form_slug . '_wppb_send_credentials',
289 [
290 'checkbox' => [
291 'selector' => '.wppb-register-user .wppb-send-credentials-checkbox #send_credentials_via_email',
292 'section_name' => 'Checkbox',
293 ],
294 'label' => [
295 'selector' => '.wppb-register-user .wppb-send-credentials-checkbox label[for=send_credentials_via_email]',
296 'section_name' => 'Label',
297 ]
298 ]
299 );
300 }
301
302 // Style controls for the 'Two-Factor Authentication' field group
303 if ( $form_type === 'epf' && $this->is_2fa_active() ) {
304 $this->add_styling_control_group(
305 'Two-Factor Authentication',
306 '',
307 'pb_edit_profile_' . $form_slug . '_2fa',
308 [
309 '2fa_heading' => [
310 'selector' => '.wppb-2fa-fields .wppb_2fa_heading h4',
311 'section_name' => 'Heading',
312 ],
313 '2fa_activate_label' => [
314 'selector' => '.wppb-2fa-fields label[for=wppb_auth_enabled]',
315 'section_name' => 'Activate Label',
316 ],
317 '2fa_activate_checkbox' => [
318 'selector' => '.wppb-2fa-fields #wppb_auth_enabled',
319 'section_name' => 'Activate Checkbox',
320 ],
321 '2fa_relaxed_label' => [
322 'selector' => '.wppb-2fa-fields label[for=wppb_auth_relaxedmode]',
323 'section_name' => 'Relaxed Mode Label',
324 ],
325 '2fa_relaxed_checkbox' => [
326 'selector' => '.wppb-2fa-fields #wppb_auth_relaxedmode',
327 'section_name' => 'Relaxed Mode Checkbox',
328 ],
329 '2fa_description_label' => [
330 'selector' => '.wppb-2fa-fields label[for=wppb_auth_description]',
331 'section_name' => 'Description Label',
332 ],
333 '2fa_description_input' => [
334 'selector' => '.wppb-2fa-fields #wppb_auth_description',
335 'section_name' => 'Description Input',
336 ],
337 '2fa_description_description' => [
338 'selector' => '.wppb-2fa-fields .wppb-description-delimiter',
339 'section_name' => 'Description Description',
340 ],
341 '2fa_secret_label' => [
342 'selector' => '.wppb-2fa-fields label[for=wppb_auth_secret]',
343 'section_name' => 'Secret Label',
344 ],
345 '2fa_secret_input' => [
346 'selector' => '.wppb-2fa-fields #wppb_auth_secret',
347 'section_name' => 'Secret Input',
348 ],
349 '2fa_new_secret_button' => [
350 'selector' => '.wppb-2fa-fields #wppb_auth_secret_buttons #wppb_auth_newsecret',
351 'section_name' => 'New Secret Button',
352 ],
353 '2fa_qr_code_button' => [
354 'selector' => '.wppb-2fa-fields #wppb_auth_secret_buttons #wppb_show_qr',
355 'section_name' => 'QR Code Button',
356 ],
357 '2fa_verify_label' => [
358 'selector' => '.wppb-2fa-fields .wppb_auth_verify label[for=wppb_auth_passw]',
359 'section_name' => 'Verify TOTP Label',
360 ],
361 '2fa_verify_input' => [
362 'selector' => '.wppb-2fa-fields .wppb_auth_verify #wppb_auth_passw',
363 'section_name' => 'Verify TOTP Input',
364 ],
365 '2fa_check_button' => [
366 'selector' => '.wppb-2fa-fields #wppb_auth_verify_buttons #wppb_auth_verify_button',
367 'section_name' => 'Check Button',
368 ],
369 '2fa_check_indicator' => [
370 'selector' => '.wppb-2fa-fields #wppb_auth_verify_buttons #wppb_auth_verify_indicator',
371 'section_name' => 'Validity Indicator',
372 ],
373 ]
374 );
375 }
376
377 // Style controls for the 'Register'/'Update' button
378 if ( $form_type === 'rf' ) {
379 $this->add_styling_control_group(
380 'Register Button',
381 '',
382 'pb_register_' . $form_slug . '_register_button',
383 [
384 'register_button' => [
385 'selector' => '.wppb-register-user #register.submit.button',
386 'section_name' => 'Register Button',
387 ]
388 ]
389 );
390 } else {
391 $this->add_styling_control_group(
392 'Update Button',
393 '',
394 'pb_edit_profile_'.$form_slug.'_update_button',
395 [
396 'update_button' => [
397 'selector' => '.wppb-edit-user #edit_profile.submit.button',
398 'section_name' => 'Update Button',
399 ]
400 ]
401 );
402 }
403
404 // Style for the Social Connect section
405 if ( $social_connect_settings && strpos($social_connect_settings['display-on-the-following-forms'],
406 ( $form_type === 'rf' ? 'pb-register' : 'pb-edit-profile' )
407 ) ) {
408 $conditions = [];
409
410 foreach ( $edit_form_links as $form_slug => $edit_form_link ) {
411 if ( $form_slug === 'default' ) {
412 $conditions['pb_form_name'][] = '';
413 } elseif ( $social_connect[$form_slug] === 'yes') {
414 $conditions['pb_form_name'][] = '-' . $form_slug;
415 }
416 }
417
418 $this->add_styling_control_group(
419 'Social Connect Section',
420 $conditions,
421 $section_id_prefix . '_' . $form_slug . '_social_connect',
422 [
423 'sc_heading' => [
424 'selector' => '.wppb-sc-heading-before-reg-buttons h3',
425 'section_name' => 'Heading',
426 ],
427 'sc_buttons' => [
428 'selector' => 'a.wppb-sc-button',
429 'section_name' => 'Buttons',
430 ]
431 ]
432 );
433 }
434
435 // Style for the MSF buttons
436 if ( wppb_check_if_add_on_is_active( 'multi-step-forms' ) ) {
437 $conditions = [];
438
439 foreach ( $edit_form_links as $form_slug => $edit_form_link ) {
440 if ( $form_slug === 'default' && !empty( get_option( 'wppb_msf_break_points', false ) ) ) {
441 $conditions['pb_form_name'][] = '';
442 } elseif ( !empty( $msf_break_points[$form_slug] ) ) {
443 $conditions['pb_form_name'][] = '-' . $form_slug;
444 }
445 }
446
447 $sections['msf_default'] = [
448 'selector' => '.wppb-msf-button',
449 'section_name' => 'Default'
450 ];
451 $sections['msf_pagination'] = [
452 'selector' => '.wppb-msf-pagination',
453 'section_name' => 'Pagination'
454 ];
455 $sections['msf_tabs'] = [
456 'selector' => '.wppb-msf-tabs',
457 'section_name' => 'Tabs'
458 ];
459
460 $this->add_styling_control_group(
461 'Multi Step Forms Buttons',
462 $conditions,
463 $section_id_prefix . '_' . $form_slug . '_msf',
464 $sections
465 );
466 }
467
468 }
469
470 /**
471 * Deal with special cases. Add the targets for each field. Add the styling control groups.
472 * @param $form_fields
473 * @param $form_type
474 */
475 protected function add_fields_styling($form_fields, $form_type ){
476 switch ( $form_type ){
477 case 'rf':
478 $section_id_prefix = 'pb_register';
479 $form_class = '.wppb-register-user';
480 break;
481 case 'epf':
482 $section_id_prefix = 'pb_edit_profile';
483 $form_class = '.wppb-edit-user';
484 break;
485 default:
486 return;
487 }
488
489 foreach ( $form_fields as $form_field ) {
490 $targets = [];
491 if ($form_field['field-title'] !== '') {
492 $targets['label'] = '';
493 }
494 if ($form_field['description'] !== '') {
495 $targets['description'] = '';
496 }
497 switch ($form_field['field']) {
498 case 'Default - Name (Heading)':
499 $field_meta = 'default_name_heading';
500 $targets = $this->replace_label_with_heading( $targets );
501 break;
502 case 'Default - Contact Info (Heading)':
503 $field_meta = 'default_contact_info_heading';
504 $targets = $this->replace_label_with_heading( $targets );
505 break;
506 case 'Default - About Yourself (Heading)':
507 $field_meta = 'default_about_yourself_heading';
508 $targets = $this->replace_label_with_heading( $targets );
509 break;
510 case 'Default - Username':
511 $field_meta = 'default_username';
512 $targets = $this->handle_placeholder_labels_active( $targets );
513 $targets['username'] = '';
514 break;
515 case 'Default - E-mail':
516 $field_meta = 'email';
517 $targets = $this->handle_placeholder_labels_active( $targets );
518 $targets['input'] = '';
519 break;
520 case 'Default - Password':
521 $field_meta = 'passw1';
522 $targets = $this->handle_placeholder_labels_active( $targets );
523 $wppb_generalSettings = get_option( 'wppb_general_settings' );
524 if ( !empty( $wppb_generalSettings['minimum_password_length'] ) || !empty( $wppb_generalSettings['minimum_password_strength'] ) ){
525 $targets['description'] = '';
526 }
527 $targets['input'] = '';
528 break;
529 case 'Default - Repeat Password':
530 $field_meta = 'passw2';
531 $targets = $this->handle_placeholder_labels_active( $targets );
532 $targets['input'] = '';
533 break;
534 case 'Default - Display name publicly as':
535 $field_meta = 'default_field_display-name';
536 if ( $form_type === 'rf' ){
537 // this field is only shown on the Edit Profile form
538 unset($targets);
539 } else {
540 $targets['default_field_display'] = '';
541 }
542 break;
543 case 'Default - Website':
544 $field_meta = 'website';
545 $targets = $this->handle_placeholder_labels_active( $targets );
546 $targets['input'] = '';
547 break;
548 case 'Heading':
549 $field_meta = 'heading';
550 $targets = $this->replace_label_with_heading( $targets );
551 break;
552 case 'HTML':
553 $field_meta = 'html';
554 if ($form_field['html-content'] !== '') {
555 $targets['html'] = '';
556 }
557 break;
558 case 'reCAPTCHA':
559 $field_meta = 'recaptcha';
560 $targets = $this->handle_placeholder_labels_active( $targets );
561 if ( $form_type === 'rf' ){
562 // this field is only shown on the Registration form
563 unset($targets);
564 }
565 break;
566 case 'Select (User Role)':
567 $field_meta = 'select_user_role';
568 if ( $form_type === 'rf' ){
569 $targets['select_user_role'] = '';
570 } else {
571 $targets['select_user_role_notice'] = '';
572 }
573 break;
574 case 'GDPR Delete Button':
575 $field_meta = 'gdpr_delete';
576 if ( $form_type === 'rf' ){
577 // this field is only shown on the Edit Profile form
578 unset($targets);
579 } else {
580 $targets['gdpr_delete_button'] = '';
581 }
582 break;
583 case 'Email Confirmation':
584 $field_meta = 'wppb_email_confirmation';
585 $targets = $this->handle_placeholder_labels_active( $targets );
586 $targets['input'] = '';
587 break;
588 case 'Select2':
589 $field_meta = $form_field['meta-name'];
590 $targets['select2'] = '';
591 break;
592 case 'Select (CPT)':
593 $field_meta = $form_field['meta-name'];
594 $targets['select_cpt'] = '';
595 break;
596 case 'Timepicker':
597 $field_meta = $form_field['meta-name'];
598 $targets['timepicker_hours'] = '';
599 $targets['timepicker_minutes'] = '';
600 $targets['timepicker_separator'] = '';
601 break;
602 case 'Checkbox':
603 $field_meta = $form_field['meta-name'];
604 $targets['checkbox'] = '';
605 $targets['checkbox_labels'] = '';
606 break;
607 case 'Radio':
608 $field_meta = $form_field['meta-name'];
609 $targets['radio'] = '';
610 $targets['radio_labels'] = '';
611 break;
612 case 'Upload':
613 $field_meta = $form_field['meta-name'];
614 $targets['upload'] = '';
615 break;
616 case 'Avatar':
617 $field_meta = $form_field['meta-name'];
618 $targets['avatar'] = '';
619 break;
620 case 'Checkbox (Terms and Conditions)':
621 $field_meta = $form_field['meta-name'];
622 if ( $form_type === 'rf' ){
623 $targets['input'] = '';
624 } else {
625 // this field is only shown on the Registration form
626 unset($targets);
627 }
628 break;
629 case 'Subscription Plans':
630 $field_meta = 'pms_subscription_plans';
631 if ( $form_type === 'rf' ){
632 $targets['heading'] = '';
633 $targets['label'] = '';
634 } else {
635 // this field can only be styled on the Registration form
636 unset($targets);
637 }
638 break;
639 case 'Repeater':
640 $field_meta = $form_field['meta-name'];
641 $repeater_fields = get_option( $form_field['meta-name'], 'not_set' );
642 if ( $repeater_fields !== 'not_set' ){
643 foreach ( $repeater_fields as $repeater_key => $repeater_field){
644 $repeater_fields[$repeater_key]['control_group_conditions'] = $form_field['control_group_conditions'];
645 }
646 $this->add_fields_styling( $repeater_fields, $form_type );
647 }
648 unset($targets);
649 break;
650 case 'WooCommerce Customer Billing Address':
651 $field_meta = $form_field['meta-name'];
652 $targets = $this->replace_label_with_heading( $targets );
653 $targets['woo_billing_label'] = ['billing_country','billing_first_name','billing_last_name','billing_company','billing_address_1','billing_address_2','billing_city','billing_state','billing_postcode','billing_email','billing_phone'];
654 $targets['woo_billing_select'] = ['billing_country',];
655 $targets['woo_billing_input'] = ['billing_first_name','billing_last_name','billing_company','billing_address_1','billing_address_2','billing_city','billing_state','billing_postcode','billing_email','billing_phone'];
656 if ( $form_type === 'rf' ){
657 $targets['woo_billing_checkbox'] = ['woo_different_shipping_address'];
658 $targets['woo_billing_checkbox_label'] = ['woo_different_shipping_address'];
659 }
660 break;
661 case 'WooCommerce Customer Shipping Address':
662 $field_meta = $form_field['meta-name'];
663 $targets = $this->replace_label_with_heading( $targets );
664 $targets['woo_shipping_label'] = ['shipping_country','shipping_first_name','shipping_last_name','shipping_company','shipping_address_1','shipping_address_2','shipping_city','shipping_state','shipping_postcode'];
665 $targets['woo_shipping_select'] = ['shipping_country',];
666 $targets['woo_shipping_input'] = ['shipping_first_name','shipping_last_name','shipping_company','shipping_address_1','shipping_address_2','shipping_city','shipping_state','shipping_postcode',];
667 break;
668 case 'WYSIWYG':
669 $field_meta = $form_field['meta-name'];
670 $targets['wysiwyg'] = '';
671 break;
672 case 'Default - First Name':
673 case 'Default - Last Name':
674 case 'Default - Nickname':
675 case 'Default - Biographical Info':
676 case 'Input':
677 case 'Textarea':
678 case 'Phone':
679 case 'Colorpicker':
680 case 'Datepicker':
681 case 'Number':
682 case 'Validation':
683 case 'Email':
684 $field_meta = $form_field['meta-name'];
685 $targets = $this->handle_placeholder_labels_active( $targets );
686 $targets['input'] = '';
687 break;
688 default:
689 $field_meta = $form_field['meta-name'];
690 $targets['input'] = '';
691 }
692
693 if (!empty($targets) && is_array($targets)) {
694 $sections = [];
695 foreach ($targets as $target => $ids) {
696 switch ($target) {
697 case 'label':
698 $sections[$target] = [
699 'selector' => $form_class . ' #wppb-form-element-' . $form_field['id'] . ' label',
700 'section_name' => 'Label',
701 ];
702 break;
703 case 'input':
704 $sections[$target] = [
705 'selector' => $form_class . ' #wppb-form-element-' . $form_field['id'] . ' #' . $field_meta,
706 'section_name' => 'Input',
707 ];
708 break;
709 case 'username':
710 $sections[$target] = [
711 'selector' => $form_class . ' #wppb-form-element-' . $form_field['id'] . ' #username',
712 'section_name' => 'Input',
713 ];
714 break;
715 case 'description':
716 $sections[$target] = [
717 'selector' => $form_class . ' #wppb-form-element-' . $form_field['id'] . ' .wppb-description-delimiter',
718 'section_name' => 'Description',
719 ];
720 break;
721 case 'heading':
722 $sections[$target] = [
723 'selector' => $form_class . ' #wppb-form-element-' . $form_field['id'] . ' h4',
724 'section_name' => 'Heading',
725 ];
726 break;
727 case 'html':
728 $sections[$target] = [
729 'selector' => $form_class . ' #wppb-form-element-' . $form_field['id'] . ' .custom_field_html',
730 'section_name' => 'HTML',
731 ];
732 break;
733 case 'select_user_role':
734 $sections[$target] = [
735 'selector' => $form_class . ' #wppb-form-element-' . $form_field['id'] . ' .custom_field_user_role',
736 'section_name' => 'Select User Role',
737 ];
738 break;
739 case 'select_user_role_notice':
740 $sections[$target] = [
741 'selector' => $form_class . ' #wppb-form-element-' . $form_field['id'] . ' p',
742 'section_name' => 'Select User Role Notice',
743 ];
744 break;
745 case 'select2':
746 $sections[$target] = [
747 'selector' => $form_class . ' #wppb-form-element-' . $form_field['id'] . ' .select2.select2-container',
748 'section_name' => 'Select2',
749 ];
750 break;
751 case 'select_cpt':
752 $sections[$target] = [
753 'selector' => $form_class . ' #wppb-form-element-' . $form_field['id'] . ' .select2.select2-container',
754 'section_name' => 'Select (CPT)',
755 ];
756 break;
757 case 'timepicker_hours':
758 $sections[$target] = [
759 'selector' => $form_class . ' #wppb-form-element-' . $form_field['id'] . ' .custom_field_timepicker_hours',
760 'section_name' => 'Timepicker Hours',
761 ];
762 break;
763 case 'timepicker_minutes':
764 $sections[$target] = [
765 'selector' => $form_class . ' #wppb-form-element-' . $form_field['id'] . ' .custom_field_timepicker_minutes',
766 'section_name' => 'Timepicker Minutes',
767 ];
768 break;
769 case 'timepicker_separator':
770 $sections[$target] = [
771 'selector' => $form_class . ' #wppb-form-element-' . $form_field['id'] . ' .wppb-timepicker-separator',
772 'section_name' => 'Timepicker Separator',
773 ];
774 break;
775 case 'checkbox':
776 $sections[$target] = [
777 'selector' => $form_class . ' #wppb-form-element-' . $form_field['id'] . ' .custom_field_checkbox',
778 'section_name' => 'Checkbox',
779 ];
780 break;
781 case 'checkbox_labels':
782 $sections[$target] = [
783 'selector' => $form_class . ' #wppb-form-element-' . $form_field['id'] . ' .wppb-rc-value',
784 'section_name' => 'Checkbox Labels',
785 ];
786 break;
787 case 'radio':
788 $sections[$target] = [
789 'selector' => $form_class . ' #wppb-form-element-' . $form_field['id'] . ' .custom_field_radio',
790 'section_name' => 'Radio',
791 ];
792 break;
793 case 'radio_labels':
794 $sections[$target] = [
795 'selector' => $form_class . ' #wppb-form-element-' . $form_field['id'] . ' .wppb-rc-value',
796 'section_name' => 'Radio Labels',
797 ];
798 break;
799 case 'upload':
800 $sections[$target] = [
801 'selector' => $form_class . ' #wppb-form-element-' . $form_field['id'] . ' .wppb_upload_button',
802 'section_name' => 'Upload Button',
803 ];
804 break;
805 case 'avatar':
806 $sections[$target] = [
807 'selector' => $form_class . ' #wppb-form-element-' . $form_field['id'] . ' .wppb_upload_button',
808 'section_name' => 'Avatar Button',
809 ];
810 break;
811 case 'gdpr_delete_button':
812 $sections[$target] = [
813 'selector' => $form_class . ' #wppb-form-element-' . $form_field['id'] . ' .wppb-delete-account',
814 'section_name' => 'GDPR Delete Button',
815 ];
816 break;
817 case 'default_field_display':
818 $sections[$target] = [
819 'selector' => $form_class . ' #wppb-form-element-' . $form_field['id'] . ' .' . $field_meta,
820 'section_name' => 'Select Name',
821 ];
822 break;
823 case 'wysiwyg':
824 $sections[$target] = [
825 'selector' => $form_class . ' #wppb-form-element-' . $form_field['id'] . ' div#wp-' . $field_meta . '-wrap',
826 'section_name' => 'Input',
827 ];
828 break;
829 case 'woo_billing_label' :
830 case 'woo_shipping_label' :
831 $sections[$target] = [
832 'selector' => $this->add_ids_to_selector( $form_class . ' #wppb-form-element-' . $form_field['id'] . ' label[for=', $ids, ']' ),
833 'section_name' => 'Labels',
834 ];
835 break;
836 case 'woo_billing_select' :
837 case 'woo_shipping_select' :
838 $sections[$target] = [
839 'selector' => $this->add_ids_to_selector( $form_class . ' #wppb-form-element-' . $form_field['id'] . ' select#', $ids ),
840 'section_name' => 'Select',
841 ];
842 break;
843 case 'woo_billing_input' :
844 case 'woo_shipping_input' :
845 $sections[$target] = [
846 'selector' => $this->add_ids_to_selector( $form_class . ' #wppb-form-element-' . $form_field['id'] . ' input#', $ids ),
847 'section_name' => 'Inputs',
848 ];
849 break;
850 case 'woo_billing_checkbox' :
851 $sections[$target] = [
852 'selector' => $this->add_ids_to_selector( $form_class . ' #wppb-form-element-' . $form_field['id'] . ' .wppb-shipping-different-address input#', $ids ),
853 'section_name' => 'Checkbox',
854 ];
855 break;
856 case 'woo_billing_checkbox_label' :
857 $sections[$target] = [
858 'selector' => $this->add_ids_to_selector( $form_class . ' #wppb-form-element-' . $form_field['id'] . ' .wppb-shipping-different-address label[for=', $ids, ']' ),
859 'section_name' => 'Checkbox Label',
860 ];
861 break;
862 default:
863 return;
864 }
865 }
866
867 $this->add_styling_control_group(
868 $form_field['field-title'],
869 $form_field['control_group_conditions'],
870 $section_id_prefix . '_' . $field_meta . '_' . $form_field['id'],
871 $sections
872 );
873 }
874 }
875 }
876
877 /**
878 * Add a selector for each id.
879 * @param $ids
880 * @param $prefix
881 * @param string $suffix
882 * @return array
883 */
884 protected function add_ids_to_selector( $prefix, $ids, $suffix = '' ){
885 if ( is_array($ids) ) {
886 $selectors = [];
887 foreach ($ids as $key => $id) {
888 $selectors[] = $prefix . $id . $suffix;
889 }
890 return $selectors;
891 }
892 return $prefix . $ids . $suffix;
893 }
894
895 /**
896 * Replace label with heading.
897 * @param $targets
898 * @return array
899 */
900 protected function replace_label_with_heading( $targets ){
901 if (array_key_exists('label', $targets)) {
902 $targets['heading'] = $targets['label'];
903 unset($targets['label']);
904 }
905 return $targets;
906 }
907
908 /**
909 * Remove control group targeting the field label if Placeholder Labels is active.
910 * @param $targets
911 * @return array
912 */
913 protected function handle_placeholder_labels_active( $targets ){
914 if( $this->is_placeholder_labels_active() && array_key_exists('label', $targets)) {
915 unset($targets['label']);
916 }
917 return $targets;
918 }
919
920 /**
921 * Render the two widget types.
922 * @param $form_type
923 * @return mixed|Profile_Builder_Form_Creator|string|void
924 */
925 protected function render_widget($form_type ) {
926
927 $output = parent::render_widget( $form_type );
928 echo $output; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
929
930 // check if the form is being displayed in the Elementor editor
931 $is_elementor_edit_mode = false;
932 if( class_exists ( '\Elementor\Plugin' ) ){
933 $is_elementor_edit_mode = \Elementor\Plugin::$instance->editor->is_edit_mode();
934 $message= "";
935 }
936
937 if ( $is_elementor_edit_mode && ( isset( $output->args ) && $output->args !== null ) ) {
938
939 if( defined( 'WPPB_PAID_PLUGIN_URL' ) && isset( $output->args['form_fields'] ) ){
940 //add the scripts for various fields
941 foreach ( $output->args['form_fields'] as $form_field ){
942 switch ( $form_field['field'] ){
943 case 'Select2':
944 echo '<script src="'.esc_url( WPPB_PAID_PLUGIN_URL ).'front-end/extra-fields/select2/select2.js?ver='.esc_attr( PROFILE_BUILDER_VERSION ).'" id="wppb_sl2_js"></script>';
945 break;
946 case 'WYSIWYG':
947 echo '<script>jQuery(document.body).off( "click.add-media-button", ".insert-media" );</script>';
948 break;
949 case 'Select (CPT)':
950 echo '<script src="'.esc_url( WPPB_PAID_PLUGIN_URL ).'front-end/extra-fields/select-cpt/select-cpt.js?ver='.esc_attr( PROFILE_BUILDER_VERSION ).'" id="wppb-select-cpt-script"></script>';
951 break;
952 case 'Phone':
953 echo '<script src="'.esc_url( WPPB_PAID_PLUGIN_URL ).'front-end/extra-fields/phone/jquery.inputmask.bundle.min.js?ver='.esc_attr( PROFILE_BUILDER_VERSION ).'" id="wppb-jquery-inputmask"></script>';
954 echo '<script src="'.esc_url( WPPB_PAID_PLUGIN_URL ).'front-end/extra-fields/phone/script-phone.js?ver='.esc_attr( PROFILE_BUILDER_VERSION ).'" id="wppb-phone-script"></script>';
955 break;
956 default:
957 break;
958 }
959 }
960 }
961
962 //Multi-Step Forms compatibility
963 if ( wppb_check_if_add_on_is_active( 'multi-step-forms' ) ) {
964
965 $ajaxUrl = admin_url( 'admin-ajax.php' );
966 $ajaxNonce = wp_create_nonce( 'wppb_msf_frontend_nonce' );
967 echo '
968 <script id="wppb-msf-script-frontend-extra">
969 var wppb_msf_data_frontend = {"ajaxUrl":"'.esc_url( $ajaxUrl ).'","ajaxNonce":"'.esc_attr( $ajaxNonce ).'"};
970 </script>
971 ';
972 echo '
973 <script src="'.esc_url( WPPB_PAID_PLUGIN_URL ).'add-ons-advanced/multi-step-forms/assets/js/frontend-multi-step-forms.js?ver='.esc_attr( PROFILE_BUILDER_VERSION ).'" id="wppb-msf-script-frontend">
974 </script>
975 ';
976
977 }
978 }
979 }
980 }