Make WordPress Core


Ignore:
Timestamp:
03/29/2022 11:56:18 PM (2 years ago)
Author:
flixos90
Message:

Media: Introduce wp_content_img_tag filter.

This filter allows modifying individual img tags within a blob of content that are by default processed by the wp_filter_content_tags() function. The addition of this filter facilitates plugins that tweak images to accomplish this goal without re-implementing duplicate content image parser logic, which furthermore can have a negative performance impact due to additional regular expressions.

In addition to the filterable img tag, the filter receives the context (typically the function or filter in which the content is parsed) and the attachment ID. The latter may be 0, in case the image is not an attachment (for example when it is an external image URL).

Props adamsilverstein, flixos90, pbearne, peterwilsoncc.
Fixes #55347.

File:
1 edited

Legend:

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

    r52190 r53028  
    22952295
    22962296    /**
     2297     * @ticket 55347
     2298     */
     2299    public function test_wp_filter_content_tags_has_filter() {
     2300        $filter = new MockAction();
     2301        add_filter( 'wp_content_img_tag', array( &$filter, 'filter' ) );
     2302        $img_tag_1 = get_image_tag( self::$large_id, '', '', '', 'medium' );
     2303
     2304        wp_filter_content_tags( $img_tag_1 );
     2305        $this->assertSame( 1, $filter->get_call_count() );
     2306    }
     2307    /**
    22972308     * @ticket 33641
    22982309     * @ticket 34528
Note: See TracChangeset for help on using the changeset viewer.