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 / lib / wck-api / fields / select-2.php

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

57 lines 2.4 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 $id = esc_attr( Wordpress_Creation_Kit_PB::wck_generate_slug( $details['title'], $details ) );
9 if( !empty( $frontend_prefix ) )
10 $id = $frontend_prefix.$id;
11
12 $element .= '<select name="'. $single_prefix . esc_attr( Wordpress_Creation_Kit_PB::wck_generate_slug( $details['title'], $details ) ) .'" id="'.$id.'"';
13 $element .= '" class="mb-select-2 mb-field" >';
14
15 if( !empty( $details['default-option'] ) && $details['default-option'] )
16 $element .= '<option value="">'. __('Select or type in an option', 'profile-builder') .'</option>';
17
18 $field_name = Wordpress_Creation_Kit_PB::wck_generate_slug( $details['title'], $details );
19
20 // we're passing this further to a function. Need to make sure it exists so we don't get a notice.
21 if( empty( $details['value'] ) ){
22 $details['value'] = false;
23 }
24
25 $options = '';
26 if( !empty( $details['options'] ) ){
27
28 $new_nonexisting_value = true;
29
30 $i = 0;
31 foreach( $details['options'] as $option ){
32 $optionOutput = Wordpress_Creation_Kit_PB::wck_generate_select_option($option, $details['value'], $i, $value);
33 $options .= apply_filters("wck_select_{$meta}_{$field_name}_option_{$i}", $optionOutput, $i);
34
35 $i++;
36
37 if( !empty( $value ) && ( $option === $value || strpos( $option, '%'.$value ) !== false ) )//it is not a custom value because it is present in the options
38 $new_nonexisting_value = false;
39 }
40
41 //display the custom value that was inserted with select 2 that was not present in options
42 if( $new_nonexisting_value )
43 $options .= '<option value="'. esc_attr( $value ) .'" '. selected( $value, $value, false ) .' >'. esc_html( $value ) .'</option>';
44 }
45
46 $element .= apply_filters( "wck_select_{$meta}_{$field_name}_options", $options );
47 $element .= '</select>';
48 $element .= '<script type="text/javascript">
49 if(typeof jQuery.fn.select2 === "undefined"){jQuery( function() {jQuery( ".mb-select-2").select2({ tags: true, placeholder: "Select or type in an option" });});}
50 else{jQuery( ".mb-select-2").select2({ tags: true, placeholder: "Select or type in an option" });}
51 </script>';
52
53
54
55
56
57