acf_restrict_uploaded_field_keys() │ ACF 6.8.11

Restricts $_FILES['acf'] to the given top-level keys, in place.

ACF_Media::save_files() uploads every file in $_FILES['acf'] on each acf/save_post and writes the attachment ID back into $_POST['acf'], so uploads must be restricted to the same keys as $_POST['acf'].

Хуков нет.

Возвращает

void. Ничего (null).

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

acf_restrict_uploaded_field_keys( $allowed_keys );
$allowed_keys(массив) (обязательный)
The allowed top-level keys.

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

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

Код acf_restrict_uploaded_field_keys() ACF 6.8.11

function acf_restrict_uploaded_field_keys( array $allowed_keys ) {
	// phpcs:disable WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Verified by the caller; only filters keys.
	if ( ! isset( $_FILES['acf'] ) ) {
		return;
	}

	if ( ! is_array( $_FILES['acf'] ) ) {
		$_FILES['acf'] = array();
		return;
	}

	$allowed_keys = array_flip( acf_normalize_field_keys( $allowed_keys ) );

	foreach ( $_FILES['acf'] as $attribute => $branches ) {
		$_FILES['acf'][ $attribute ] = is_array( $branches ) ? array_intersect_key( $branches, $allowed_keys ) : array();
	}
	// phpcs:enable WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
}