Alert: This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness.

_load_image_to_edit_path() WordPress Function

The load_image_to_edit_path() function loads an image to be edited in the WordPress media editor. This function is typically used when a user clicks on an image in the media library to edit it.

_load_image_to_edit_path( int $attachment_id, string|int[] $size = 'full' ) #

Retrieve the path or URL of an attachment’s attached file.


Description

If the attached file is not present on the local filesystem (usually due to replication plugins), then the URL of the file is returned if allow_url_fopen is supported.


Top ↑

Parameters

$attachment_id

(int)(Required)Attachment ID.

$size

(string|int[])(Optional) Image size. Accepts any registered image size name, or an array of width and height values in pixels (in that order).

Default value: 'full'


Top ↑

Return

(string|false) File path or URL on success, false on failure.


Top ↑

Source

File: wp-admin/includes/image.php

1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
function _load_image_to_edit_path( $attachment_id, $size = 'full' ) {
    $filepath = get_attached_file( $attachment_id );
 
    if ( $filepath && file_exists( $filepath ) ) {
        if ( 'full' !== $size ) {
            $data = image_get_intermediate_size( $attachment_id, $size );
 
            if ( $data ) {
                $filepath = path_join( dirname( $filepath ), $data['file'] );
 
                /**
                 * Filters the path to an attachment's file when editing the image.
                 *
                 * The filter is evaluated for all image sizes except 'full'.
                 *
                 * @since 3.1.0
                 *
                 * @param string       $path          Path to the current image.
                 * @param int          $attachment_id Attachment ID.
                 * @param string|int[] $size          Requested image size. Can be any registered image size name, or
                 *                                    an array of width and height values in pixels (in that order).
                 */
                $filepath = apply_filters( 'load_image_to_edit_filesystempath', $filepath, $attachment_id, $size );
            }
        }
    } elseif ( function_exists( 'fopen' ) && ini_get( 'allow_url_fopen' ) ) {
        /**
         * Filters the path to an attachment's URL when editing the image.
         *
         * The filter is only evaluated if the file isn't stored locally and `allow_url_fopen` is enabled on the server.
         *
         * @since 3.1.0
         *
         * @param string|false $image_url     Current image URL.
         * @param int          $attachment_id Attachment ID.
         * @param string|int[] $size          Requested image size. Can be any registered image size name, or
         *                                    an array of width and height values in pixels (in that order).
         */
        $filepath = apply_filters( 'load_image_to_edit_attachmenturl', wp_get_attachment_url( $attachment_id ), $attachment_id, $size );
    }
 
    /**
     * Filters the returned path or URL of the current image.
     *
     * @since 2.9.0
     *
     * @param string|false $filepath      File path or URL to current image, or false.
     * @param int          $attachment_id Attachment ID.
     * @param string|int[] $size          Requested image size. Can be any registered image size name, or
     *                                    an array of width and height values in pixels (in that order).
     */
    return apply_filters( 'load_image_to_edit_path', $filepath, $attachment_id, $size );
}


Top ↑

Changelog

Changelog
VersionDescription
3.4.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by the Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.