Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
12/13/2016 03:09:52 AM (10 years ago)
Author:
boonebgorges
Message:

XProfile: Abstract date-parsing logic during save routines into standalone function.

This ensures that validation works the same way in all contexts where
date fields can be saved.

Props lakrisgubben.
Fixes #4187.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-members/bp-members-screens.php

    r11032 r11295  
    150150                                // Loop through the posted fields formatting any datebox values then validate the field.
    151151                                foreach ( (array) $profile_field_ids as $field_id ) {
    152                                         if ( !isset( $_POST['field_' . $field_id] ) ) {
    153                                                 if ( !empty( $_POST['field_' . $field_id . '_day'] ) && !empty( $_POST['field_' . $field_id . '_month'] ) && !empty( $_POST['field_' . $field_id . '_year'] ) )
    154                                                         $_POST['field_' . $field_id] = date( 'Y-m-d H:i:s', strtotime( $_POST['field_' . $field_id . '_day'] . $_POST['field_' . $field_id . '_month'] . $_POST['field_' . $field_id . '_year'] ) );
    155                                         }
     152                                        bp_xprofile_maybe_format_datebox_post_data( $field_id );
    156153
    157154                                        // Create errors for required fields without values.
    … …  
    219216                                        $profile_field_ids = explode( ',', $_POST['signup_profile_field_ids'] );
    220217
    221                                         // Loop through the posted fields formatting any datebox values then add to usermeta - @todo This logic should be shared with the same in xprofile_screen_edit_profile().
     218                                        /*
     219                                         * Loop through the posted fields, formatting any
     220                                         * datebox values, then add to usermeta.
     221                                         */
    222222                                        foreach ( (array) $profile_field_ids as $field_id ) {
    223                                                 if ( ! isset( $_POST['field_' . $field_id] ) ) {
    224 
    225                                                         if ( ! empty( $_POST['field_' . $field_id . '_day'] ) && ! empty( $_POST['field_' . $field_id . '_month'] ) && ! empty( $_POST['field_' . $field_id . '_year'] ) ) {
    226                                                                 // Concatenate the values.
    227                                                                 $date_value = $_POST['field_' . $field_id . '_day'] . ' ' . $_POST['field_' . $field_id . '_month'] . ' ' . $_POST['field_' . $field_id . '_year'];
    228 
    229                                                                 // Turn the concatenated value into a timestamp.
    230                                                                 $_POST['field_' . $field_id] = date( 'Y-m-d H:i:s', strtotime( $date_value ) );
    231                                                         }
    232                                                 }
     223                                                bp_xprofile_maybe_format_datebox_post_data( $field_id );
    233224
    234225                                                if ( !empty( $_POST['field_' . $field_id] ) )
Note: See TracChangeset for help on using the changeset viewer.