wp_get_original_image_path() WordPress Function

The wp_get_original_image_path() function returns the path to the original image file.

wp_get_original_image_path( int $attachment_id, bool $unfiltered = false ) #

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.


Top ↑

Parameters

$attachment_id

(int)(Required)Attachment ID.

$unfiltered

(bool)(Optional) Passed through to get_attached_file().

Default value: false


Top ↑

Return

(string|false) Path to the original image file or false if the attachment is not an image.


Top ↑

Source

File: wp-includes/post.php

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 );
}


Top ↑

Changelog

Changelog
VersionDescription
5.4.0Added the $unfiltered parameter.
5.3.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.

Show More
Show More