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 / 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.9, at admin/advanced-settings/includes/forms/placeholder-labels.php

315 lines 10.1 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', 'normal', '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', 'normal', '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="cozmoslabs-form-field-wrapper cozmoslabs-toggle-switch">
131 <label class="cozmoslabs-form-field-label" for="pbpl-active"><?php esc_html_e( 'Enable Placeholders', 'profile-builder' ); ?></label>
132
133 <div class="cozmoslabs-toggle-container">
134 <input type="checkbox" id="pbpl-active" name="pbpl-active" value="yes" <?php echo $pbpl_select_value == 'yes' ? 'checked' : ''; ?>>
135 <label class="cozmoslabs-toggle-track" for="pbpl-active"></label>
136 </div>
137
138 <div class="cozmoslabs-toggle-description">
139 <p class="cozmoslabs-description"><?php esc_html_e( 'Replace labels with placeholders', 'profile-builder' ) ?></p>
140 </div>
141 </div>
142 <?php
143 }
144
145
146 /*
147 * Function that saves the Meta Box option
148 *
149 * @since v.2.0
150 *
151 */
152 function wppb_pbpl_save_meta_box_option() {
153 global $post;
154
155 if( isset( $_POST['pbpl-active'] ) ) {
156 $pbpl_select_value = sanitize_text_field( $_POST['pbpl-active'] );
157
158 update_post_meta( $post->ID, 'pbpl-active', $pbpl_select_value );
159 }
160 elseif ( !empty( $post->ID ) ) update_post_meta( $post->ID, 'pbpl-active', 'no' );
161 }
162 add_action( 'save_post', 'wppb_pbpl_save_meta_box_option' );
163
164
165 /*
166 * Function that activate or deactivate replacement of labels with placeholders in form
167 *
168 * @since v.2.0
169 *
170 * @param array $form Contain the form args
171 */
172 function wppb_pbpl_activate( $form ) {
173 $pbpl_pb_moduleSettings = get_option( 'wppb_module_settings', 'not_found' );
174
175 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' ) ) {
176 if( ! empty( $form['ID'] ) ) {
177 $pbpl_saved_value = get_post_meta( $form['ID'], 'pbpl-active', true );
178
179 if( $pbpl_saved_value == 'no' ) {
180 return;
181 } else {
182 wppb_pbpl_add_filters();
183 }
184 } else {
185 wppb_pbpl_add_filters();
186 }
187 } else {
188 wppb_pbpl_add_filters();
189 }
190 }
191 add_action( 'wppb_form_args_before_output', 'wppb_pbpl_activate' );
192
193
194 /*
195 * Function that adds the necessary filters
196 *
197 * @since v.2.0
198 *
199 */
200 function wppb_pbpl_add_filters() {
201 add_filter( 'wppb_field_css_class', 'wppb_pbpl_field_css_class', 10, 1 );
202 add_filter( 'wppb_extra_attribute', 'wppb_pbpl_extra_attribute', 10, 3 );
203 add_filter( 'wppb_woo_extra_attribute', 'wppb_pbpl_woo_extra_attribute', 10, 2 );
204 add_filter( 'wppb_extra_select_option', 'wppb_pbpl_extra_select_option', 10, 3 );
205 add_filter( 'wppb_select2_multiple_arguments', 'wppb_pbpl_select2_multiple_placeholder', 10, 3 );
206 }
207
208 /*
209 * Function that adds the necessary filters
210 *
211 * @since v.2.3.4
212 *
213 */
214 function wppb_pbpl_extra_select_option( $option, $field, $item_title ) {
215 $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>';
216
217 return $option;
218 }
219
220 /*
221 * Function that adds placeholder for Select2 Multiple field
222 *
223 * @since v.2.3.4
224 *
225 */
226 function wppb_pbpl_select2_multiple_placeholder( $arguments, $form_location, $field ) {
227 $arguments['placeholder'] = esc_attr( wppb_icl_t( 'plugin profile-builder-pro', 'custom_field_'.$field['id'].'_title_translation', $field['field-title'], true ) ) . ( $field['required'] == 'Yes' ? '*' : '' );
228
229 return $arguments;
230 }
231
232 /*
233 * Function that adds placeholder for Recover Password form fields
234 *
235 * @since v.2.3.4
236 *
237 */
238 function wppb_pbpl_recover_password( $extra_attr, $input_title, $input_type ) {
239 $extra_attr .= ' placeholder="'. esc_attr( $input_title ) . '" ';
240
241 return $extra_attr;
242 }
243 add_filter( 'wppb_recover_password_extra_attr', 'wppb_pbpl_recover_password', 10, 3 );
244
245
246 /**
247 * Add necessary class to PMS Billing Fields and replace empty Option for Select Fields (placeholder)
248 *
249 */
250 function wppb_pms_add_classes ( $fields ) {
251 $forms_settings = get_option( 'wppb_toolbox_forms_settings' );
252
253 if ( $forms_settings['placeholder-labels'] == 'yes' ) {
254 foreach ( $fields as $field ) {
255 if ( isset( $field['name'] ) && isset( $field['wrapper_class'] ) )
256 $fields[$field['name']]['wrapper_class'] .= ' pbpl-class';
257
258 if ( isset($field['options']) ) {
259 $fields[$field['name']]['options'][''] = __( 'Select an option', 'profile-builder' );
260 }
261 }
262 }
263
264 return $fields;
265 }
266 add_filter('pms_inv_get_invoice_fields', 'wppb_pms_add_classes' );
267 add_filter('pms_get_tax_extra_fields', 'wppb_pms_add_classes' );
268
269
270 /**
271 * Add Placeholders to PMS Billing Fields
272 *
273 */
274 function wppb_pbpl_add_pms_fields_placeholder( $form_fields ) {
275 $forms_settings = get_option( 'wppb_toolbox_forms_settings' );
276
277 if ( $forms_settings['placeholder-labels'] != 'yes' || !function_exists( 'pms_in_inv_get_invoice_fields' ) )
278 return $form_fields;
279
280 $pms_billing_fields = pms_in_inv_get_invoice_fields();
281
282 foreach ($pms_billing_fields as $key => $data) {
283 $required = ( isset( $data['required'] ) && $data['required'] == 1 ) ? ' *' : '';
284
285 if ( ($data['type'] == 'text' || $data['type'] == 'select_state' ) && strpos( $form_fields,'name="'. $key .'"' ) )
286 $form_fields = str_replace('name="'. $key .'"', 'name="'. $key .'"" placeholder="'. $data['label'] . $required .'"', $form_fields);
287 }
288
289 return $form_fields;
290 }
291 add_filter('wppb_output_fields_filter', 'wppb_pbpl_add_pms_fields_placeholder' );
292
293
294 /**
295 * Add Placeholder to Resend Activation Email Form
296 *
297 */
298 function wppb_pbpl_resend_activation( $extra_attr, $input_title, $input_type ) {
299 $extra_attr .= ' placeholder="'. esc_attr( $input_title ) . '" ';
300
301 return $extra_attr;
302 }
303 add_filter( 'wppb_resend_activation_extra_attr', 'wppb_pbpl_resend_activation', 10, 3 );
304
305 function wppb_pbpl_add_resend_activation_classes( $classes, $field ) {
306 $forms_settings = get_option( 'wppb_toolbox_forms_settings' );
307
308 if ( $forms_settings['placeholder-labels'] == 'yes' )
309 $classes .= ' pbpl-class';
310
311 return $classes;
312 }
313 add_filter( 'wppb_resend_activation_extra_css_class', 'wppb_pbpl_add_resend_activation_classes', 20, 2);
314
315