Skip to content

Commit 37456c9

Browse files
Script Loader: Check if $_wp_admin_css_colors is set in wp_style_loader_src().
This aims to avoid PHP warnings if the `colors` dependency is loaded or the `style_loader_src` filter is used in a context where the `$_wp_admin_css_colors` global does not exist. Follow-up to [7976]. Props crstauf, petitphp, SergeyBiryukov. Fixes #61302. git-svn-id: https://develop.svn.wordpress.org/trunk@61388 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 2ae6561 commit 37456c9

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

src/wp-includes/script-loader.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2090,8 +2090,8 @@ function wp_style_loader_src( $src, $handle ) {
20902090
$color = 'fresh';
20912091
}
20922092

2093-
$color = $_wp_admin_css_colors[ $color ];
2094-
$url = $color->url;
2093+
$color = $_wp_admin_css_colors[ $color ] ?? null;
2094+
$url = $color->url ?? '';
20952095

20962096
if ( ! $url ) {
20972097
return false;
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
/**
4+
* Test wp_style_loader_src().
5+
*
6+
* @group dependencies
7+
* @group scripts
8+
*
9+
* @covers ::wp_style_loader_src
10+
*/
11+
class Tests_Dependencies_wpStyleLoaderSrc extends WP_UnitTestCase {
12+
13+
/**
14+
* Tests that PHP warnings are not thrown when wp_style_loader_src() is called
15+
* before the `$_wp_admin_css_colors` global is set.
16+
*
17+
* The warnings that we should not see:
18+
* `Warning: Trying to access array offset on null`.
19+
* `Warning: Attempt to read property "url" on null`.
20+
*
21+
* @ticket 61302
22+
*/
23+
public function test_without_wp_admin_css_colors_global() {
24+
$this->assertFalse( wp_style_loader_src( '', 'colors' ) );
25+
}
26+
}

0 commit comments

Comments
 (0)