acf_field_select::format_rest_choicespublicACF 6.2

Formats the choices available for the REST API.

Метод класса: acf_field_select{}

Хуков нет.

Возвращает

Массив.

Использование

$acf_field_select = new acf_field_select();
$acf_field_select->format_rest_choices( $choices );
$choices(массив) (обязательный)
The choices for the field.

Список изменений

С версии 6.2 Введена.

Код acf_field_select::format_rest_choices() ACF 6.4.2

public function format_rest_choices( $choices ) {
	$keys        = array_keys( $choices );
	$values      = array_values( $choices );
	$int_choices = array();

	if ( array_diff( $keys, $values ) ) {
		// User has specified custom keys.
		$choices = $keys;
	} else {
		// Default keys, same as value.
		$choices = $values;
	}

	// Assume everything is a string by default.
	$choices = array_map( 'strval', $choices );

	// Also allow integers if is_numeric().
	foreach ( $choices as $choice ) {
		if ( is_numeric( $choice ) ) {
			$int_choices[] = (int) $choice;
		}
	}

	return array_merge( $choices, $int_choices );
}