Make WordPress Core

Ticket #17262: 17262.7.diff

File 17262.7.diff, 1.6 KB (added by mashukushibiki, 5 years ago)

I modified my previous attachment. I also have not tested this code yet.

Line 
1Index: src/wp-includes/media.php
2===================================================================
3--- a/src/wp-includes/media.php
4+++ b/src/wp-includes/media.php
5@@ -946,6 +946,40 @@ function wp_get_attachment_image_url( $attachment_id, $size = 'thumbnail', $icon
6         return isset( $image['0'] ) ? $image['0'] : false;
7 }
8 
9/**
10 * Get the path of an image attachment.
11 *
12 * @since X.X.X
13 *
14 * @param int                            $attachment_id Image attachment ID.
15 * @param string|array $size                                    Optional. Image size to retrieve. Accepts any valid image size, or an array
16 *                                    of width and height values in pixels (in that order). Default 'thumbnail'.
17 * @return string|false Attachment path or false if no image is available.
18 */
19function wp_get_attachment_image_file( $attachment_id, $size = 'thumbnail' ) {
20
21        // get the file array
22-        $file = wp_get_attachment_metadata( attachment_id );
23+        $file = wp_get_attachment_metadata( $attachment_id );
24        if ( $file ) {
25
26                // get file name
27                $file_name = isset ( $file[ 'sizes' ][ $size ][ 'file' ] ) ? $file[ 'sizes' ][ $size ][ 'file' ] : false;
28
29                // get file path
30                $file_path = _wp_get_attachment_relative_path( $file_name );
31
32                // return path
33                if ( ! empty( $file_path) ) {
34
35                        $path = ABSPATH . '/wp-content/uploads/' . trailingslashit( $file_path ) . $file_name;
36                        return $path;
37                }
38        }
39
40        return false;
41}
42
43/**
44 * Get the attachment path relative to the upload directory.
45 *