-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PrefixAllGlobals: refactor the template file name recognition
As it turns out that the regex in the FileName sniff, while good for inspiration, is not actually suitable to be used here directly, we need to solve the template file name recognition within this sniff. To that end and based on the Theme Handbook, I have: * Added a `$simple_theme_template_file_names` property with the simple plain file names as per the handbook. * Added a `COMPLEX_THEME_TEMPLATE_NAME_REGEX` constant with a regex to facilitate recognizing more complex template file names. * Added the `page-templates` folder name to the list of `$allowed_folders` in the ruleset. See: https://developer.wordpress.org/themes/template-files-section/page-template-files/#file-organization-of-page-templates * Adjusted the logic in the overloaded method to use the new property and constant. * Adjusted the unit tests to match. * Added an additional unit test with a file in a subdirectory of an allowed folder. * Added an additional unit test case file to cover the regex. Note: similar to the WPCS FileNameSniff, this sniff does not currently allow for mimetype sublevel only file names, such as `plain.php`.
- Loading branch information
Showing
7 changed files
with
117 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
WPThemeReview/Tests/CoreFunctionality/PrefixAllGlobalsTests/page-recent-news.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// phpcs:set WPThemeReview.CoreFunctionality.PrefixAllGlobals prefixes[] my_theme | ||
<?php | ||
|
||
$my_theme_var = 123; // OK, prefixed. | ||
$var = 'Value'; // OK, template file. | ||
|
||
// phpcs:set WPThemeReview.CoreFunctionality.PrefixAllGlobals prefixes[] |
8 changes: 8 additions & 0 deletions
8
...Tests/CoreFunctionality/PrefixAllGlobalsTests/page-templates/layouts/page_two-columns.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// phpcs:set WPThemeReview.CoreFunctionality.PrefixAllGlobals prefixes[] my_theme | ||
// phpcs:set WPThemeReview.CoreFunctionality.PrefixAllGlobals allowed_folders[] template-parts,templates,partials,page-templates | ||
<?php | ||
$my_theme_var = 123; // OK, prefixed. | ||
$var = 'Value'; // OK, file in allowed folder. | ||
|
||
// phpcs:set WPThemeReview.CoreFunctionality.PrefixAllGlobals prefixes[] | ||
// phpcs:set WPThemeReview.CoreFunctionality.PrefixAllGlobals allowed_folders[] |
4 changes: 2 additions & 2 deletions
4
WPThemeReview/Tests/CoreFunctionality/PrefixAllGlobalsTests/partials/post-edit.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
// phpcs:set WPThemeReview.CoreFunctionality.PrefixAllGlobals prefixes[] my_theme | ||
// phpcs:set WPThemeReview.CoreFunctionality.PrefixAllGlobals allowed_folders[] template-parts,templates,partials | ||
// phpcs:set WPThemeReview.CoreFunctionality.PrefixAllGlobals allowed_folders[] template-parts,templates,partials,page-templates | ||
<?php | ||
$my_theme_var = 123; // OK, prefixed. | ||
$var = 'Value'; // OK, template file. | ||
$var = 'Value'; // OK, file in allowed folder. | ||
|
||
// phpcs:set WPThemeReview.CoreFunctionality.PrefixAllGlobals prefixes[] | ||
// phpcs:set WPThemeReview.CoreFunctionality.PrefixAllGlobals allowed_folders[] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters