acf_upload_files()ACF 5.0.9

acf_upload_files

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

@type    function

Хуков нет.

Возвращает

null. Ничего.

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

acf_upload_files( $ancestors );
$ancestors **
-
По умолчанию: array()

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

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

Код acf_upload_files() ACF 5.10.2

function acf_upload_files( $ancestors = array() ) {

	// vars
	$file = array(
		'name'     => '',
		'type'     => '',
		'tmp_name' => '',
		'error'    => '',
		'size'     => '',
	);

	// populate with $_FILES data
	foreach ( array_keys( $file ) as $k ) {

		$file[ $k ] = $_FILES['acf'][ $k ];

	}

	// 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 ealry if file has error (no file uploaded)
	if ( $file['error'] ) {

		return;

	}

	// assign global _acfuploader for media validation
	$_POST['_acfuploader'] = end( $ancestors );

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

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

}