WC_Admin_Post_Types::unique_filename() public WC 1.0
Change filename to append random text.
{} Это метод класса: WC_Admin_Post_Types{}
Хуков нет.
Возвращает
Строку. Modified filename.
Использование
$WC_Admin_Post_Types = new WC_Admin_Post_Types(); $WC_Admin_Post_Types->unique_filename( $full_filename, $ext );
- $full_filename(строка) (обязательный)
- Original filename with extension.
- $ext(строка) (обязательный)
- Extension.
Код WC_Admin_Post_Types::unique_filename() WC Admin Post Types::unique filename WC 5.0.0
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;
}