able 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. * * @param WC_Product $product The product we wish to examine for downloadable file paths. */ 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() ) ); } } } /** * Indicates if a synchronization of product download directories is in progress. * * @return bool */ public function in_progress(): bool { return (bool) get_option( self::SYNC_TASK_PAGE, false ); } /** * Returns a value between 0 and 100 representing the percentage complete of the current sync. * * @return int */ public function get_progress(): int { return min( 100, max( 0, (int) get_option( self::SYNC_TASK_PROGRESS, 0 ) ) ); } }