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

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

101 lines 5.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 // Exit if accessed directly
3 if ( ! defined( 'ABSPATH' ) ) exit;
4
5 /* handle field output */
6 function wppb_radio_handler( $output, $form_location, $field, $user_id, $field_check_errors, $request_data ){
7 if ( $field['field'] == 'Radio' ){
8 $item_title = apply_filters( 'wppb_'.$form_location.'_radio_custom_field_'.$field['id'].'_item_title', wppb_icl_t( 'plugin profile-builder-pro', 'custom_field_'.$field['id'].'_title_translation', $field['field-title'], true ) );
9 $item_description = wppb_icl_t( 'plugin profile-builder-pro', 'custom_field_'.$field['id'].'_description_translation', $field['description'], true );
10 $item_option_labels = wppb_icl_t( 'plugin profile-builder-pro', 'custom_field_'.$field['id'].'_labels_translation', $field['labels'], true );
11
12 $radio_labels = apply_filters( 'wppb_radio_labels_array', explode( ',', $item_option_labels ), $field, $form_location, $user_id, $request_data );
13 $radio_values = apply_filters( 'wppb_radio_options_array', explode( ',', $field['options'] ), $field, $form_location, $user_id, $request_data );
14
15 if( $form_location != 'register' )
16 $input_value = ( ( wppb_user_meta_exists ( $user_id, $field['meta-name'] ) != null ) ? stripslashes(get_user_meta( $user_id, $field['meta-name'], true )) : $field['default-option'] );
17 else
18 $input_value = ( isset( $field['default-option'] ) ? trim( $field['default-option'] ) : '' );
19
20 $input_value = ( isset( $request_data[wppb_handle_meta_name( $field['meta-name'] )] ) ? trim( stripslashes( $request_data[wppb_handle_meta_name( $field['meta-name'] )] )) : $input_value );
21 $input_value = apply_filters( 'wppb_form_radio_field_value', $input_value, $field, $form_location );
22
23 $extra_attr = apply_filters( 'wppb_extra_attribute', '', $field, $form_location );
24
25 if ( $form_location != 'back_end' ){
26 $error_mark = ( ( $field['required'] == 'Yes' ) ? '<span class="wppb-required" title="'.wppb_required_field_error($field["field-title"]).'">*</span>' : '' );
27
28 if ( array_key_exists( $field['id'], $field_check_errors ) )
29 $error_mark = '<img src="'.WPPB_PLUGIN_URL.'assets/images/pencil_delete.png" title="'.wppb_required_field_error($field["field-title"]).'"/>';
30
31 $question_id = 'wppb-question-' . $field['id'];
32
33 $output = '
34 <label id="'. esc_attr( $question_id ) .'">'.$item_title.$error_mark.'</label>';
35 $output .= '<ul class="wppb-radios">';
36 foreach( $radio_values as $key => $value){
37 $output .= '<li><input value="'.esc_attr( trim( $value ) ).'" class="custom_field_radio '. apply_filters( 'wppb_fields_extra_css_class', '', $field ) .'" id="'.Wordpress_Creation_Kit_PB::wck_generate_slug( trim( $value ) ).'_'.$field['id'].'" name="'.$field['meta-name'].'" type="radio" aria-describedby="'. esc_attr( $question_id ) .'" '. $extra_attr .' ';
38
39 if ( $input_value === trim( $value ) )
40 $output .= ' checked';
41
42 $output .= ' /><label for="'.Wordpress_Creation_Kit_PB::wck_generate_slug( trim( $value ) ).'_'.$field['id'].'" class="wppb-rc-value">'.( ( !isset( $radio_labels[$key] ) || !$radio_labels[$key] ) ? trim( $radio_values[$key] ) : trim( $radio_labels[$key] ) ).'</label></li>';
43 }
44 $output .= '</ul>';
45
46 if( !empty( $item_description ) )
47 $output .= '<span class="wppb-description-delimiter">'.$item_description.'</span>';
48
49 }else{
50 $item_title = ( ( $field['required'] == 'Yes' ) ? $item_title .' <span class="description">('. __( 'required', 'profile-builder' ) .')</span>' : $item_title );
51 $output = '
52 <table class="form-table">
53 <tr>
54 <th><label for="'.$field['meta-name'].'">'.$item_title.'</label></th>
55 <td>';
56
57 foreach( $radio_values as $key => $value ){
58 $output .= '<li><input value="'.esc_attr( trim( $value ) ).'" id="'.Wordpress_Creation_Kit_PB::wck_generate_slug( trim( $value ) ).'_'.$field['id'].'" class="custom_field_radio" name="'.$field['meta-name'].'" type="radio" '. $extra_attr .' ';
59
60 if ( $input_value === trim( $value ) )
61 $output .= ' checked';
62
63 $output .= ' /><label for="'.Wordpress_Creation_Kit_PB::wck_generate_slug( trim( $value ) ).'_'.$field['id'].'" class="wppb-rc-value">'.( ( !isset( $radio_labels[$key] ) || !$radio_labels[$key] ) ? trim( $radio_values[$key] ) : trim( $radio_labels[$key] ) ).'</label></li>';
64 }
65
66 $output .= '
67 <span class="description">'.$item_description.'</span>
68 </td>
69 </tr>
70 </table>';
71 }
72
73 return apply_filters( 'wppb_'.$form_location.'_radio_custom_field_'.$field['id'], $output, $form_location, $field, $user_id, $field_check_errors, $request_data, $input_value );
74 }
75 }
76 add_filter( 'wppb_output_form_field_radio', 'wppb_radio_handler', 10, 6 );
77 add_filter( 'wppb_admin_output_form_field_radio', 'wppb_radio_handler', 10, 6 );
78
79
80 /* handle field save */
81 function wppb_save_radio_select_value( $field, $user_id, $request_data, $form_location ){
82 if( $field['field'] == 'Radio' ){
83 if ( isset( $request_data[wppb_handle_meta_name( $field['meta-name'] )] ) )
84 update_user_meta( $user_id, $field['meta-name'], sanitize_text_field( $request_data[wppb_handle_meta_name( $field['meta-name'] )] ) );
85 }
86 }
87 add_action( 'wppb_save_form_field', 'wppb_save_radio_select_value', 10, 4 );
88 add_action( 'wppb_backend_save_form_field', 'wppb_save_radio_select_value', 10, 4 );
89
90
91 /* handle field validation */
92 function wppb_check_radio_value( $message, $field, $request_data, $form_location ){
93 if( $field['field'] == 'Radio' ){
94 if ( !isset( $request_data[wppb_handle_meta_name( $field['meta-name'] )] ) && ( $field['required'] == 'Yes' ) ){
95 return wppb_required_field_error($field["field-title"]);
96 }
97 }
98
99 return $message;
100 }
101 add_filter( 'wppb_check_form_field_radio', 'wppb_check_radio_value', 10, 4 );