acf_rest_apply_user_data_sanitizer()ACF 6.8.7

Reduces User field REST responses to IDs for requesters without the list_users capability. Hooked into acf/rest/format_value_for_rest so the sanitizer only runs for field types that can carry user data.

No Hooks.

Returns

Mixed.

Usage

acf_rest_apply_user_data_sanitizer( $value_formatted, $post_id, $field, $value, $format );
$value_formatted(mixed) (required)
The formatted field value.
$post_id(string|int) (required)
The post ID of the current object.
$field(array) (required)
The field array.
$value(mixed) (required)
The raw/unformatted value.
$format(string) (required)
The format applied to the field value.

Changelog

Since 6.8.7 Introduced.
Since ACF 6.8.7

acf_rest_apply_user_data_sanitizer() code ACF 6.8.8

function acf_rest_apply_user_data_sanitizer( $value_formatted, $post_id, $field, $value, $format ) {
	if ( 'standard' !== $format || empty( $field['type'] ) ) {
		return $value_formatted;
	}

	if ( ! in_array( $field['type'], array( 'user', 'group', 'clone', 'repeater', 'flexible_content' ), true ) ) {
		return $value_formatted;
	}

	// Preserve existing behavior for requesters authorized to list users.
	if ( current_user_can( 'list_users' ) ) {
		return $value_formatted;
	}

	return acf_rest_sanitize_user_data( $value_formatted, $value, $field );
}