mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2025-10-16 12:05:38 +00:00
Media: Revert the addition of a $size parameter to get_attached_file().
Reverts [55199], [55202], and [55217] but keeps the updated docs. Props: flixos90, joedolson, azaozz. Fixes: #51780. git-svn-id: https://develop.svn.wordpress.org/trunk@55437 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
5ce8b1f9ed
commit
0bbf09f496
@ -705,8 +705,6 @@ function create_initial_post_types() {
|
||||
/**
|
||||
* Retrieves attached file path based on attachment ID.
|
||||
*
|
||||
* Will return intermediate size path if the `$size` parameter is provided.
|
||||
*
|
||||
* By default the path will go through the {@see 'get_attached_file'} filter, but
|
||||
* passing `true` to the `$unfiltered` argument will return the file path unfiltered.
|
||||
*
|
||||
@ -715,28 +713,14 @@ function create_initial_post_types() {
|
||||
* a mechanism for sending the attached filename through a filter.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @since 6.2.0 The `$size` parameter was added.
|
||||
*
|
||||
* @param int $attachment_id Attachment ID.
|
||||
* @param bool $unfiltered Optional. Whether to skip the {@see 'get_attached_file'} filter.
|
||||
* Default false.
|
||||
* @param string|int[] $size Optional. Image size. Accepts any registered image size name, or an array
|
||||
* of width and height values in pixels (in that order). Default empty string.
|
||||
* @param int $attachment_id Attachment ID.
|
||||
* @param bool $unfiltered Optional. Whether to skip the {@see 'get_attached_file'} filter.
|
||||
* Default false.
|
||||
* @return string|false The file path to where the attached file should be, false otherwise.
|
||||
*/
|
||||
function get_attached_file( $attachment_id, $unfiltered = false, $size = '' ) {
|
||||
|
||||
// Check for intermediate sizes first, otherwise fall back to the original attachment size.
|
||||
if ( ! empty( $size ) ) {
|
||||
$intermediate_image = image_get_intermediate_size( $attachment_id, $size );
|
||||
if ( ! $intermediate_image || ! isset( $intermediate_image['path'] ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$file = $intermediate_image['path'];
|
||||
} else {
|
||||
$file = get_post_meta( $attachment_id, '_wp_attached_file', true );
|
||||
}
|
||||
function get_attached_file( $attachment_id, $unfiltered = false ) {
|
||||
$file = get_post_meta( $attachment_id, '_wp_attached_file', true );
|
||||
|
||||
// If the file is relative, prepend upload dir.
|
||||
if ( $file && 0 !== strpos( $file, '/' ) && ! preg_match( '|^.:\\\|', $file ) ) {
|
||||
@ -754,14 +738,11 @@ function get_attached_file( $attachment_id, $unfiltered = false, $size = '' ) {
|
||||
* Filters the attached file based on the given ID.
|
||||
*
|
||||
* @since 2.1.0
|
||||
* @since 6.2.0 The `$size` parameter was added.
|
||||
*
|
||||
* @param string|false $file The file path to where the attached file should be, false otherwise.
|
||||
* @param int $attachment_id Attachment ID.
|
||||
* @param string|int[] $size Optional. Image size. Accepts any registered image size name, or an array
|
||||
* of width and height values in pixels (in that order). Default empty string.
|
||||
*/
|
||||
return apply_filters( 'get_attached_file', $file, $attachment_id, $size );
|
||||
return apply_filters( 'get_attached_file', $file, $attachment_id );
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -18,7 +18,6 @@ class Tests_Media_wpGenerateAttachmentMetadata extends WP_UnitTestCase {
|
||||
* Tests that filesize meta is generated for JPEGs.
|
||||
*
|
||||
* @ticket 49412
|
||||
* @ticket 51780
|
||||
*
|
||||
* @covers ::wp_create_image_subsizes
|
||||
*/
|
||||
@ -29,11 +28,10 @@ class Tests_Media_wpGenerateAttachmentMetadata extends WP_UnitTestCase {
|
||||
|
||||
$this->assertSame( wp_filesize( get_attached_file( $attachment ) ), $metadata['filesize'] );
|
||||
|
||||
foreach ( $metadata['sizes'] as $size => $intermediate_size ) {
|
||||
foreach ( $metadata['sizes'] as $intermediate_size ) {
|
||||
$this->assertArrayHasKey( 'filesize', $intermediate_size );
|
||||
$this->assertNotEmpty( $intermediate_size['filesize'] );
|
||||
$this->assertIsNumeric( $intermediate_size['filesize'] );
|
||||
$this->assertStringContainsString( $intermediate_size['file'], get_attached_file( $attachment, false, $size ) );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user