On this page
wp_get_original_image_url( int $attachment_id ): string|false
Retrieves the URL to an original attachment image.
Description
Similar to wp_get_attachment_url() however some images may have been processed after uploading. In this case this function returns the URL to the originally uploaded image file.
Parameters
$attachment_idint Required-
Attachment post ID.
Return
string|false Attachment image URL, false on error or if the attachment is not an image.
Source
File: wp-includes/post.php. View all references
function wp_get_original_image_url( $attachment_id ) {
if ( ! wp_attachment_is_image( $attachment_id ) ) {
return false;
}
$image_url = wp_get_attachment_url( $attachment_id );
if ( ! $image_url ) {
return false;
}
$image_meta = wp_get_attachment_metadata( $attachment_id );
if ( empty( $image_meta['original_image'] ) ) {
$original_image_url = $image_url;
} else {
$original_image_url = path_join( dirname( $image_url ), $image_meta['original_image'] );
}
/**
* Filters the URL to the original attachment image.
*
* @since 5.3.0
*
* @param string $original_image_url URL to original image.
* @param int $attachment_id Attachment ID.
*/
return apply_filters( 'wp_get_original_image_url', $original_image_url, $attachment_id );
}
Hooks
- apply_filters( 'wp_get_original_image_url',
string $original_image_url ,int $attachment_id ) -
Filters the URL to the original attachment image.
Related
Uses
| Uses | Description |
|---|---|
| path_join() wp-includes/functions.php | Joins two filesystem paths together. |
| wp_attachment_is_image() wp-includes/post.php | Determines whether an attachment is an image. |
| wp_get_attachment_url() wp-includes/post.php | Retrieves the URL for an attachment. |
| wp_get_attachment_metadata() wp-includes/post.php | Retrieves attachment metadata for attachment ID. |
| apply_filters() wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook. |
Used By
| Used By | Description |
|---|---|
| attachment_submitbox_metadata() wp-admin/includes/media.php | Displays non-editable attachment metadata in the publish meta box. |
| wp_prepare_attachment_for_js() wp-includes/media.php | Prepares an attachment post object for JS, where it is expected to be JSON-encoded and fit into an Attachment model. |
Changelog
| Version | Description |
|---|---|
| 5.3.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/wp_get_original_image_url