This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness.

BP_REST_XProfile_Fields_Endpoint::get_date_field_options_array( BP_XProfile_Field $field, string $type = '' )

Get datebox options

Description

Parameters

$field

(BP_XProfile_Field) (Required) XProfile field object.

$type

(string) (Optional) Date type parameter.

Default value: ''

Return

(array)

Source

File: bp-xprofile/classes/class-bp-rest-xprofile-fields-endpoint.php

	private function get_date_field_options_array( $field, $type = '' ) {
		$eng_months = array(
			'January',
			'February',
			'March',
			'April',
			'May',
			'June',
			'July',
			'August',
			'September',
			'October',
			'November',
			'December',
		);

		$options = array();

		// $type will be passed by calling function when needed.
		switch ( $type ) {
			case 'day':
				for ( $i = 1; $i < 32; ++ $i ) {
					$options[] = array(
						'type' => 'option',
						'name' => $i,
					);
				}
				break;

			case 'month':
				for ( $i = 0; $i < 12; ++ $i ) {
					$options[] = array(
						'type' => 'option',
						'name' => $eng_months[ $i ],
					);
				}
				break;

			case 'year':
				$settings = BP_XProfile_Field_Type_Datebox::get_field_settings( $field->id );

				if ( 'relative' === $settings['range_type'] ) {
					// phpcs:ignore
					$start = date( 'Y' ) + $settings['range_relative_start'];
					// phpcs:ignore
					$end = date( 'Y' ) + $settings['range_relative_end'];
				} else {
					$start = $settings['range_absolute_start'];
					$end   = $settings['range_absolute_end'];
				}

				for ( $i = $end; $i >= $start; $i -- ) {
					$options[] = array(
						'type' => 'option',
						'name' => $i,
					);
				}
				break;
		}

		return $options;
	}

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.