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

351 lines 11.5 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 /* Verify our metabox nonce before current_user_can — save_post runs for every
164 * post type and map_meta_cap warns if the CPT is unregistered. */
165 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' ) )
166 return;
167
168 if( ! current_user_can( 'edit_post', $post_id ) )
169 return;
170
171 if( isset( $_POST['pbpl-active'] ) && $_POST['pbpl-active'] == 'yes' )
172 update_post_meta( $post_id, 'pbpl-active', 'yes' );
173 else delete_post_meta( $post_id, 'pbpl-active' );
174
175 }
176 add_action( 'save_post', 'wppb_pbpl_save_meta_box_option' );
177
178
179 /*
180 * Function that activate or deactivate replacement of labels with placeholders in form
181 *
182 * @since v.2.0
183 *
184 * @param array $form Contain the form args
185 */
186 function wppb_pbpl_activate( $form ) {
187 $pbpl_pb_moduleSettings = get_option( 'wppb_module_settings', 'not_found' );
188
189 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' ) ) {
190 if( ! empty( $form['ID'] ) ) {
191 $pbpl_saved_value = get_post_meta( $form['ID'], 'pbpl-active', true );
192
193 if( $pbpl_saved_value != 'yes' ) {
194 return;
195 } else {
196 wppb_pbpl_add_filters();
197 }
198 } else {
199 wppb_pbpl_add_filters();
200 }
201 } else {
202 wppb_pbpl_add_filters();
203 }
204 }
205 add_action( 'wppb_form_args_before_output', 'wppb_pbpl_activate' );
206
207
208 /*
209 * Function that adds the necessary filters
210 *
211 * @since v.2.0
212 *
213 */
214 function wppb_pbpl_add_filters() {
215 add_filter( 'wppb_field_css_class', 'wppb_pbpl_field_css_class', 10, 1 );
216 add_filter( 'wppb_blog_details_field_css_class', 'wppb_pbpl_field_css_class', 10, 1 );
217 add_filter( 'wppb_extra_attribute', 'wppb_pbpl_extra_attribute', 10, 3 );
218 add_filter( 'wppb_woo_extra_attribute', 'wppb_pbpl_woo_extra_attribute', 10, 2 );
219 add_filter( 'wppb_extra_select_option', 'wppb_pbpl_extra_select_option', 10, 3 );
220 add_filter( 'wppb_select2_multiple_arguments', 'wppb_pbpl_select2_multiple_placeholder', 10, 3 );
221 }
222
223 /*
224 * Function that adds the necessary filters
225 *
226 * @since v.2.3.4
227 *
228 */
229 function wppb_pbpl_extra_select_option( $option, $field, $item_title ) {
230 $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>';
231
232 return $option;
233 }
234
235 /*
236 * Function that adds placeholder for Select2 Multiple field
237 *
238 * @since v.2.3.4
239 *
240 */
241 function wppb_pbpl_select2_multiple_placeholder( $arguments, $form_location, $field ) {
242 $arguments['placeholder'] = esc_attr( wppb_icl_t( 'plugin profile-builder-pro', 'custom_field_'.$field['id'].'_title_translation', $field['field-title'], true ) ) . ( $field['required'] == 'Yes' ? '*' : '' );
243
244 return $arguments;
245 }
246
247 /*
248 * Function that adds placeholder for Recover Password form fields
249 *
250 * @since v.2.3.4
251 *
252 */
253 function wppb_pbpl_recover_password( $extra_attr, $input_title, $input_type ) {
254 $extra_attr .= ' placeholder="'. esc_attr( $input_title ) . '" ';
255
256 return $extra_attr;
257 }
258 add_filter( 'wppb_recover_password_extra_attr', 'wppb_pbpl_recover_password', 10, 3 );
259
260
261 /**
262 * Add necessary class to PMS Billing Fields and replace empty Option for Select Fields (placeholder)
263 *
264 */
265 function wppb_pms_add_classes ( $fields ) {
266 $forms_settings = get_option( 'wppb_toolbox_forms_settings' );
267
268 if ( $forms_settings['placeholder-labels'] == 'yes' ) {
269 foreach ( $fields as $field ) {
270 if ( isset( $field['name'] ) && isset( $field['wrapper_class'] ) )
271 $fields[$field['name']]['wrapper_class'] .= ' pbpl-class';
272
273 if ( isset($field['options']) ) {
274 $fields[$field['name']]['options'][''] = __( 'Select an option', 'profile-builder' );
275 }
276 }
277 }
278
279 return $fields;
280 }
281 add_filter('pms_inv_get_invoice_fields', 'wppb_pms_add_classes' );
282 add_filter('pms_get_tax_extra_fields', 'wppb_pms_add_classes' );
283
284
285 /**
286 * Add Placeholders to PMS Billing Fields
287 *
288 */
289 function wppb_pbpl_add_pms_fields_placeholder( $form_fields ) {
290 $forms_settings = get_option( 'wppb_toolbox_forms_settings' );
291
292 if ( $forms_settings['placeholder-labels'] != 'yes' || !function_exists( 'pms_in_inv_get_invoice_fields' ) )
293 return $form_fields;
294
295 $pms_billing_fields = pms_in_inv_get_invoice_fields();
296
297 foreach ($pms_billing_fields as $key => $data) {
298 $required = ( isset( $data['required'] ) && $data['required'] == 1 ) ? ' *' : '';
299
300 if ( ($data['type'] == 'text' || $data['type'] == 'select_state' ) && strpos( $form_fields,'name="'. $key .'"' ) )
301 $form_fields = str_replace('name="'. $key .'"', 'name="'. $key .'"" placeholder="'. $data['label'] . $required .'"', $form_fields);
302 }
303
304 return $form_fields;
305 }
306 add_filter('wppb_output_fields_filter', 'wppb_pbpl_add_pms_fields_placeholder' );
307
308
309 /**
310 * Add Placeholder to Resend Activation Email Form
311 *
312 */
313 function wppb_pbpl_resend_activation( $extra_attr, $input_title, $input_type ) {
314 $extra_attr .= ' placeholder="'. esc_attr( $input_title ) . '" ';
315
316 return $extra_attr;
317 }
318 add_filter( 'wppb_resend_activation_extra_attr', 'wppb_pbpl_resend_activation', 10, 3 );
319
320
321 /**
322 * Add Placeholder to Blog Details Fields
323 *
324 */
325 function wppb_pbpl_blog_details( $placeholder, $field_slug, $label ){
326
327 if( $field_slug !== 'default_field_blog_url' && $field_slug !== 'default_field_blog_title' )
328 return $placeholder;
329
330 return ' placeholder="'. esc_attr( $label ) . '" ';
331 }
332 add_filter( 'wppb_blog_details_field_placeholder', 'wppb_pbpl_blog_details', 10, 3 );
333
334
335 /**
336 * Add Placeholder Labels classes
337 *
338 */
339 function wppb_pbpl_add_resend_activation_classes( $classes, $field ) {
340 $forms_settings = get_option( 'wppb_toolbox_forms_settings' );
341
342 if ( $forms_settings['placeholder-labels'] == 'yes' )
343 $classes .= ' pbpl-class';
344
345 return $classes;
346 }
347 add_filter( 'wppb_resend_activation_extra_css_class', 'wppb_pbpl_add_resend_activation_classes', 20, 2);
348 add_filter( 'wppb_login_field_extra_css_class', 'wppb_pbpl_add_resend_activation_classes', 20, 2);
349 add_filter( 'wppb_recover_field_extra_css_class', 'wppb_pbpl_add_resend_activation_classes', 20, 2);
350
351