WC_Product::build_downloads_map()privateWC 1.0

Takes an array of downloadable file representations and converts it into an array of WC_Product_Download objects, indexed by download ID.

{} Это метод класса: WC_Product{}

Хуков нет.

Возвращает

WC_Product_Download[].

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

// private - только в коде основоного (родительского) класса
$result = $this->build_downloads_map( $downloads ): array;
$downloads(array[]|WC_Product_Download[]) (обязательный)
Download data to be re-mapped.

Код WC_Product::build_downloads_map() WC 6.9.1

private function build_downloads_map( array $downloads ): array {
	$downloads_map = array();

	foreach ( $downloads as $download_data ) {
		// If the item is already a WC_Product_Download we can add it to the map and move on.
		if ( is_a( $download_data, 'WC_Product_Download' ) ) {
			$downloads_map[ $download_data->get_id() ] = $download_data;
			continue;
		}

		// If the item is not an array, there is nothing else we can do (bad data).
		if ( ! is_array( $download_data ) ) {
			continue;
		}

		// Otherwise, transform the array to a WC_Product_Download and add to the map.
		$download_object = new WC_Product_Download();

		// If we don't have a previous hash, generate UUID for download.
		if ( empty( $download_data['download_id'] ) ) {
			$download_data['download_id'] = wp_generate_uuid4();
		}

		$download_object->set_id( $download_data['download_id'] );
		$download_object->set_name( $download_data['name'] );
		$download_object->set_file( $download_data['file'] );
		$download_object->set_enabled( isset( $download_data['enabled'] ) ? $download_data['enabled'] : true );

		$downloads_map[ $download_object->get_id() ] = $download_object;
	}

	return $downloads_map;
}