Automattic\WooCommerce\Internal\ProductDownloads\ApprovedDirectories

Synchronize::process_product()privateWC 1.0

Processes an individual downloadable product, adding the parent paths for any downloadable files to the Approved Download Directories list.

Any such paths will be added with the disabled flag set, because we want a site administrator to review and approve first.

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

Возвращает

null. Ничего.

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

// private - только в коде основоного (родительского) класса
$result = $this->process_product( $product );
$product(WC_Product) (обязательный)
The product we wish to examine for downloadable file paths.

Код Synchronize::process_product() WC 6.8.0

private function process_product( WC_Product $product ) {
	$downloads = $product->get_downloads();

	foreach ( $downloads as $downloadable ) {
		$parent_url = _x( 'invalid URL', 'Approved product download URLs migration', 'woocommerce' );

		try {
			$download_file = $downloadable->get_file();

			/**
			 * Controls whether shortcodes should be resolved and validated using the Approved Download Directory feature.
			 *
			 * @param bool $should_validate
			 */
			if ( apply_filters( 'woocommerce_product_downloads_approved_directory_validation_for_shortcodes', true ) && 'shortcode' === $downloadable->get_type_of_file_path() ) {
				$download_file = do_shortcode( $download_file );
			}

			$parent_url = ( new URL( $download_file ) )->get_parent_url();
			$this->register->add_approved_directory( $parent_url, false );
		} catch ( Exception $e ) {
			wc_get_logger()->log(
				'error',
				sprintf(
				/* translators: %s is a URL, %d is a product ID. */
					__( 'Product download migration: %1$s (for product %1$d) could not be added to the list of approved download directories.', 'woocommerce' ),
					$parent_url,
					$product->get_id()
				)
			);
		}
	}
}