acf_upload_files()ACF 5.0.9

This function will walk through the $_FILES data and upload each found.

Хуков нет.

Возвращает

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

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

acf_upload_files( $ancestors );
$ancestors(массив)
An internal parameter, not required.
По умолчанию: array()

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

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

Код acf_upload_files() ACF 6.0.4

function acf_upload_files( $ancestors = array() ) {

	$file = acf_sanitize_files_array( $_FILES['acf'] );

	// walk through ancestors
	if ( ! empty( $ancestors ) ) {

		foreach ( $ancestors as $a ) {

			foreach ( array_keys( $file ) as $k ) {

				$file[ $k ] = $file[ $k ][ $a ];

			}
		}
	}

	// is array?
	if ( is_array( $file['name'] ) ) {

		foreach ( array_keys( $file['name'] ) as $k ) {

			$_ancestors = array_merge( $ancestors, array( $k ) );

			acf_upload_files( $_ancestors );

		}

		return;

	}

	// Bail early if file has error (no file uploaded).
	if ( $file['error'] ) {
		return;
	}

	$field_key  = end( $ancestors );
	$nonce_name = $field_key . '_file_nonce';

	if ( empty( $_REQUEST['acf'][ $nonce_name ] ) || ! wp_verify_nonce( sanitize_text_field( $_REQUEST['acf'][ $nonce_name ] ), 'acf/file_uploader_nonce/' . $field_key ) ) {
		return;
	}

	// Assign global _acfuploader for media validation.
	$_POST['_acfuploader'] = $field_key;

	// file found!
	$attachment_id = acf_upload_file( $file );

	// update $_POST
	array_unshift( $ancestors, 'acf' );
	acf_update_nested_array( $_POST, $ancestors, $attachment_id );

}