PluginProbe
User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor / 3.9.9
User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor v3.9.9
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 3.9.9, at assets/misc/elementor/widgets/class-pb-widget-rf-epf.php

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