Comments (6)
I have a sniff for this.
from wpthemereview.
One thing I've seen as problematic with this check is that theme authors are now starting to incorrectly use get_template_part()
to load non-template files. I wonder if we should consider a check specifically for functions.php
that does the opposite. Thoughts?
from wpthemereview.
I think this needs to be improved as well. I think the warning for using require/include functions could be changed to an error if the file being loaded does not have the 'function' string.
The use of get_template_directory can also be checked in the same (or probably) a new sniff.
from wpthemereview.
I can't ever see this particular check being an error. There are too many exceptions. Just a couple:
This correctly uses locate_template()
:
$template = locate_template( array( 'example/abc.php`, `example/xyz.php' ) );
if ( $template )
include( $template );
This correctly uses get_page_template()
:
$template = get_page_template();
if ( $template )
include( $template );
Not all files loaded will have a function
string. You can have a class without any methods/functions defined. Some files will only have variables.
For a functions-file sniff, get_template_directory()
wouldn't really be a good idea either. Just a couple of examples that break that:
Using a variable:
$dir = trailingslashit( get_template_directory() );
require_once( $dir . 'file-1.php' );
require_once( $dir . 'file-2.php' );
Including file from child theme:
if ( is_child_theme() ) {
$dir = trailingslashit( get_stylesheet_directory() );
if ( file_exists( $dir . 'example.php' ) )
require_onc( $dir . 'example.php' );
These are just examples that are common in my own themes. Proper file loading is something that's going to always take a manual check as far as I can tell.
from wpthemereview.
OK no problem....we can move back to a warning.
However let's eliminate all the warnings that we know are OK. On testing I have seen some themes that have a significant amount of warnings. In themecheck this is handled by not checking the functions.php file, and only issuing one warning per file.
I would think we could add a few checks that would greatly reduce the number of times this warning comes up. One of course would be where functions are defined, a warning should not be issued. That would cut down the warnings significantly.
What do you think?
from wpthemereview.
Closing as #67 has been merged.
from wpthemereview.
Related Issues (20)
- Empty Author URI and Theme URI gives error of duplicate URL HOT 4
- 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.