WPThemeReview
WPThemeReview copied to clipboard
Passing dynamic information to sniffs
I started looking how we could pass the text domains to the i18n sniff without having the text domain in the ruleset.
I tried to use setSniffProperty( 'WordPress_Sniffs_WP_I18nSniff', 'text_domain', 'my-slug' );
which did not work and ended up using WordPress_Sniffs_WP_I18nSniff::$text_domain_override
.
If people are running the check from cli then they can use the ruleset to define their properties. If we are running the command from a system like the NS Theme Check by @ernilambar we need to pass the text domain dynamically. e.g. https://github.com/grappler/ns-theme-check/commit/0ef750f2d14761e9f7d2d3e46b5e00c2fbe0fd7e
I think we can solve some of the open issues still with PHPCS if we pass the theme data to the cli dynamically. For example we could pass all of the theme tags and if a add_theme_support()
is used but the tag is not then we could show an error.
In the case of NS Theme Check we can use WordPress functions to fetch that theme data. If the data is not set like in the cli we can show a warning. The data would be defined via a property or static variable in the class.
ping @fklein-lu & @jrfnl
For the text-domain part, this should be fixed by https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/pull/807
This has been fixed with the prefix all globals sniff, and by adding the optional parameter.
@dingo-d I don't understand why this was closed ?
Oh, I totally mistaken the text-domain with the prefix 🤦♂ My bad.
Another dynamic item is whether it's a child theme or not.
How does the child theme affect the standards? I'm wondering how does this affect the code and what needs to be checked. Is it something that can be sniffed, are the changes substantial?
Well, child themes don't have to be child theme friendly. They can remove parent theme menu items. They don't have to have the standard classes in the style. There are quite a few errors that Theme Check shows on a child theme that shouldn't be shown.
I'm wondering if this is more suited for the theme sniffer than for the standards themselves? Or it would mean that we should override the WordPress_Sniffs_WP_I18nSniff
to allow for the dynamic parts?
If that's the case I'm for modifying it, but I'm not 100% sure if I got the jist of it.