WC_Admin_Upload_Downloadable_Product::update_filename()publicWC 4.0

Change filename for WooCommerce uploads and prepend unique chars for security.

Method of the class: WC_Admin_Upload_Downloadable_Product{}

No Hooks.

Return

String. New filename with unique hash.

Usage

$WC_Admin_Upload_Downloadable_Product = new WC_Admin_Upload_Downloadable_Product();
$WC_Admin_Upload_Downloadable_Product->update_filename( $full_filename, $ext, $dir );
$full_filename(string) (required)
Original filename.
$ext(string) (required)
Extension of file.
$dir(string) (required)
Directory path.

Changelog

Since 4.0 Introduced.

WC_Admin_Upload_Downloadable_Product::update_filename() code WC 9.7.1

public function update_filename( $full_filename, $ext, $dir ) {
	// phpcs:disable WordPress.Security.NonceVerification.Missing
	if ( ! isset( $_POST['type'] ) || ! 'downloadable_product' === $_POST['type'] ) {
		return $full_filename;
	}

	if ( ! strpos( $dir, 'woocommerce_uploads' ) ) {
		return $full_filename;
	}

	if ( 'no' === get_option( 'woocommerce_downloads_add_hash_to_filename' ) ) {
		return $full_filename;
	}

	return $this->unique_filename( $full_filename, $ext );
	// phpcs:enable WordPress.Security.NonceVerification.Missing
}