WordPress.org

Make WordPress Core

Ticket #48302: 48302.2.diff

File 48302.2.diff, 1.5 KB (added by kraftbj, 21 months ago)

Adds check to confirm we have an attachment URL.

  • src/wp-includes/media.php

    diff --git src/wp-includes/media.php src/wp-includes/media.php
    index 002581e174..c359e079ff 100644
    function _wp_add_additional_image_sizes() { 
    43864386        // 2x large size
    43874387        add_image_size( '2048x2048', 2048, 2048 );
    43884388}
     4389
     4390/**
     4391 * Retrieves the URL for an original image.
     4392 *
     4393 * WordPress Big Image processing will limit the scale of a large image by default. This function returns the absolute
     4394 * original image, not the scaled one.
     4395 *
     4396 * @since 5.3.0
     4397 *
     4398 * @param int $attachment_id Attachment ID.
     4399 * @return string|false Path to the original image file or false if the attachment is not an image.
     4400 */
     4401function wp_get_attachment_original_image_url( $attachment_id ) {
     4402        if ( ! wp_attachment_is_image( $attachment_id ) ) {
     4403                return false;
     4404        }
     4405
     4406        $image_url = wp_get_attachment_image_url( $attachment_id, 'full' );
     4407
     4408        if ( empty( $image_url ) ) {
     4409                return false;
     4410        }
     4411
     4412        $image_meta = wp_get_attachment_metadata( $attachment_id );
     4413
     4414
     4415        if ( empty( $image_meta['original_image'] ) ) {
     4416                $original_image = $image_url;
     4417        } else {
     4418                $original_image = path_join( dirname( $image_url ), $image_meta['original_image'] );
     4419        }
     4420
     4421        /**
     4422         * Filters the URL to the original image.
     4423         *
     4424         * @since 5.3.0
     4425         *
     4426         * @param string $original_image URL to original image file.
     4427         * @param int    $attachment_id  Attachment ID.
     4428         */
     4429        return apply_filters( 'wp_get_attachment_original_url', $original_image, $attachment_id );
     4430}