Skip to:
Content

BuddyPress.org

Ticket #4187: 4187.1.diff

File 4187.1.diff, 6.4 KB (added by lakrisgubben, 9 years ago)
  • src/bp-members/bp-members-screens.php

     
    149149
    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.
    158155                                        if ( xprofile_check_is_required_field( $field_id ) && empty( $_POST[ 'field_' . $field_id ] ) && ! bp_current_user_can( 'bp_moderate' ) )
     
    218215                                        // Let's compact any profile field info into usermeta.
    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                                        // Loop through the posted fields formatting any datebox values then add to usermeta
    222219                                        foreach ( (array) $profile_field_ids as $field_id ) {
    223                                                 if ( ! isset( $_POST['field_' . $field_id] ) ) {
     220                                                bp_xprofile_maybe_format_datebox_post_data( $field_id );
    224221
    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                                                 }
    233 
    234222                                                if ( !empty( $_POST['field_' . $field_id] ) )
    235223                                                        $usermeta['field_' . $field_id] = $_POST['field_' . $field_id];
    236224
  • src/bp-xprofile/bp-xprofile-functions.php

     
    12871287
    12881288        return $field_ids;
    12891289}
     1290
     1291/**
     1292 * Formats any datebox values passed through a POST request
     1293 *
     1294 * @since 2.8.0
     1295 *
     1296 * @param int $field_id The id of the current field being looped through.
     1297 * @return void This function only changes the global $_POST that should contain the datebox data.
     1298 */
     1299function bp_xprofile_maybe_format_datebox_post_data( $field_id ) {
     1300        if ( ! isset( $_POST['field_' . $field_id ] ) ) {
     1301                if ( ! empty( $_POST['field_' . $field_id . '_day'] ) && ! empty( $_POST['field_' . $field_id . '_month'] ) && ! empty( $_POST['field_' . $field_id . '_year'] ) ) {
     1302                        // Concatenate the values.
     1303                        $date_value = $_POST['field_' . $field_id . '_day'] . ' ' . $_POST['field_' . $field_id . '_month'] . ' ' . $_POST['field_' . $field_id . '_year'];
     1304
     1305                        // Check that the concatenated value can be turned into a timestamp.
     1306                        if ( $timestamp = strtotime( $date_value ) ) {
     1307                                // Add the timestamp to the global $_POST that should contain the datebox data.
     1308                                $_POST['field_' . $field_id] = date( 'Y-m-d H:i:s', $timestamp );
     1309                        }
     1310                }
     1311        }
     1312}
  • src/bp-xprofile/bp-xprofile-screens.php

     
    8585                $posted_field_ids = wp_parse_id_list( $_POST['field_ids'] );
    8686                $is_required      = array();
    8787
    88                 // Loop through the posted fields formatting any datebox values
    89                 // then validate the field.
     88                // Loop through the posted fields formatting any datebox values then validate the field.
    9089                foreach ( (array) $posted_field_ids as $field_id ) {
    91                         if ( !isset( $_POST['field_' . $field_id] ) ) {
     90                        bp_xprofile_maybe_format_datebox_post_data( $field_id );
    9291
    93                                 if ( !empty( $_POST['field_' . $field_id . '_day'] ) && !empty( $_POST['field_' . $field_id . '_month'] ) && !empty( $_POST['field_' . $field_id . '_year'] ) ) {
    94                                         // Concatenate the values.
    95                                         $date_value =   $_POST['field_' . $field_id . '_day'] . ' ' . $_POST['field_' . $field_id . '_month'] . ' ' . $_POST['field_' . $field_id . '_year'];
    96 
    97                                         // Turn the concatenated value into a timestamp.
    98                                         $_POST['field_' . $field_id] = date( 'Y-m-d H:i:s', strtotime( $date_value ) );
    99                                 }
    100 
    101                         }
    102 
    10392                        $is_required[ $field_id ] = xprofile_check_is_required_field( $field_id ) && ! bp_current_user_can( 'bp_moderate' );
    10493                        if ( $is_required[$field_id] && empty( $_POST['field_' . $field_id] ) ) {
    10594                                $errors = true;
  • src/bp-xprofile/classes/class-bp-xprofile-user-admin.php

     
    227227
    228228                        // Loop through the posted fields formatting any datebox values then validate the field.
    229229                        foreach ( (array) $posted_field_ids as $field_id ) {
    230                                 if ( ! isset( $_POST['field_' . $field_id ] ) ) {
    231                                         if ( ! empty( $_POST['field_' . $field_id . '_day'] ) && ! empty( $_POST['field_' . $field_id . '_month'] ) && ! empty( $_POST['field_' . $field_id . '_year'] ) ) {
     230                                bp_xprofile_maybe_format_datebox_post_data( $field_id );
    232231
    233                                                 // Concatenate the values.
    234                                                 $date_value =   $_POST['field_' . $field_id . '_day'] . ' ' . $_POST['field_' . $field_id . '_month'] . ' ' . $_POST['field_' . $field_id . '_year'];
    235 
    236                                                 // Turn the concatenated value into a timestamp.
    237                                                 $_POST['field_' . $field_id] = date( 'Y-m-d H:i:s', strtotime( $date_value ) );
    238                                         }
    239                                 }
    240 
    241232                                $is_required[ $field_id ] = xprofile_check_is_required_field( $field_id ) && ! bp_current_user_can( 'bp_moderate' );
    242233                                if ( $is_required[ $field_id ] && empty( $_POST['field_' . $field_id ] ) ) {
    243234                                        $redirect_to = add_query_arg( 'error', '2', $redirect_to );