Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
12/13/2016 03:09:52 AM (9 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-xprofile/bp-xprofile-functions.php

    r11243 r11295  
    12881288    return $field_ids;
    12891289}
     1290
     1291/**
     1292 * Formats datebox field 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
     1298 *              the datebox data.
     1299 */
     1300function bp_xprofile_maybe_format_datebox_post_data( $field_id ) {
     1301    if ( ! isset( $_POST['field_' . $field_id] ) ) {
     1302        if ( ! empty( $_POST['field_' . $field_id . '_day'] ) && ! empty( $_POST['field_' . $field_id . '_month'] ) && ! empty( $_POST['field_' . $field_id . '_year'] ) ) {
     1303            // Concatenate the values.
     1304            $date_value = $_POST['field_' . $field_id . '_day'] . ' ' . $_POST['field_' . $field_id . '_month'] . ' ' . $_POST['field_' . $field_id . '_year'];
     1305
     1306            // Check that the concatenated value can be turned into a timestamp.
     1307            if ( $timestamp = strtotime( $date_value ) ) {
     1308                // Add the timestamp to the global $_POST that should contain the datebox data.
     1309                $_POST['field_' . $field_id] = date( 'Y-m-d H:i:s', $timestamp );
     1310            }
     1311        }
     1312    }
     1313}
Note: See TracChangeset for help on using the changeset viewer.