WC_Admin_Upload_Downloadable_Product::unique_filename()
Change filename to append random text.
Метод класса: WC_Admin_Upload_Downloadable_Product{}
Хуков нет.
Возвращает
Строку
. Modified filename.
Использование
$WC_Admin_Upload_Downloadable_Product = new WC_Admin_Upload_Downloadable_Product(); $WC_Admin_Upload_Downloadable_Product->unique_filename( $full_filename, $ext );
- $full_filename(строка) (обязательный)
- Original filename with extension.
- $ext(строка) (обязательный)
- Extension.
Код WC_Admin_Upload_Downloadable_Product::unique_filename() WC Admin Upload Downloadable Product::unique filename WC 9.4.2
public function unique_filename( $full_filename, $ext ) { $ideal_random_char_length = 6; // Not going with a larger length because then downloaded filename will not be pretty. $max_filename_length = 255; // Max file name length for most file systems. $length_to_prepend = min( $ideal_random_char_length, $max_filename_length - strlen( $full_filename ) - 1 ); if ( 1 > $length_to_prepend ) { return $full_filename; } $suffix = strtolower( wp_generate_password( $length_to_prepend, false, false ) ); $filename = $full_filename; if ( strlen( $ext ) > 0 ) { $filename = substr( $filename, 0, strlen( $filename ) - strlen( $ext ) ); } $full_filename = str_replace( $filename, "$filename-$suffix", $full_filename ); return $full_filename; }