wp_get_original_image_path( int $attachment_id, bool $unfiltered = false ): string|false
- Since
- 5.3.0, 5.4.0
- Source
wp-includes/post.php:8461
Retrieves the path to an uploaded image file.
Description
Similar to
get_attached_file() however some images may have been processed after uploading to make them suitable for web use. In this case the attached "full" size file is usually replaced with a scaled down version of the original image. This function always returns the path to the originally uploaded image file.Parameters
$attachment_idint- Attachment ID.
$unfilteredbooloptional- Passed through to
get_attached_file(). Default false.Default:false
Return
string|false- Path to the original image file or false if the attachment is not an image.
Hooks fired · 1
One hook fires while wp_get_original_image_path() runs, in this order:
- apply_filters( wp_get_original_image_path )filterline 8483 (+22 into the body)
Filters the path to the original image.
Uses · 5
- wp_attachment_is_image()Determines whether an attachment is an image.
- wp_get_attachment_metadata()Retrieves attachment metadata for attachment ID.
- get_attached_file()Retrieves attached file path based on attachment ID.
- path_join()Joins two filesystem paths together.
- apply_filters()Calls the callback functions that have been added to a filter hook.
Used by · 5
- WP_REST_Attachments_Controller::edit_media_item()Applies edits to a media item and creates a new attachment record.
- attachment_submitbox_metadata()Displays non-editable attachment metadata in the publish meta box.
- wp_get_missing_image_subsizes()Compare the existing image sub-sizes (as saved in the attachment meta) to the currently registered image sub-sizes, and return the difference.
- wp_prepare_attachment_for_js()Prepares an attachment post object for JS, where it is expected to be JSON-encoded and fit into an Attachment model.
- wp_update_image_subsizes()If any of the currently registered image sub-sizes are missing, create them and update the image meta data.
Source
function wp_get_original_image_path( $attachment_id, $unfiltered = false ) { if ( ! wp_attachment_is_image( $attachment_id ) ) { return false; } $image_meta = wp_get_attachment_metadata( $attachment_id ); $image_file = get_attached_file( $attachment_id, $unfiltered ); if ( empty( $image_meta['original_image'] ) ) { $original_image = $image_file; } else { $original_image = path_join( dirname( $image_file ), $image_meta['original_image'] ); } /** * Filters the path to the original image. * * @since 5.3.0 * * @param string $original_image Path to original image file. * @param int $attachment_id Attachment ID. */ return apply_filters( 'wp_get_original_image_path', $original_image, $attachment_id );}History
Introduced in 5.3.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
5.4.0
Added the
$unfiltered parameter.from the docblock5.3.0
Introduced.from the docblock
About this page
- Parsed data
- Generated from the wordpress-develop 6.9.7 tag, from
src/wp-includes/post.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.