_acf_verify_file_uploader_nonce() │ ACF 6.8.11

Returns true if the basic uploader nonce submitted for a field verifies for the object being saved.

The nonce is verified against the render IDs set by acf_set_upload_render_ids() for this save, or the post ID being saved. Saves that never set render IDs, such as other plugins' form handlers, also accept the render IDs of the field lists in the request. The nonce itself is signed for the current user and render, so this only accepts nonces the user was served.

Внутренняя функция — эта функция рассчитана на использование самим ядром. Не рекомендуется использовать эту функцию в своем коде.

Хуков нет.

Возвращает

boolean.

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

_acf_verify_file_uploader_nonce( $field_key );
$field_key(строка) (обязательный)
The field key.

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

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

Код _acf_verify_file_uploader_nonce() ACF 6.8.11

function _acf_verify_file_uploader_nonce( $field_key ) {
	$nonce_name = $field_key . '_file_nonce';

	if ( empty( $_REQUEST['acf'][ $nonce_name ] ) || ! is_string( $_REQUEST['acf'][ $nonce_name ] ) ) {
		return false;
	}

	$nonce = sanitize_text_field( wp_unslash( $_REQUEST['acf'][ $nonce_name ] ) );

	$upload_render_ids = acf_get_form_data( 'upload_render_ids' );
	$render_ids        = is_array( $upload_render_ids ) && $upload_render_ids ? $upload_render_ids : array( (string) acf_get_form_data( 'post_id' ) );

	foreach ( $render_ids as $render_id ) {
		if ( '' !== (string) $render_id && wp_verify_nonce( $nonce, acf_get_file_uploader_nonce_action( (string) $render_id, $field_key ) ) ) {
			return true;
		}
	}

	if ( null !== $upload_render_ids || ! isset( $_POST['_acf_fields'] ) || ! is_array( $_POST['_acf_fields'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing -- Only the keys are read, as render IDs to verify the uploader nonce against.
		return false;
	}

	foreach ( array_map( 'strval', array_keys( $_POST['_acf_fields'] ) ) as $render_id ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Only the keys are read.
		if ( '' !== $render_id && wp_verify_nonce( $nonce, acf_get_file_uploader_nonce_action( $render_id, $field_key ) ) ) {
			return true;
		}
	}

	return false;
}