Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Implement sniff] Everything in the global namespace should be prefixed #129

Closed
1 of 2 tasks
jrfnl opened this issue Apr 4, 2017 · 4 comments
Closed
1 of 2 tasks

Comments

@jrfnl
Copy link
Contributor

jrfnl commented Apr 4, 2017

Rule type:

Error

Rule:

I'm not sure whether anything about this is currently in the handbook, but it is best practice to prefix all function/class/constant/variable/hook names used in the global namespace to prevent naming collisions with plugins and potentially the parent-theme.

Decision needed:

Check whether this is currently covered the handbook and if it isn't, a decision is needed on whether it should be added.

Advice: Add to the handbook.

Notes for implementation:

To do:

  • Add the rule in the Theme Review handbook to the Requirements page.
  • Add existing WordPress.NamingConventions.PrefixAllGlobals sniff to the ruleset after the current version of WPCS has been merged back into TRTCS.
@carolinan
Copy link

The requirement reads
"Provide a unique prefix for everything the Theme defines in the public namespace, including options, functions, global variables, constants, post meta, etc."

@jrfnl
Copy link
Contributor Author

jrfnl commented Apr 4, 2017

@carolinan Excellent! Thanks. In that case, only the sniff needs to be added to the ruleset.

@justintadlock
Copy link

Just want to note that I'm a bit iffy on meta necessarily being prefixed. In general, I usually say that it must be. However, there are some common keys that theme authors use from theme to theme. Using a common key gives you a bit more portability in an area where WP sucks at portability.

Prefixing should be done here if it's something specific to this one particular theme.

For example, suppose we allowed themes to register post types, I wouldn't want them prefixing their "testimonial" post type as themename_testimonial. I'd want them sticking with a more standard testimonial.

I'd treat metadata the same. If it's specific to the theme, prefix. If it's something that other themes could use, stick with a un-prefixed, common naming system.

@jrfnl
Copy link
Contributor Author

jrfnl commented Apr 13, 2017

@justintadlock The sniff (currently) does not check meta keys or post types. It only checks PHP globals (variables, functions, classes, constants) and hook names for WP.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants