diff --git a/src/wp-includes/theme.php b/src/wp-includes/theme.php
index c3d5003f75..76cc489b2e 100644
|
a
|
b
|
function get_header_image() { |
| 1179 | 1179 | $url = get_random_header_image(); |
| 1180 | 1180 | } |
| 1181 | 1181 | |
| | 1182 | /** |
| | 1183 | * Filters the header image URL. |
| | 1184 | * |
| | 1185 | * @since 6.1.0 |
| | 1186 | * |
| | 1187 | * @param string $url Header image URL. |
| | 1188 | */ |
| | 1189 | $url = apply_filters( 'header_image', $url ); |
| | 1190 | |
| | 1191 | if ( ! is_string( $url ) ) { |
| | 1192 | return false; |
| | 1193 | } |
| | 1194 | |
| | 1195 | $url = trim( $url ); |
| | 1196 | |
| 1182 | 1197 | return sanitize_url( set_url_scheme( $url ) ); |
| 1183 | 1198 | } |
| 1184 | 1199 | |
diff --git a/tests/phpunit/tests/theme/customHeader.php b/tests/phpunit/tests/theme/customHeader.php
index 958462afef..0b4b0d4f56 100644
|
a
|
b
|
class Tests_Theme_CustomHeader extends WP_UnitTestCase { |
| 119 | 119 | $this->assertStringContainsString( sprintf( 'src="%s"', $custom ), $html ); |
| 120 | 120 | } |
| 121 | 121 | |
| | 122 | /** |
| | 123 | * Tests the "header_image" filter. |
| | 124 | * |
| | 125 | * @ticket 56180 |
| | 126 | * |
| | 127 | * @covers get_header_image |
| | 128 | * |
| | 129 | * @dataProvider data_filter_header_image |
| | 130 | * |
| | 131 | * @param mixed $header_image The header image. |
| | 132 | * @param string $expected The expected return value from get_header_image(). |
| | 133 | */ |
| | 134 | public function test_filter_header_image( $header_image, $expected ) { |
| | 135 | add_filter( |
| | 136 | 'header_image', |
| | 137 | static function() use ( $header_image ) { |
| | 138 | return $header_image; |
| | 139 | } |
| | 140 | ); |
| | 141 | |
| | 142 | $this->assertSame( $expected, get_header_image() ); |
| | 143 | } |
| | 144 | |
| | 145 | /** |
| | 146 | * Data provider. |
| | 147 | * |
| | 148 | * @return array |
| | 149 | */ |
| | 150 | public function data_filter_header_image() { |
| | 151 | return array( |
| | 152 | 'an image url' => array( |
| | 153 | 'header_image' => 'http://example.org/image.png', |
| | 154 | 'expected' => 'http://example.org/image.png', |
| | 155 | ), |
| | 156 | 'an empty string' => array( |
| | 157 | 'header_image' => '', |
| | 158 | 'expected' => '', |
| | 159 | ), |
| | 160 | 'a string with spaces' => array( |
| | 161 | 'header_image' => ' ', |
| | 162 | 'expected' => '', |
| | 163 | ), |
| | 164 | 'null' => array( |
| | 165 | 'header_image' => null, |
| | 166 | 'expected' => false, |
| | 167 | ), |
| | 168 | 'false' => array( |
| | 169 | 'header_image' => false, |
| | 170 | 'expected' => false, |
| | 171 | ), |
| | 172 | ); |
| | 173 | } |
| | 174 | |
| 122 | 175 | public function test_get_custom_header_markup_without_registered_default_image() { |
| 123 | 176 | $this->add_theme_support(); |
| 124 | 177 | |