WC_Admin_Post_Types::update_filename()publicWC 4.0

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

{} It's a method of the class: WC_Admin_Post_Types{}

No Hooks.

Return

String. New filename with unique hash.

Usage

$WC_Admin_Post_Types = new WC_Admin_Post_Types();
$WC_Admin_Post_Types->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.

Code of WC_Admin_Post_Types::update_filename() WC 6.7.0

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
}