Changeset 54086 for trunk/src/wp-includes/class-wp-image-editor.php
- Timestamp:
- 09/06/2022 09:13:17 PM (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-wp-image-editor.php
r54085 r54086 425 425 } 426 426 427 /** 428 * Builds an output filename based on current file, and adding proper suffix 429 * 430 * @since 3.5.0 431 * 432 * @param string $suffix 433 * @param string $dest_path 434 * @param string $extension 435 * @return string filename 427 /** 428 * Builds an output filename based on current file, and adding proper suffix. 429 * 430 * @since 3.5.0 431 * @since 6.1.0 Skips adding a suffix when set to an empty string. When the 432 * file extension being generated doesn't match the image file extension, 433 * add the extension to the suffix 434 * 435 * @param string $suffix Optional. Suffix to add to the filename. The default null 436 * will result in a 'widthxheight' suffix. Passing 437 * an empty string will result in no suffix. 438 * @param string $dest_path Optional. The path to save the file to. The default null 439 * will use the image file path. 440 * @param string $extension Optional. The file extension to use. The default null 441 * will use the image file extension. 442 * @return string filename The generated file name. 436 443 */ 437 444 public function generate_filename( $suffix = null, $dest_path = null, $extension = null ) { 438 445 // $suffix will be appended to the destination filename, just before the extension. 439 if ( !$suffix ) {446 if ( null === $suffix ) { 440 447 $suffix = $this->get_suffix(); 441 448 } … … 458 465 } 459 466 460 return trailingslashit( $dir ) . "{$name}-{$suffix}.{$new_ext}"; 467 if ( empty( $suffix ) ) { 468 $suffix = ''; 469 } else { 470 $suffix = "-{$suffix}"; 471 } 472 473 // When the file extension being generated doesn't match the image file extension, 474 // add the extension to the suffix to ensure a unique file name. Prevents 475 // name conflicts when a single image type can have multiple extensions, 476 // eg. .jpg, .jpeg and .jpe are all valid JPEG extensions. 477 if ( ! empty( $extension ) && $extension !== $ext ) { 478 $suffix .= "-{$ext}"; 479 } 480 481 return trailingslashit( $dir ) . "{$name}{$suffix}.{$new_ext}"; 461 482 } 462 483
Note: See TracChangeset
for help on using the changeset viewer.