Skip to content

Commit 7529b4d

Browse files
committed
WP.EnqueuedResources: bug fix
Identified by joyously in the ThemeReviewCS repo: WPTRT/WPThemeReview 202 When inline JQuery is used to reference a stylesheet link tag, the sniff misidentifies this as a stylesheet which needs to be enqueued. This very simple fix should prevent that, at least for the reported cases. Includes unit test.
1 parent e41ea6a commit 7529b4d

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

WordPress/Sniffs/WP/EnqueuedResourcesSniff.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function register() {
4444
public function process_token( $stackPtr ) {
4545
$token = $this->tokens[ $stackPtr ];
4646

47-
if ( preg_match( '#rel=\\\\?[\'"]?stylesheet\\\\?[\'"]?#', $token['content'] ) > 0 ) {
47+
if ( preg_match( '# rel=\\\\?[\'"]?stylesheet\\\\?[\'"]?#', $token['content'] ) > 0 ) {
4848
$this->phpcsFile->addError(
4949
'Stylesheets must be registered/enqueued via wp_enqueue_style',
5050
$stackPtr,

WordPress/Tests/WP/EnqueuedResourcesUnitTest.inc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,9 @@ $head = <<<'EOD'
3030
<link rel="stylesheet" href="http://someurl/somefile.css">
3131
<script src="http://someurl/somefile.js"></script>
3232
EOD;
33+
34+
?>
35+
36+
jQuery( document ).ready( function() {
37+
$('link[rel="stylesheet"]:not([data-inprogress])').forEach(StyleFix.link);
38+
});

0 commit comments

Comments
 (0)