Make WordPress Core

Changeset 46353


Ignore:
Timestamp:
09/30/2019 04:27:11 PM (5 years ago)
Author:
azaozz
Message:

Media: Move wp_get_original_image_path() to wp-content/post.php to make it easier to access from plugins.

Props pbiron.
See #47873.

Location:
trunk/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/image.php

    r46217 r46353  
    10351035    return $dst_file;
    10361036}
    1037 
    1038 /**
    1039  * Retrieves the path to an uploaded image.
    1040  *
    1041  * Similar to `get_attached_file()` however some images may have been
    1042  * processed after uploading to make them "web ready".
    1043  * In this case this function returns the path to the originally uploaded image file.
    1044  *
    1045  * @since 5.3.0
    1046  *
    1047  * @param int $attachment_id Attachment ID.
    1048  * @return string|false Path to the original image file or false if the attachment is not an image.
    1049  */
    1050 function wp_get_original_image_path( $attachment_id ) {
    1051     if ( ! wp_attachment_is_image( $attachment_id ) ) {
    1052         return false;
    1053     }
    1054 
    1055     $image_meta = wp_get_attachment_metadata( $attachment_id );
    1056     $image_file = get_attached_file( $attachment_id );
    1057 
    1058     if ( empty( $image_meta['original_image'] ) ) {
    1059         $original_image = $image_file;
    1060     } else {
    1061         $original_image = path_join( dirname( $image_file ), $image_meta['original_image'] );
    1062     }
    1063 
    1064     /**
    1065      * Filters the path to the original image.
    1066      *
    1067      * @since 5.3.0
    1068      *
    1069      * @param string $original_image Path to original image file.
    1070      * @param int    $attachment_id  Attachment ID.
    1071      */
    1072     return apply_filters( 'wp_get_original_image_path', $original_image, $attachment_id );
    1073 }
  • trunk/src/wp-includes/post.php

    r46288 r46353  
    71417141    return $types;
    71427142}
     7143
     7144/**
     7145 * Retrieves the path to an uploaded image file.
     7146 *
     7147 * Similar to `get_attached_file()` however some images may have been processed after uploading
     7148 * to make them suitable for web use. In this case the attached "full" size file is usually replaced
     7149 * with a scaled down version of the original image. This function always returns the path
     7150 * to the originally uploaded image file.
     7151 *
     7152 * @since 5.3.0
     7153 *
     7154 * @param int $attachment_id Attachment ID.
     7155 * @return string|false Path to the original image file or false if the attachment is not an image.
     7156 */
     7157function wp_get_original_image_path( $attachment_id ) {
     7158    if ( ! wp_attachment_is_image( $attachment_id ) ) {
     7159        return false;
     7160    }
     7161
     7162    $image_meta = wp_get_attachment_metadata( $attachment_id );
     7163    $image_file = get_attached_file( $attachment_id );
     7164
     7165    if ( empty( $image_meta['original_image'] ) ) {
     7166        $original_image = $image_file;
     7167    } else {
     7168        $original_image = path_join( dirname( $image_file ), $image_meta['original_image'] );
     7169    }
     7170
     7171    /**
     7172     * Filters the path to the original image.
     7173     *
     7174     * @since 5.3.0
     7175     *
     7176     * @param string $original_image Path to original image file.
     7177     * @param int    $attachment_id  Attachment ID.
     7178     */
     7179    return apply_filters( 'wp_get_original_image_path', $original_image, $attachment_id );
     7180}
Note: See TracChangeset for help on using the changeset viewer.