Changeset 55437
- Timestamp:
- 03/01/2023 12:34:18 AM (19 months ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/post.php
r55401 r55437 706 706 * Retrieves attached file path based on attachment ID. 707 707 * 708 * Will return intermediate size path if the `$size` parameter is provided.709 *710 708 * By default the path will go through the {@see 'get_attached_file'} filter, but 711 709 * passing `true` to the `$unfiltered` argument will return the file path unfiltered. … … 716 714 * 717 715 * @since 2.0.0 718 * @since 6.2.0 The `$size` parameter was added. 719 * 720 * @param int $attachment_id Attachment ID. 721 * @param bool $unfiltered Optional. Whether to skip the {@see 'get_attached_file'} filter. 722 * Default false. 723 * @param string|int[] $size Optional. Image size. Accepts any registered image size name, or an array 724 * of width and height values in pixels (in that order). Default empty string. 716 * 717 * @param int $attachment_id Attachment ID. 718 * @param bool $unfiltered Optional. Whether to skip the {@see 'get_attached_file'} filter. 719 * Default false. 725 720 * @return string|false The file path to where the attached file should be, false otherwise. 726 721 */ 727 function get_attached_file( $attachment_id, $unfiltered = false, $size = '' ) { 728 729 // Check for intermediate sizes first, otherwise fall back to the original attachment size. 730 if ( ! empty( $size ) ) { 731 $intermediate_image = image_get_intermediate_size( $attachment_id, $size ); 732 if ( ! $intermediate_image || ! isset( $intermediate_image['path'] ) ) { 733 return false; 734 } 735 736 $file = $intermediate_image['path']; 737 } else { 738 $file = get_post_meta( $attachment_id, '_wp_attached_file', true ); 739 } 722 function get_attached_file( $attachment_id, $unfiltered = false ) { 723 $file = get_post_meta( $attachment_id, '_wp_attached_file', true ); 740 724 741 725 // If the file is relative, prepend upload dir. … … 755 739 * 756 740 * @since 2.1.0 757 * @since 6.2.0 The `$size` parameter was added.758 741 * 759 742 * @param string|false $file The file path to where the attached file should be, false otherwise. 760 743 * @param int $attachment_id Attachment ID. 761 * @param string|int[] $size Optional. Image size. Accepts any registered image size name, or an array762 * of width and height values in pixels (in that order). Default empty string.763 744 */ 764 return apply_filters( 'get_attached_file', $file, $attachment_id , $size);745 return apply_filters( 'get_attached_file', $file, $attachment_id ); 765 746 } 766 747 -
trunk/tests/phpunit/tests/media/wpGenerateAttachmentMetadata.php
r55199 r55437 19 19 * 20 20 * @ticket 49412 21 * @ticket 5178022 21 * 23 22 * @covers ::wp_create_image_subsizes … … 30 29 $this->assertSame( wp_filesize( get_attached_file( $attachment ) ), $metadata['filesize'] ); 31 30 32 foreach ( $metadata['sizes'] as $ size => $intermediate_size ) {31 foreach ( $metadata['sizes'] as $intermediate_size ) { 33 32 $this->assertArrayHasKey( 'filesize', $intermediate_size ); 34 33 $this->assertNotEmpty( $intermediate_size['filesize'] ); 35 34 $this->assertIsNumeric( $intermediate_size['filesize'] ); 36 $this->assertStringContainsString( $intermediate_size['file'], get_attached_file( $attachment, false, $size ) );37 35 } 38 36 }
Note: See TracChangeset
for help on using the changeset viewer.