bp_xprofile_maybe_format_datebox_post_data( int $field_id )

Formats datebox field values passed through a POST request.

Description

Parameters

$field_id

(int) (Required) The id of the current field being looped through.

Return

(void) This function only changes the global $_POST that should contain the datebox data.

Source

File: bp-xprofile/bp-xprofile-functions.php

function bp_xprofile_maybe_format_datebox_post_data( $field_id ) {
	if ( ! isset( $_POST['field_' . $field_id] ) ) {
		if ( ! empty( $_POST['field_' . $field_id . '_day'] ) && ! empty( $_POST['field_' . $field_id . '_month'] ) && ! empty( $_POST['field_' . $field_id . '_year'] ) ) {
			// Concatenate the values.
			$date_value = $_POST['field_' . $field_id . '_day'] . ' ' . $_POST['field_' . $field_id . '_month'] . ' ' . $_POST['field_' . $field_id . '_year'];

			// Check that the concatenated value can be turned into a timestamp.
			if ( $timestamp = strtotime( $date_value ) ) {
				// Add the timestamp to the global $_POST that should contain the datebox data.
				$_POST['field_' . $field_id] = date( 'Y-m-d H:i:s', $timestamp );
			}
		}
	}
}

Changelog

Changelog
Version Description
BuddyPress 2.8.0 Introduced.

Questions?

We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.