Comments (7)
The sniff covers both actions as well as filters.
Generally speaking, themes should hook into core filters and actions and shouldn't ever need to invoke the core hooks.
There are always exceptions, of course. In that case, the invocation can be whitelisted and the reason for calling the core hook documented, like so:
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- Invoking core hook for reasons.....
do_action( 'name_of_core_hook' );
from wpthemereview.
False positive in something like: I have a loop creating markup and inserting actions:
do_action( $col_data[ $type ] );
Results in:
WARNING Hook names invoked by a theme/plugin should start with the theme/plugin prefix. Found: "$col_data[ $type ]".
They vary depending on what plugins are installed.
I think hooks consisting of variables only should be excluded.
from wpthemereview.
I don't think that's an exception. It should still start with the theme's prefix.
from wpthemereview.
Oh sorry, that example was unclear - that's being called from within a class and a function, so I wouldn't have prefixed the variable. I think the global variable sniff would be enough to alert about that though, there shouldn't be a reason why the hook name as only a variable should have to be checked further in that case.
from wpthemereview.
We're not talking about prefixing variables here. We're talking about prefixing hook names. There are very few cases where themes should be calling do_action
on unprefixed hook names.
from wpthemereview.
I know, the title of the ticket is "Exceptions to prefixing hook names," so I thought it made sense to place it here rather than a new ticket. Currently I'm getting the warnings above saying I should prefix the hook name, but it shouldn't be giving me one as it isn't contextually aware of what is stored inside of the variable, and I think that situation should be an exception to the existing sniff.
The note about the prefixing variables is saying that even if I were using a variable in the global namespace and calling do_action( $something )
directly in a template file, I would still get this error. Even in those situations it's not needed since variables already have checks for prefixing those names, and the sniff isn't aware of the value assigned to $something
.
from wpthemereview.
Should we have a sniff for that, or maybe some kind of whitelist added in the ruleset.xml
(if this is possible ofc) for this?
Otherwise I'd like to close this as a part of the issue grooming process 🙂
from wpthemereview.
Related Issues (20)
- variables in template files are flagged as global HOT 15
- False positive on loading stylesheet in JS file HOT 4
- [New sniff] WC template versions HOT 7
- Dealing with rules that shouldn't apply to templates HOT 1
- Add sniff: WordPress.PHP.IniSet HOT 6
- [New sniff] Check if page templates are using reserved prefix HOT 1
- Detect WPTRT feature project versions HOT 3
- Add sniff documentation HOT 1
- Minimal PHP version HOT 11
- Whitelist wp_body_open function from PrefixAllGlobals sniff HOT 5
- sniff: plugin territory - action hook wp_edit_nav_menu_walker
- File name with reserved slug in subfolder HOT 11
- Optimisation and minor grammar fixes
- [Implement sniff] Warn about short ternary usage in themes HOT 9
- Internal.Exception -- function update_current_version() should be removed.
- [Update existing sniff] Allow register_block_style HOT 1
- Allow `add_menu_page` & `add_submenu_page` HOT 9
- twentyseventeen theme: posts with no date - but date is shown in similar posts HOT 1
- 👍
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from wpthemereview.