Comments (8)
This issue raises a number of questions:
- Is this the only filter where a check like this would need to take place or are there / will there be more actions/filters where the parameters will need to be checked ?
- Does the check need to be for the amount of parameters passed or also need to go into the content ? (If the answer would be 'content', that would be neigh impossible as variables can be named differently across themes.)
Questions from an implementation perspective:
- Do we need to create a re-usable abstract class which handles a large part of the logic and can be extended for individual actions/filters or small groups thereof ?
- If this will be the only one, we can just use a hard-coded check, if not, we may need to have an extensible array property listing the hooks or in the case of the abstract, possibly a function instead.
Also: is there a rule in the handbook covering this or should it be added ?
from wpthemereview.
Is this the only filter where a check like this would need to take place or are there / will there be more actions/filters where the parameters will need to be checked ?
Not sure if there are others at the moment.
Does the check need to be for the amount of parameters passed or also need to go into the content ? (If the answer would be 'content', that would be neigh impossible as variables can be named differently across themes.)
Amount is doable and would make theme devs aware of the issue.
Do we need to create a re-usable abstract class which handles a large part of the logic and can be extended for individual actions/filters or small groups thereof ?
If this will be the only one, we can just use a hard-coded check, if not, we may need to have an extensible array property listing the hooks or in the case of the abstract, possibly a function instead.
There's few cases of themes needing to call core WP hooks like this. It's really a poor implementation on core's part to be honest.
I really can't think of another example off the top of my head, but I'll leave it open to others.
Also: is there a rule in the handbook covering this or should it be added ?
We don't currently have a specific rule to this specific case. It falls under the more general "Use template tags and action/filter hooks properly" guideline. See: https://make.wordpress.org/themes/handbook/review/required/#core-functionality-and-features
from wpthemereview.
If custom widgets are no longer allowed this would be a non issue?
from wpthemereview.
Perhaps, but we haven't gotten rid of custom widgets yet. My theme in particular relies on my custom widgets for its flexibility.
from wpthemereview.
We could maybe add a warning sniff about possible depreciation of custom widgets, but I guess this depends on how the gutenberg widget thing will progress...
from wpthemereview.
We need to see how relevant this issue is in the context of widgets being moved to core blocks.
Also, we got the info about unused parameters in actions and hooks in general, but that sounds more like a WPCS issue to me.
Thoughts @jrfnl?
from wpthemereview.
Also, we got the info about unused parameters in actions and hooks in general, but that sounds more like a WPCS issue to me.
I agree. I think someone should probably check if there is a WPCS issue open for this, and if not, open one.
I imagine it would be good to have one generic sniff which checks that if any of the WP core hooks are invoked in a plugin/theme (or in core itself) that the amount of parameters passed is the same as in the original hook definition used in Core.
This would be a horrific sniff to maintain though unless we also create a second (non-public) sniff to scan core on each release which would update the (public) sniff, see WordPress/WordPress-Coding-Standards#1803 for more information about that principle.
from wpthemereview.
I like that idea, especially if we would have the extra utility sniff in the linked issue 🙂 That would help with the maintenance. I'll open up an issue upstream, and close this one 👍
from wpthemereview.
Related Issues (20)
- variables in template files are flagged as global HOT 15
- Exceptions to prefixing hook names HOT 7
- 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.