WordPress.org

Make WordPress Core


Ignore:
Timestamp:
09/30/2019 04:27:11 PM (7 weeks 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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.