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

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