acf_rest_reduce_icon_picker_reference() │ ACF 6.8.10

All-or-nothing reduction for Icon Picker fields.

Icon Picker stores a compound value { type: string, value: mixed } and only its media_library variant expands a stored attachment ID into a full attachment array in standard-format mode. The other variants (dashicons, url, svg) carry user-provided data with no permission gate needed.

When the type is media_library and the caller cannot read the target attachment, the field is reduced to the same shape ?acf_format=light would return: { type:'media_library', value: <int> }. Everything else passes through unchanged.

Хуков нет.

Возвращает

mixed.

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

acf_rest_reduce_icon_picker_reference( $formatted_value, $raw_value, $field );
$formatted_value(разное) (обязательный)
The formatted field value.
$raw_value(разное) (обязательный)
The raw field value.
$field(массив) (обязательный)
The field array.

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

С версии 6.8.10 Введена.
Since ACF 6.8.10

Код acf_rest_reduce_icon_picker_reference() ACF 6.8.11

function acf_rest_reduce_icon_picker_reference( $formatted_value, $raw_value, $field ) {
	if ( ! is_array( $formatted_value ) ) {
		return $formatted_value;
	}

	$type = $formatted_value['type'] ?? ( is_array( $raw_value ) ? $raw_value['type'] ?? null : null );
	if ( 'media_library' !== $type ) {
		return $formatted_value;
	}

	$target_id = 0;
	if ( is_array( $raw_value ) && isset( $raw_value['value'] ) && is_numeric( $raw_value['value'] ) ) {
		$target_id = (int) $raw_value['value'];
	} elseif ( isset( $formatted_value['value'] ) ) {
		$expanded = $formatted_value['value'];
		if ( is_array( $expanded ) && isset( $expanded['ID'] ) ) {
			$target_id = (int) $expanded['ID'];
		} elseif ( is_numeric( $expanded ) ) {
			$target_id = (int) $expanded;
		}
	}

	if ( $target_id <= 0 ) {
		return $formatted_value;
	}

	if ( acf_rest_reference_is_exposable( $target_id, $field ) ) {
		return $formatted_value;
	}

	return array(
		'type'  => 'media_library',
		'value' => $target_id,
	);
}