PluginProbe
User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor / 3.16.3
User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor v3.16.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 / lib / wck-api / fields / checkbox.php

checkbox.php in User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor 3.16.3, at assets/lib/wck-api/fields/checkbox.php

91 lines 3.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /* @param string $meta Meta name.
3 * @param array $details Contains the details for the field.
4 * @param string $value Contains input value;
5 * @param string $context Context where the function is used. Depending on it some actions are preformed.;
6 * @return string $element input element html string. */
7
8 if( !empty( $details['options'] ) ){
9
10 $options_number = count( $details['options'] );
11
12 if ( $options_number > 1 ) {
13 $checkboxes_wrapper_open = '<div class="wck-checkboxes cozmoslabs-checkbox-list '. (( $details['slug'] === 'buttons-order' ) ? ' cozmoslabs-checkbox-1-col-list' : ' cozmoslabs-checkbox-2-col-list') .'">';
14 $checkboxes_wrapper_close = '</div>';
15 $toggle_container_extra_class = 'cozmoslabs-chckbox-container';
16 }
17 else {
18 $checkboxes_wrapper_open = '';
19 $checkboxes_wrapper_close = '';
20 $toggle_container_extra_class = 'cozmoslabs-toggle-container';
21 }
22
23 $element .= $checkboxes_wrapper_open;
24 foreach( $details['options'] as $option ){
25 $found = false;
26
27 if( !is_array( $value ) )
28 $values = !empty( $value ) ? explode( ', ', $value ) : array();
29 else
30 $values = $value;
31
32 if( strpos( $option, '%' ) === false ){
33 $label = $option;
34 $value_attr = $option;
35 if ( in_array( $option, $values ) )
36 $found = true;
37 }
38 else{
39 $option_parts = explode( '%', $option );
40 if( !empty( $option_parts ) ){
41 if( empty( $option_parts[0] ) && count( $option_parts ) == 3 ){
42 $label = $option_parts[1];
43 $value_attr = $option_parts[2];
44 if ( in_array( $option_parts[2], $values ) )
45 $found = true;
46 }
47 }
48 }
49
50 $element .= '<div class="'. $toggle_container_extra_class .'"><input type="checkbox" name="'. $single_prefix . esc_attr( Wordpress_Creation_Kit_PB::wck_generate_slug( $details['title'], $details ) );
51 if( $this->args['single'] && $this->args['context'] != 'option' ) {
52 $element .= '[]';
53 }
54 $element .= '" id="';
55
56 if( !empty( $frontend_prefix ) )
57 $element .= $frontend_prefix;
58
59 /* since the slug below is generated from the value as well we need to determine here if we have a slug or not and not let the wck_generate_slug() function do that */
60 if( !empty( $details['slug'] ) )
61 $slug_from = $details['slug'];
62 else
63 $slug_from = $details['title'];
64
65 $context_slug = !empty($context) ? $context . '_' : '';
66
67 $element .= esc_attr( Wordpress_Creation_Kit_PB::wck_generate_slug( $context_slug . $slug_from . '_' . $value_attr ) ) .'" value="'. esc_attr( $value_attr ) .'" '. checked( $found, true, false ) .'class="mb-checkbox mb-field" />';
68
69 if ( $options_number > 1 )
70 $element .= '<label for="'. esc_attr( Wordpress_Creation_Kit_PB::wck_generate_slug( $context_slug . $slug_from . '_' . $value_attr ) ) .'">'. esc_html( $label ) .'</label>';
71 else
72 $element .= '<label class="cozmoslabs-toggle-track" for="'. esc_attr( Wordpress_Creation_Kit_PB::wck_generate_slug( $context_slug . $slug_from . '_' . $value_attr ) ) .'"></label>';
73
74 $element .= '</div>';
75
76 if ( $options_number == 1 ){
77 $include_title_in_toggle = '<strong>'. $details['title'] .'</strong>';
78
79 if( isset( $details['include_title_in_toggle'] ) && $details['include_title_in_toggle'] == false )
80 $include_title_in_toggle = '';
81
82 $element .= '<div class="cozmoslabs-toggle-description">
83 <label for="'. esc_attr( Wordpress_Creation_Kit_PB::wck_generate_slug( $context_slug . $slug_from . '_' . $value_attr ) ) .'" class="cozmoslabs-description">'. esc_html__( 'Enable ', 'profile-builder' ) . $include_title_in_toggle .'</label>
84 </div>';
85 }
86
87 }
88
89 $element .= $checkboxes_wrapper_close;
90 }
91 ?>