← All changes
|
admin/advanced-settings/includes/forms/placeholder-labels.php
+87
-17
3.9.6
→
4.0.3
View file →
| @@ -1,5 +1,8 @@ | ||
| 1 | 1 | <?php |
| 2 | +// Exit if accessed directly | |
| 3 | +if ( ! defined( 'ABSPATH' ) ) exit; | |
| 4 | + | |
| 2 | 5 | /* |
| 3 | 6 | * Function that enqueues the necessary scripts in the front-end area |
| 4 | 7 | * |
| 5 | 8 | * @since v.1.0 |
| @@ -27,9 +30,9 @@ | ||
| 27 | 30 | */ |
| 28 | 31 | function wppb_pbpl_field_css_class( $field ) { |
| 29 | 32 | $field = esc_attr( $field ); |
| 30 | 33 | |
| 31 | - if( strpos( $field, 'wppb-subscription-plans' ) == false ) { | |
| 34 | + if( strpos( $field, 'wppb-subscription-plans' ) == false && strpos( $field, 'wppb-default-blog-details' ) == false ) { | |
| 32 | 35 | $field = $field . ' pbpl-class'; |
| 33 | 36 | } |
| 34 | 37 | |
| 35 | 38 | return $field; |
| @@ -64,8 +67,9 @@ | ||
| 64 | 67 | 'Datepicker', |
| 65 | 68 | 'Number', |
| 66 | 69 | 'Validation', |
| 67 | 70 | 'Email', |
| 71 | + 'Input (Hidden)', | |
| 68 | 72 | ); |
| 69 | 73 | |
| 70 | 74 | if( ! empty ( $field ) && in_array( $field['field'], $extra_attr_only_for ) ) { |
| 71 | 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' ) ? '*' : '' ) . '"'; |
| @@ -126,18 +130,23 @@ | ||
| 126 | 130 | $pbpl_select_value = get_post_meta( $post->ID, 'pbpl-active', true ); |
| 127 | 131 | $pbpl_select_value = esc_attr( $pbpl_select_value ); |
| 128 | 132 | |
| 129 | 133 | ?> |
| 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> | |
| 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> | |
| 138 | 145 | </div> |
| 139 | 146 | <?php |
| 147 | + | |
| 148 | + wp_nonce_field( 'wppb-pbpl-post-'. $post->ID .'-options-verify', 'wppb_pbpl_save_post_options', false ); | |
| 140 | 149 | } |
| 141 | 150 | |
| 142 | 151 | |
| 143 | 152 | /* |
| @@ -145,16 +154,25 @@ | ||
| 145 | 154 | * |
| 146 | 155 | * @since v.2.0 |
| 147 | 156 | * |
| 148 | 157 | */ |
| 149 | -function wppb_pbpl_save_meta_box_option() { | |
| 150 | - global $post; | |
| 158 | +function wppb_pbpl_save_meta_box_option( $post_id ) { | |
| 151 | 159 | |
| 152 | - if( isset( $_POST['pbpl-active'] ) ) { | |
| 153 | - $pbpl_select_value = sanitize_text_field( $_POST['pbpl-active'] ); | |
| 160 | + if( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) | |
| 161 | + return; | |
| 154 | 162 | |
| 155 | - update_post_meta( $post->ID, 'pbpl-active', $pbpl_select_value ); | |
| 156 | - } | |
| 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 | + | |
| 157 | 175 | } |
| 158 | 176 | add_action( 'save_post', 'wppb_pbpl_save_meta_box_option' ); |
| 159 | 177 | |
| 160 | 178 | |
| @@ -168,12 +186,12 @@ | ||
| 168 | 186 | function wppb_pbpl_activate( $form ) { |
| 169 | 187 | $pbpl_pb_moduleSettings = get_option( 'wppb_module_settings', 'not_found' ); |
| 170 | 188 | |
| 171 | 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' ) ) { |
| 172 | - if( ! empty( $form['ID'] ) ) { | |
| 190 | + if( wppb_pbpl_form_uses_per_form_option( $form ) ) { | |
| 173 | 191 | $pbpl_saved_value = get_post_meta( $form['ID'], 'pbpl-active', true ); |
| 174 | 192 | |
| 175 | - if( $pbpl_saved_value == 'no' ) { | |
| 193 | + if( $pbpl_saved_value != 'yes' ) { | |
| 176 | 194 | return; |
| 177 | 195 | } else { |
| 178 | 196 | wppb_pbpl_add_filters(); |
| 179 | 197 | } |
| @@ -187,8 +205,38 @@ | ||
| 187 | 205 | add_action( 'wppb_form_args_before_output', 'wppb_pbpl_activate' ); |
| 188 | 206 | |
| 189 | 207 | |
| 190 | 208 | /* |
| 209 | + * Function that decides whether a form is governed by the per-form "Enable Placeholders" option | |
| 210 | + * | |
| 211 | + * - a bare shortcode resolves to the default form, which nobody ever opted in on | |
| 212 | + * - the modern form builder hides the meta box, so the option cannot be set there | |
| 213 | + * - when it does not apply, the global Placeholder Labels setting decides | |
| 214 | + * | |
| 215 | + * @param array $form Contain the form args | |
| 216 | + * | |
| 217 | + * @return bool | |
| 218 | + */ | |
| 219 | +function wppb_pbpl_form_uses_per_form_option( $form ) { | |
| 220 | + if( empty( $form['ID'] ) ) | |
| 221 | + return false; | |
| 222 | + | |
| 223 | + if( empty( $form['form_name'] ) || $form['form_name'] === 'unspecified' ) | |
| 224 | + return false; | |
| 225 | + | |
| 226 | + if( ! function_exists( 'wppb_fb_is_active_for' ) ) | |
| 227 | + return true; | |
| 228 | + | |
| 229 | + $post_type = get_post_type( $form['ID'] ); | |
| 230 | + | |
| 231 | + if( ! in_array( $post_type, array( 'wppb-rf-cpt', 'wppb-epf-cpt' ), true ) ) | |
| 232 | + return false; | |
| 233 | + | |
| 234 | + return ! wppb_fb_is_active_for( $post_type ); | |
| 235 | +} | |
| 236 | + | |
| 237 | + | |
| 238 | +/* | |
| 191 | 239 | * Function that adds the necessary filters |
| 192 | 240 | * |
| 193 | 241 | * @since v.2.0 |
| 194 | 242 | * |
| @@ -194,8 +242,9 @@ | ||
| 194 | 242 | * |
| 195 | 243 | */ |
| 196 | 244 | function wppb_pbpl_add_filters() { |
| 197 | 245 | add_filter( 'wppb_field_css_class', 'wppb_pbpl_field_css_class', 10, 1 ); |
| 246 | + add_filter( 'wppb_blog_details_field_css_class', 'wppb_pbpl_field_css_class', 10, 1 ); | |
| 198 | 247 | add_filter( 'wppb_extra_attribute', 'wppb_pbpl_extra_attribute', 10, 3 ); |
| 199 | 248 | add_filter( 'wppb_woo_extra_attribute', 'wppb_pbpl_woo_extra_attribute', 10, 2 ); |
| 200 | 249 | add_filter( 'wppb_extra_select_option', 'wppb_pbpl_extra_select_option', 10, 3 ); |
| 201 | 250 | add_filter( 'wppb_select2_multiple_arguments', 'wppb_pbpl_select2_multiple_placeholder', 10, 3 ); |
| @@ -297,8 +346,27 @@ | ||
| 297 | 346 | return $extra_attr; |
| 298 | 347 | } |
| 299 | 348 | add_filter( 'wppb_resend_activation_extra_attr', 'wppb_pbpl_resend_activation', 10, 3 ); |
| 300 | 349 | |
| 350 | + | |
| 351 | +/** | |
| 352 | + * Add Placeholder to Blog Details Fields | |
| 353 | + * | |
| 354 | + */ | |
| 355 | +function wppb_pbpl_blog_details( $placeholder, $field_slug, $label ){ | |
| 356 | + | |
| 357 | + if( $field_slug !== 'default_field_blog_url' && $field_slug !== 'default_field_blog_title' ) | |
| 358 | + return $placeholder; | |
| 359 | + | |
| 360 | + return ' placeholder="'. esc_attr( $label ) . '" '; | |
| 361 | +} | |
| 362 | +add_filter( 'wppb_blog_details_field_placeholder', 'wppb_pbpl_blog_details', 10, 3 ); | |
| 363 | + | |
| 364 | + | |
| 365 | +/** | |
| 366 | + * Add Placeholder Labels classes | |
| 367 | + * | |
| 368 | + */ | |
| 301 | 369 | function wppb_pbpl_add_resend_activation_classes( $classes, $field ) { |
| 302 | 370 | $forms_settings = get_option( 'wppb_toolbox_forms_settings' ); |
| 303 | 371 | |
| 304 | 372 | if ( $forms_settings['placeholder-labels'] == 'yes' ) |
| @@ -306,5 +374,7 @@ | ||
| 306 | 374 | |
| 307 | 375 | return $classes; |
| 308 | 376 | } |
| 309 | 377 | add_filter( 'wppb_resend_activation_extra_css_class', 'wppb_pbpl_add_resend_activation_classes', 20, 2); |
| 378 | +add_filter( 'wppb_login_field_extra_css_class', 'wppb_pbpl_add_resend_activation_classes', 20, 2); | |
| 379 | +add_filter( 'wppb_recover_field_extra_css_class', 'wppb_pbpl_add_resend_activation_classes', 20, 2); | |
| 310 | 380 | |