PluginProbe
User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor / 3.9.8
User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor v3.9.8
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 / admin / advanced-settings / includes / forms / placeholder-labels.php

placeholder-labels.php in User Profile Builder – Beautiful User Registration Forms, User Profiles & User Role Editor 3.9.8, at admin/advanced-settings/includes/forms/placeholder-labels.php

311 lines 9.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 * Function that enqueues the necessary scripts in the front-end area
4 *
5 * @since v.1.0
6 *
7 */
8 function wppb_pbpl_scripts_and_styles() {
9 wp_enqueue_script( 'wppb_pbpl_init', WPPB_PLUGIN_URL . 'assets/js/placeholder-labels.js', array( 'jquery' ) );
10 wp_enqueue_style( 'wppb_pbpl_css', WPPB_PLUGIN_URL . 'assets/css/placeholder-labels.css' );
11
12 if( is_rtl() ) {
13 wp_enqueue_style( 'wppb_pbpl_css_rtl', plugin_dir_url( __FILE__ ) . 'assets/css/placeholder-labels-rtl.css' );
14 }
15 }
16 add_action( 'wp_enqueue_scripts', 'wppb_pbpl_scripts_and_styles' );
17
18
19 /*
20 * Function that adds a new class to each form field
21 *
22 * @since v.1.0
23 *
24 * @param string $field Contain the class of each form field
25 *
26 * @return string
27 */
28 function wppb_pbpl_field_css_class( $field ) {
29 $field = esc_attr( $field );
30
31 if( strpos( $field, 'wppb-subscription-plans' ) == false ) {
32 $field = $field . ' pbpl-class';
33 }
34
35 return $field;
36 }
37
38
39 /*
40 * Function that adds a new placeholder attribute to each form field
41 *
42 * @since v.1.0
43 *
44 * @param array $field Contain each form field
45 *
46 * @return string
47 */
48 function wppb_pbpl_extra_attribute( $extra_attribute, $field, $form_location ) {
49 $extra_attr_only_for = array(
50 'Default - Username',
51 'Default - First Name',
52 'Default - Last Name',
53 'Default - Nickname',
54 'Default - E-mail',
55 'Default - Website',
56 'Default - Password',
57 'Default - Repeat Password',
58 'Default - Biographical Info',
59 'Input',
60 'Textarea',
61 'Email Confirmation',
62 'Phone',
63 'Colorpicker',
64 'Datepicker',
65 'Number',
66 'Validation',
67 'Email',
68 );
69
70 if( ! empty ( $field ) && in_array( $field['field'], $extra_attr_only_for ) ) {
71 $extra_attribute .= 'placeholder = "' . esc_attr( wppb_icl_t( 'plugin profile-builder-pro', 'custom_field_'.$field['id'].'_title_translation', $field['field-title'], true ) ) . ( ( $field['required'] == 'Yes' ) ? '*' : '' ) . '"';
72 }
73
74 return $extra_attribute;
75 }
76
77
78 /*
79 * Function that adds a new placeholder attribute to each WooCommerce Add-on form field
80 *
81 * @since v.1.1
82 *
83 * @param array $field Contain each form field
84 *
85 * @return string
86 */
87 function wppb_pbpl_woo_extra_attribute( $extra_attribute, $field ) {
88 $extra_attribute .= 'placeholder = "' . esc_attr( $field['label'] ) . ( ( $field['required'] == 'Yes' ) ? '*' : '' ) . '"';
89
90 return $extra_attribute;
91 }
92
93
94 /*
95 * Function that adds a Meta Box on each edit Register and Edit-Profile forms when Multiple Forms are active
96 *
97 * @since v.2.0
98 *
99 */
100 function wppb_pbpl_add_meta_boxes() {
101 $pbpl_pb_moduleSettings = get_option( 'wppb_module_settings', 'not_found' );
102
103 if( $pbpl_pb_moduleSettings != 'not_found' ) {
104
105 if( $pbpl_pb_moduleSettings['wppb_multipleRegistrationForms'] == 'show' ) {
106 add_meta_box( 'pbpl-rf-side', __( 'Placeholder Labels', 'profile-builder' ), 'wppb_pbpl_meta_box_content', 'wppb-rf-cpt', 'side', 'low' );
107 }
108
109 if( $pbpl_pb_moduleSettings['wppb_multipleEditProfileForms'] == 'show' ) {
110 add_meta_box( 'pbpl-epf-side', __( 'Placeholder Labels', 'profile-builder' ), 'wppb_pbpl_meta_box_content', 'wppb-epf-cpt', 'side', 'low' );
111 }
112
113 }
114 }
115 add_action( 'add_meta_boxes', 'wppb_pbpl_add_meta_boxes' );
116
117
118 /*
119 * Function that adds content to Meta Boxes on each edit Register and Edit-Profile forms
120 *
121 * @since v.2.0
122 *
123 * @param object $post Contain the post data
124 */
125 function wppb_pbpl_meta_box_content( $post ) {
126 $pbpl_select_value = get_post_meta( $post->ID, 'pbpl-active', true );
127 $pbpl_select_value = esc_attr( $pbpl_select_value );
128
129 ?>
130 <div class="wrap">
131 <p>
132 <label for="pbpl-active" ><?php esc_html_e( 'Replace labels with placeholders:', 'profile-builder' ) ?></label>
133 </p>
134 <select name="pbpl-active" id="pbpl-active" class="mb-select">
135 <option value="yes" <?php selected( $pbpl_select_value, 'yes' ); ?>><?php esc_html_e( 'Yes', 'profile-builder' ) ?></option>
136 <option value="no" <?php selected( $pbpl_select_value, 'no' ); ?>><?php esc_html_e( 'No', 'profile-builder' ) ?></option>
137 </select>
138 </div>
139 <?php
140 }
141
142
143 /*
144 * Function that saves the Meta Box option
145 *
146 * @since v.2.0
147 *
148 */
149 function wppb_pbpl_save_meta_box_option() {
150 global $post;
151
152 if( isset( $_POST['pbpl-active'] ) ) {
153 $pbpl_select_value = sanitize_text_field( $_POST['pbpl-active'] );
154
155 update_post_meta( $post->ID, 'pbpl-active', $pbpl_select_value );
156 }
157 }
158 add_action( 'save_post', 'wppb_pbpl_save_meta_box_option' );
159
160
161 /*
162 * Function that activate or deactivate replacement of labels with placeholders in form
163 *
164 * @since v.2.0
165 *
166 * @param array $form Contain the form args
167 */
168 function wppb_pbpl_activate( $form ) {
169 $pbpl_pb_moduleSettings = get_option( 'wppb_module_settings', 'not_found' );
170
171 if( ( $pbpl_pb_moduleSettings != 'not_found' && isset( $pbpl_pb_moduleSettings['wppb_multipleRegistrationForms'] ) && $pbpl_pb_moduleSettings['wppb_multipleRegistrationForms'] == 'show' ) || ( $pbpl_pb_moduleSettings != 'not_found' && isset( $pbpl_pb_moduleSettings['wppb_multipleEditProfileForms'] ) && $pbpl_pb_moduleSettings['wppb_multipleEditProfileForms'] == 'show' ) ) {
172 if( ! empty( $form['ID'] ) ) {
173 $pbpl_saved_value = get_post_meta( $form['ID'], 'pbpl-active', true );
174
175 if( $pbpl_saved_value == 'no' ) {
176 return;
177 } else {
178 wppb_pbpl_add_filters();
179 }
180 } else {
181 wppb_pbpl_add_filters();
182 }
183 } else {
184 wppb_pbpl_add_filters();
185 }
186 }
187 add_action( 'wppb_form_args_before_output', 'wppb_pbpl_activate' );
188
189
190 /*
191 * Function that adds the necessary filters
192 *
193 * @since v.2.0
194 *
195 */
196 function wppb_pbpl_add_filters() {
197 add_filter( 'wppb_field_css_class', 'wppb_pbpl_field_css_class', 10, 1 );
198 add_filter( 'wppb_extra_attribute', 'wppb_pbpl_extra_attribute', 10, 3 );
199 add_filter( 'wppb_woo_extra_attribute', 'wppb_pbpl_woo_extra_attribute', 10, 2 );
200 add_filter( 'wppb_extra_select_option', 'wppb_pbpl_extra_select_option', 10, 3 );
201 add_filter( 'wppb_select2_multiple_arguments', 'wppb_pbpl_select2_multiple_placeholder', 10, 3 );
202 }
203
204 /*
205 * Function that adds the necessary filters
206 *
207 * @since v.2.3.4
208 *
209 */
210 function wppb_pbpl_extra_select_option( $option, $field, $item_title ) {
211 $option = '<option value="" class="custom_field_select_option '. apply_filters( 'wppb_fields_extra_css_class', '', $field ) .'" disabled '. ( $field['field'] == 'Select (User Role)' ? '' : ( $field['field'] == 'Select2 (Multiple)' ? '' : 'selected' ) ) .'>'. esc_attr( $item_title ) . ( $field['required'] == 'Yes' ? '*' : '' ) .'</option>';
212
213 return $option;
214 }
215
216 /*
217 * Function that adds placeholder for Select2 Multiple field
218 *
219 * @since v.2.3.4
220 *
221 */
222 function wppb_pbpl_select2_multiple_placeholder( $arguments, $form_location, $field ) {
223 $arguments['placeholder'] = esc_attr( wppb_icl_t( 'plugin profile-builder-pro', 'custom_field_'.$field['id'].'_title_translation', $field['field-title'], true ) ) . ( $field['required'] == 'Yes' ? '*' : '' );
224
225 return $arguments;
226 }
227
228 /*
229 * Function that adds placeholder for Recover Password form fields
230 *
231 * @since v.2.3.4
232 *
233 */
234 function wppb_pbpl_recover_password( $extra_attr, $input_title, $input_type ) {
235 $extra_attr .= ' placeholder="'. esc_attr( $input_title ) . '" ';
236
237 return $extra_attr;
238 }
239 add_filter( 'wppb_recover_password_extra_attr', 'wppb_pbpl_recover_password', 10, 3 );
240
241
242 /**
243 * Add necessary class to PMS Billing Fields and replace empty Option for Select Fields (placeholder)
244 *
245 */
246 function wppb_pms_add_classes ( $fields ) {
247 $forms_settings = get_option( 'wppb_toolbox_forms_settings' );
248
249 if ( $forms_settings['placeholder-labels'] == 'yes' ) {
250 foreach ( $fields as $field ) {
251 if ( isset( $field['name'] ) && isset( $field['wrapper_class'] ) )
252 $fields[$field['name']]['wrapper_class'] .= ' pbpl-class';
253
254 if ( isset($field['options']) ) {
255 $fields[$field['name']]['options'][''] = __( 'Select an option', 'profile-builder' );
256 }
257 }
258 }
259
260 return $fields;
261 }
262 add_filter('pms_inv_get_invoice_fields', 'wppb_pms_add_classes' );
263 add_filter('pms_get_tax_extra_fields', 'wppb_pms_add_classes' );
264
265
266 /**
267 * Add Placeholders to PMS Billing Fields
268 *
269 */
270 function wppb_pbpl_add_pms_fields_placeholder( $form_fields ) {
271 $forms_settings = get_option( 'wppb_toolbox_forms_settings' );
272
273 if ( $forms_settings['placeholder-labels'] != 'yes' || !function_exists( 'pms_in_inv_get_invoice_fields' ) )
274 return $form_fields;
275
276 $pms_billing_fields = pms_in_inv_get_invoice_fields();
277
278 foreach ($pms_billing_fields as $key => $data) {
279 $required = ( isset( $data['required'] ) && $data['required'] == 1 ) ? ' *' : '';
280
281 if ( ($data['type'] == 'text' || $data['type'] == 'select_state' ) && strpos( $form_fields,'name="'. $key .'"' ) )
282 $form_fields = str_replace('name="'. $key .'"', 'name="'. $key .'"" placeholder="'. $data['label'] . $required .'"', $form_fields);
283 }
284
285 return $form_fields;
286 }
287 add_filter('wppb_output_fields_filter', 'wppb_pbpl_add_pms_fields_placeholder' );
288
289
290 /**
291 * Add Placeholder to Resend Activation Email Form
292 *
293 */
294 function wppb_pbpl_resend_activation( $extra_attr, $input_title, $input_type ) {
295 $extra_attr .= ' placeholder="'. esc_attr( $input_title ) . '" ';
296
297 return $extra_attr;
298 }
299 add_filter( 'wppb_resend_activation_extra_attr', 'wppb_pbpl_resend_activation', 10, 3 );
300
301 function wppb_pbpl_add_resend_activation_classes( $classes, $field ) {
302 $forms_settings = get_option( 'wppb_toolbox_forms_settings' );
303
304 if ( $forms_settings['placeholder-labels'] == 'yes' )
305 $classes .= ' pbpl-class';
306
307 return $classes;
308 }
309 add_filter( 'wppb_resend_activation_extra_css_class', 'wppb_pbpl_add_resend_activation_classes', 20, 2);
310
311