UserExperience/AdminBarRemoval: various improvements#866
Merged
Conversation
* Testing against false positives for calls to methods or namespaced function calls (= the issue being addressed in this PR).
* Safeguarding that function calls using PHP 5.6+ argument unpacking are flagged.
* Safeguarding handling of PHP 8.0+ attribute class using the same name as a target function.
* Safeguarding that the function is not flagged when used as a PHP 8.1+ first class callable.
* Adding tests with more variations:
- Non-lowercase function call(s).
- Fully qualified function calls for the escaping functions.
- Use PHP 7.3+ trailing comma's in a few function calls.
- Text strings using single quotes and double quotes.
…eter values The PHPCSUtils `PassedParameters::getParameters()` return value includes a `'clean'` array index, which contains the contents of the parameter stripped of surrounding whitespace and comments. The `AdminBarRemoval` sniff uses the parameter contents in a couple of places to compare against a specific text string, but would break if the parameter value would contain a comment. Fixed now. Includes tests.
…ction calls using named parameters Includes tests.
… alias ... for `add_filter()`. Includes test.
…first class callables ... when used as the `$callback` parameter for `add_filter()`/`add_action()`. Includes tests.
…ensitive ... even when passed as callbacks. Includes test.
No need for a `switch` here.
…s PHP file A number of IDEs will use STDIN to run PHPCS and will pass the `stdin_path` to PHPCS to set the file name, which often results in the filename being quoted. In that case, the original logic in this sniff would break as the `$file_extension` would end up being `'css"'`, which doesn't match the expected `'css'`. The new PHPCSUtils 1.1.0 `FilePath::getName()` method will strip quotes from the file name, as well as normalize the slashes to forward (*nix) slashes. Applying that method fixes the bug.
Let PHP sort out splitting the extension off the file name.
GaryJones
approved these changes
Jul 30, 2025
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
UserExperience/AdminBarRemoval: add additional tests
UserExperience/AdminBarRemoval: bug fix - disregard comments in parameter values
The PHPCSUtils
PassedParameters::getParameters()return value includes a'clean'array index, which contains the contents of the parameter stripped of surrounding whitespace and comments.The
AdminBarRemovalsniff uses the parameter contents in a couple of places to compare against a specific text string, but would break if the parameter value would contain a comment.Fixed now. Includes tests.
UserExperience/AdminBarRemoval: add support for handling PHP 8.0+ function calls using named parameters
Includes tests.
UserExperience/AdminBarRemoval: bug fix - recognize add_action() as alias
... for
add_filter().Includes test.
UserExperience/AdminBarRemoval: add support for recognizing PHP 8.1+ first class callables
... when used as the
$callbackparameter foradd_filter()/add_action().Includes tests.
UserExperience/AdminBarRemoval: bug fix - function names are case-insensitive
... even when passed as callbacks.
Includes test.
UserExperience/AdminBarRemoval: remove some redundant logic
No need for a
switchhere.UserExperience/AdminBarRemoval: bug fix - CSS file might be handled as PHP file
A number of IDEs will use STDIN to run PHPCS and will pass the
stdin_pathto PHPCS to set the file name, which often results in the filename being quoted.In that case, the original logic in this sniff would break as the
$file_extensionwould end up being'css"', which doesn't match the expected'css'.The new PHPCSUtils 1.1.0
FilePath::getName()method will strip quotes from the file name, as well as normalize the slashes to forward (*nix) slashes.Applying that method fixes the bug.
UserExperience/AdminBarRemoval: minor simplification
Let PHP sort out splitting the extension off the file name.