Make WordPress Core

Changeset 53027

Timestamp:
03/29/2022 09:46:09 PM (2 years ago)
Author:
joedolson
Message:

Media: Preserve attachment properties on cropping custom logo.

Migrate the alternative text, title, description, and caption of an image over to the cropped copy of the image after cropping. Ensure that characteristics added to an image prior to cropping are not lost.

Props flixos90, Clorith, afercia, antonvlasenko, ironprogrammer, hellofromTonya.
Fixes #37750.

Location:
trunk
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/ajax-actions.php

    r52978 r53027  
    39713971            $cropped = apply_filters( 'wp_create_file_in_uploads', $cropped, $attachment_id ); // For replication.
    39723972
    3973             $parent_url = wp_get_attachment_url( $attachment_id );
    3974             $url        = str_replace( wp_basename( $parent_url ), wp_basename( $cropped ), $parent_url );
     3973            $parent_url      = wp_get_attachment_url( $attachment_id );
     3974            $parent_basename = wp_basename( $parent_url );
     3975            $url             = str_replace( $parent_basename, wp_basename( $cropped ), $parent_url );
    39753976
    39763977            $size       = wp_getimagesize( $cropped );
    39773978            $image_type = ( $size ) ? $size['mime'] : 'image/jpeg';
    39783979
     3980
     3981
     3982
     3983
     3984
     3985
     3986
     3987
     3988
     3989
     3990
     3991
     3992
     3993
    39793994            $object = array(
    3980                 'post_title'     => wp_basename( $cropped ),
    3981                 'post_content'   => $url,
     3995                'post_title'     => wp_basename( $cropped ),
     3996                'post_content'   => $url,
    39823997                'post_mime_type' => $image_type,
    39833998                'guid'           => $url,
    39843999                'context'        => $context,
    39854000            );
     4001
     4002
     4003
     4004
     4005
     4006
     4007
     4008
     4009
     4010
     4011
     4012
    39864013
    39874014            $attachment_id = wp_insert_attachment( $object, $cropped );
Note: See TracChangeset for help on using the changeset viewer.