bp_xprofile_maybe_format_datebox_post_data( int $field_id )

Formats datebox field values passed through a POST request.


Parameters Parameters

$field_id

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


Top ↑

Return Return

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


Source 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 );
			}
		}
	}
}


Top ↑

Changelog Changelog

Changelog
Version Description
2.8.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.