WPThemeReview icon indicating copy to clipboard operation
WPThemeReview copied to clipboard

Passing dynamic information to sniffs

Open grappler opened this issue 8 years ago • 8 comments

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

grappler avatar Dec 26 '16 13:12 grappler

For the text-domain part, this should be fixed by https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/pull/807

jrfnl avatar Jan 18 '17 11:01 jrfnl

This has been fixed with the prefix all globals sniff, and by adding the optional parameter.

dingo-d avatar May 18 '19 12:05 dingo-d

@dingo-d I don't understand why this was closed ?

jrfnl avatar May 19 '19 20:05 jrfnl

Oh, I totally mistaken the text-domain with the prefix 🤦‍♂ My bad.

dingo-d avatar May 20 '19 08:05 dingo-d

Another dynamic item is whether it's a child theme or not.

joyously avatar Jun 03 '19 20:06 joyously

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?

dingo-d avatar Jun 04 '19 07:06 dingo-d

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.

joyously avatar Jun 04 '19 13:06 joyously

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.

dingo-d avatar Mar 11 '20 16:03 dingo-d