Make WordPress Core


Ignore:
Timestamp:
03/02/2024 08:13:02 PM (4 months ago)
Author:
joedolson
Message:

Media: Accessibility: Copy attachment properties on site icon crop.

Add parity between site icon, custom header, and default image crop behaviors. [53027] fixed a bug where alt text and caption were not copied on custom headers, but did not apply that change in any other context.

Deprecate the create_attachment_object method in the Wp_Site_Icon and Custom_Image_Header classes and replace that functionality with the new function wp_copy_parent_attachment_properties() to improve consistency.

Props afercia, rcreators, jorbin, joedolson, huzaifaalmesbah, shailu25, swissspidy, mukesh27.
Fixes #60524.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/image/header.php

    r56548 r57755  
    109109    }
    110110
    111     public function test_create_attachment_object() {
    112         $id = wp_insert_attachment(
    113             array(
    114                 'post_status' => 'publish',
    115                 'post_title'  => 'foo.png',
    116                 'post_type'   => 'post',
    117                 'guid'        => 'http://localhost/foo.png',
    118             )
    119         );
    120 
    121         $cropped = 'foo-cropped.png';
    122 
    123         $object = $this->custom_image_header->create_attachment_object( $cropped, $id );
    124         $this->assertSame( 'foo-cropped.png', $object['post_title'] );
    125         $this->assertSame( 'http://localhost/' . $cropped, $object['guid'] );
    126         $this->assertSame( 'custom-header', $object['context'] );
    127         $this->assertSame( 'image/jpeg', $object['post_mime_type'] );
    128     }
    129 
    130111    public function test_insert_cropped_attachment() {
    131112        $id = wp_insert_attachment(
     
    139120
    140121        $cropped = 'foo-cropped.png';
    141         $object  = $this->custom_image_header->create_attachment_object( $cropped, $id );
     122        $object  = wp_copy_parent_attachment_properties( $cropped, $id, 'custom-header' );
    142123
    143124        $cropped_id = $this->custom_image_header->insert_attachment( $object, $cropped );
     
    162143        // Create inital crop object.
    163144        $cropped_1 = 'foo-cropped-1.png';
    164         $object    = $this->custom_image_header->create_attachment_object( $cropped_1, $id );
     145        $object    = wp_copy_parent_attachment_properties( $cropped_1, $id, 'custom-header' );
    165146
    166147        // Ensure no previous crop exists.
     
    176157        // Create second crop.
    177158        $cropped_2 = 'foo-cropped-2.png';
    178         $object    = $this->custom_image_header->create_attachment_object( $cropped_2, $id );
     159        $object    = wp_copy_parent_attachment_properties( $cropped_2, $id );
    179160
    180161        // Test that a previous crop is found.
Note: See TracChangeset for help on using the changeset viewer.