acf_field_select::format_rest_choices
Formats the choices available for the REST API.
Метод класса: acf_field_select{}
Хуков нет.
Возвращает
array.
Использование
$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 field select::format rest choices ACF 6.8.8
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 );
}