Make WordPress Core


Ignore:
Timestamp:
07/20/2022 09:11:30 PM (4 years ago)
Author:
audrasjb
Message:

Themes: Add a hook to filter theme header image URL.

This changeset introduces the get_header_image filter, which can be used to modify header image URL returned by get_header_image(), in themes that support the Header Image feature.

Props hztyfoon, audrasjb, mukesh27, SergeyBiryukov, costdev.
Fixes #56180.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/theme/customHeader.php

    r52010 r53741  
    8080        $this->assertFalse( has_header_image() );
    8181        $this->assertFalse( $image );
     82    }
     83
     84    /**
     85     * Tests the "get_header_image" filter.
     86     *
     87     * @ticket 56180
     88     *
     89     * @covers get_header_image
     90     *
     91     * @dataProvider data_filter_header_image
     92     *
     93     * @param mixed  $header_image The header image.
     94     * @param string $expected     The expected return value from get_header_image().
     95     */
     96    public function test_filter_header_image( $header_image, $expected ) {
     97        add_filter(
     98            'get_header_image',
     99            static function() use ( $header_image ) {
     100                return $header_image;
     101            }
     102        );
     103
     104        $this->assertSame( $expected, get_header_image() );
     105    }
     106
     107    /**
     108     * Data provider.
     109     *
     110     * @return array
     111     */
     112    public function data_filter_header_image() {
     113        return array(
     114            'an image url'         => array(
     115                'header_image' => 'http://example.org/image.png',
     116                'expected'     => 'http://example.org/image.png',
     117            ),
     118            'an empty string'      => array(
     119                'header_image' => '',
     120                'expected'     => '',
     121            ),
     122            'a string with spaces' => array(
     123                'header_image' => ' ',
     124                'expected'     => '',
     125            ),
     126            'null'                 => array(
     127                'header_image' => null,
     128                'expected'     => false,
     129            ),
     130            'false'                => array(
     131                'header_image' => false,
     132                'expected'     => false,
     133            ),
     134        );
    82135    }
    83136
Note: See TracChangeset for help on using the changeset viewer.