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 / front-end / default-fields / checkbox / checkbox.php

checkbox.php in User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor 3.9.9, at front-end/default-fields/checkbox/checkbox.php

126 lines 7.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /* handle field output */
3 function wppb_checkbox_handler( $output, $form_location, $field, $user_id, $field_check_errors, $request_data ){
4 if ( $field['field'] == 'Checkbox' ){
5 $item_title = apply_filters( 'wppb_'.$form_location.'_checkbox_custom_field_'.$field['id'].'_item_title', wppb_icl_t( 'plugin profile-builder-pro', 'custom_field_'.$field['id'].'_title_translation', $field['field-title'], true ) );
6 $item_description = wppb_icl_t( 'plugin profile-builder-pro', 'custom_field_'.$field['id'].'_description_translation', $field['description'], true );
7 $item_option_labels = wppb_icl_t( 'plugin profile-builder-pro', 'custom_field_'.$field['id'].'_labels_translation', $field['labels'], true );
8
9 $checkbox_labels = apply_filters( 'wppb_checkbox_labels_array', explode( ',', $item_option_labels ), $field, $form_location, $user_id, $request_data );
10 $checkbox_values = apply_filters( 'wppb_checkbox_options_array', explode( ',', $field['options'] ), $field, $form_location, $user_id, $request_data );
11
12 if( $form_location != 'register' )
13 $input_value = ( ( wppb_user_meta_exists ( $user_id, $field['meta-name'] ) != null ) ? array_map( 'trim', explode( ',', stripslashes(get_user_meta( $user_id, $field['meta-name'], true )) ) ) : array_map( 'trim', explode( ',', $field['default-options'] ) ) );
14 else
15 $input_value = ( !empty( $field['default-options'] ) ? array_map( 'trim', explode( ',', $field['default-options'] ) ) : array() );
16
17 if( isset( $request_data[ wppb_handle_meta_name( $field['meta-name'] ) ] ) && !empty( $request_data[ wppb_handle_meta_name( $field['meta-name'] ) ] ) )
18 $input_value = $request_data[ wppb_handle_meta_name( $field['meta-name'] ) ];
19
20 $extra_attr = apply_filters( 'wppb_extra_attribute', '', $field, $form_location );
21
22 if ( $form_location != 'back_end' ){
23 $error_mark = ( ( $field['required'] == 'Yes' ) ? '<span class="wppb-required" title="'.wppb_required_field_error($field["field-title"]).'">*</span>' : '' );
24
25 if ( array_key_exists( $field['id'], $field_check_errors ) )
26 $error_mark = '<img src="'.WPPB_PLUGIN_URL.'assets/images/pencil_delete.png" title="'.wppb_required_field_error($field["field-title"]).'"/>';
27
28 $output = '
29 <label for="'.$field['meta-name'].'">'.$item_title.$error_mark.'</label>';
30 $output .= '<ul class="wppb-checkboxes">';
31 $output .= '<li class="wppb-hidden"><input type="hidden" value="" name="' . $field['meta-name'] . '"></li>';
32 foreach( $checkbox_values as $key => $value ) {
33 if ( $value !== "" ) {
34 $output .= '<li><input value="' . esc_attr(trim($value)) . '" class="custom_field_checkbox" name="' . $field['meta-name'] . '[]" id="' . Wordpress_Creation_Kit_PB::wck_generate_slug(trim($value)) . '_' . $field['id'] . '" type="checkbox" ' . $extra_attr . ' ';
35
36 if (in_array(trim($value), $input_value))
37 $output .= ' checked';
38
39 $output .= ' /><label for="' . Wordpress_Creation_Kit_PB::wck_generate_slug(trim($value)) . '_' . $field['id'] . '" class="wppb-rc-value">' . ((!isset($checkbox_labels[$key]) || !$checkbox_labels[$key]) ? trim($checkbox_values[$key]) : trim($checkbox_labels[$key])) . '</label></li>';
40 }
41 }
42 $output .= '</ul>';
43 if( !empty( $item_description ) )
44 $output .= '<span class="wppb-description-delimiter">'.$item_description.'</span>';
45
46 }else{
47 $item_title = ( ( $field['required'] == 'Yes' ) ? $item_title .' <span class="description">('. __( 'required', 'profile-builder' ) .')</span>' : $item_title );
48 $output = '
49 <table class="form-table">
50 <tr>
51 <th><label for="'.$field['meta-name'].'">'.$item_title.'</label></th>
52 <td>';
53 $output .= '<ul class="wppb-checkboxes">';
54 $output .= '<li class="wppb-hidden"><input type="hidden" value="" name="' . $field['meta-name'] . '"></li>';
55 foreach( $checkbox_values as $key => $value ) {
56 if ( $value !== "" ) {
57 $output .= '<li><input value="' . esc_attr(trim($value)) . '" class="custom_field_checkbox ' . apply_filters('wppb_fields_extra_css_class', '', $field) . '" name="' . $field['meta-name'] . '[]" id="' . Wordpress_Creation_Kit_PB::wck_generate_slug(trim($value)) . '_' . $field['id'] . '" type="checkbox"';
58
59 if (in_array(trim($value), $input_value))
60 $output .= ' checked';
61
62 $output .= ' /><label for="' . Wordpress_Creation_Kit_PB::wck_generate_slug(trim($value)) . '_' . $field['id'] . '" class="wppb-rc-value">' . ((!isset($checkbox_labels[$key]) || !$checkbox_labels[$key]) ? trim($checkbox_values[$key]) : trim($checkbox_labels[$key])) . '</label></li>';
63 }
64 }
65 $output .= '</ul>
66 <span class="wppb-description-delimiter">'.$item_description.'</span>
67 </td>
68 </tr>
69 </table>';
70 }
71
72 return apply_filters( 'wppb_'.$form_location.'_checkbox_custom_field_'.$field['id'], $output, $form_location, $field, $user_id, $field_check_errors, $request_data, $input_value );
73 }
74 }
75 add_filter( 'wppb_output_form_field_checkbox', 'wppb_checkbox_handler', 10, 6 );
76 add_filter( 'wppb_admin_output_form_field_checkbox', 'wppb_checkbox_handler', 10, 6 );
77
78
79 /* handle field save */
80 function wppb_save_checkbox_value( $field, $user_id, $request_data, $form_location ){
81 if( $field['field'] == 'Checkbox' ){
82 if( isset( $request_data[ wppb_handle_meta_name( $field['meta-name'] ) ] ) ) {
83 $checkbox_values = wppb_process_checkbox_value($field, $request_data);
84 update_user_meta($user_id, $field['meta-name'], $checkbox_values);
85 }
86 }
87 }
88 add_action( 'wppb_save_form_field', 'wppb_save_checkbox_value', 10, 4 );
89 add_action( 'wppb_backend_save_form_field', 'wppb_save_checkbox_value', 10, 4 );
90
91
92 function wppb_process_checkbox_value( $field, $request_data ){
93 $checkbox_values = '';
94
95 if( isset( $request_data[ wppb_handle_meta_name( $field['meta-name'] ) ] ) && is_array( $request_data[ wppb_handle_meta_name( $field['meta-name'] ) ] ) )
96 $checkbox_values = implode( ',', $request_data[ wppb_handle_meta_name( $field['meta-name'] ) ] );
97
98 return trim( $checkbox_values, ',' );
99 }
100
101
102 function wppb_add_checkbox_for_user_signup( $field_value, $field, $request_data ){
103 return wppb_process_checkbox_value( $field, $request_data );
104 }
105 add_filter( 'wppb_add_to_user_signup_form_field_checkbox', 'wppb_add_checkbox_for_user_signup', 10, 3 );
106
107
108 /* handle field validation */
109 function wppb_check_checkbox_value( $message, $field, $request_data, $form_location ){
110
111 if( $field['field'] == 'Checkbox' ){
112 $checked_values = '';
113
114 if( isset( $request_data[ wppb_handle_meta_name( $field['meta-name'] ) ] ) && is_array( $request_data[ wppb_handle_meta_name( $field['meta-name'] ) ] ) )
115 $checked_values = implode( ',', $request_data[ wppb_handle_meta_name( $field['meta-name'] ) ] );
116
117 if ( ( $field['required'] == 'Yes' ) && empty( $checked_values ) ){
118 return wppb_required_field_error($field["field-title"]);
119 }
120
121 }
122
123 return $message;
124 }
125 add_filter( 'wppb_check_form_field_checkbox', 'wppb_check_checkbox_value', 10, 4 );
126