Changeset 53751 for trunk/src/wp-includes/class-wp-image-editor.php
- Timestamp:
- 07/21/2022 06:01:01 PM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-wp-image-editor.php
r53547 r53751 334 334 protected function get_output_format( $filename = null, $mime_type = null ) { 335 335 $new_ext = null; 336 337 // If no mime type is passed but output mime type is set, use that. 338 if ( ! $mime_type && ! empty( $this->output_mime_type ) ) { 339 $mime_type = $this->output_mime_type; 340 } 336 341 337 342 // By default, assume specified type takes priority. … … 426 431 427 432 /** 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 433 * Builds an output filename based on current file, and adding proper suffix. 434 * 435 * @since 3.5.0 436 * @since 6.1.0 Skips adding a suffix when set to an empty string. When the 437 * file extension being generated doesn't match the image file extension, 438 * add the extension to the suffix 439 * 440 * @param string $suffix Optional. Suffix to add to the filename. The default null 441 * will result in a 'widthxheight' suffix. Passing 442 * an empty string will result in no suffix. 443 * @param string $dest_path Optional. The path to save the file to. The default null 444 * will use the image file path. 445 * @param string $extension Optional. The file extension to use. The default null 446 * will use the image file extension. 447 * @return string filename The generated file name. 436 448 */ 437 449 public function generate_filename( $suffix = null, $dest_path = null, $extension = null ) { 438 450 // $suffix will be appended to the destination filename, just before the extension. 439 if ( !$suffix ) {451 if ( null === $suffix ) { 440 452 $suffix = $this->get_suffix(); 441 453 } … … 458 470 } 459 471 460 return trailingslashit( $dir ) . "{$name}-{$suffix}.{$new_ext}"; 472 if ( empty( $suffix ) ) { 473 $suffix = ''; 474 } else { 475 $suffix = "-{$suffix}"; 476 } 477 478 // When the file extension being generated doesn't match the image file extension, 479 // add the extension to the suffix to ensure a unique file name. Prevents 480 // name conflicts when a single image type can have multiple extensions, 481 // eg. .jpg, .jpeg and .jpe are all valid JPEG extensions. 482 if ( ! empty( $extension ) && $extension !== $ext ) { 483 $suffix .= "-{$ext}"; 484 } 485 486 return trailingslashit( $dir ) . "{$name}{$suffix}.{$new_ext}"; 461 487 } 462 488 … … 638 664 return wp_get_default_extension_for_mime_type( $mime_type ); 639 665 } 666 667 /** 668 * Set the editor output mime type, useful when outputting alternate mime types. 669 * 670 * Track that the mime type is set with the mime type set flag. 671 * 672 * @since 6.1.0 673 * 674 * @param string $output_mime_type The mime type to set. 675 */ 676 public function set_output_mime_type( $output_mime_type ) { 677 $this->output_mime_type = $output_mime_type; 678 } 679 680 /** 681 * Reset the mime type to the original file mime type. 682 * 683 * Reset the mime type set flag. 684 * 685 * @since 6.1.0 686 */ 687 public function reset_output_mime_type() { 688 $this->output_mime_type = $this->mime_type; 689 } 640 690 } 641
Note: See TracChangeset
for help on using the changeset viewer.