Make WordPress Core


Ignore:
Timestamp:
10/20/2020 03:29:42 PM (4 years ago)
Author:
SergeyBiryukov
Message:

Media: Introduce a filter for wp_get_attachment_image() HTML output.

Props prionkor, antpb, donmhico, audrasjb, Mista-Flo, hellofromTonya.
Fixes #50801.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/media.php

    r49193 r49234  
    13421342
    13431343        $this->assertSame( $expected, wp_get_attachment_image( self::$large_id ) );
     1344    }
     1345
     1346    /**
     1347     * @ticket 50801
     1348     */
     1349    function test_wp_get_attachment_image_filter_output() {
     1350        $image    = image_downsize( self::$large_id, 'thumbnail' );
     1351        $expected = 'Override wp_get_attachment_image';
     1352
     1353        add_filter( 'wp_get_attachment_image', array( $this, 'filter_wp_get_attachment_image' ) );
     1354        $output = wp_get_attachment_image( self::$large_id );
     1355        remove_filter( 'wp_get_attachment_image', array( $this, 'filter_wp_get_attachment_image' ) );
     1356
     1357        $this->assertSame( $expected, $output );
     1358    }
     1359
     1360    function filter_wp_get_attachment_image() {
     1361        return 'Override wp_get_attachment_image';
    13441362    }
    13451363
Note: See TracChangeset for help on using the changeset viewer.