WordPress / WordPress/WordPress-Coding-Standards

Update needed to the WP global variables list

Open
#924 12 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Status: Good first issue Status: Help wanted Type: Chores/Cleanup
Dominant language
PHP
Stars
2.8k
Forks
521
Avg merge
5d 20h
Merged PRs (30d)
1

Description

As discussed in https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/pull/904#pullrequestreview-30382018, the list with WP global variables needs to be updated.

The list is currently used by two sniffs:

  • Variables.GlobalVariables to check for overwriting WordPress native global variables.
  • NamingConventions.PrefixAllGlobals - to verifies whether a prefix is needed for variables.

For the NamingConventions.PrefixAllGlobals sniff the list needs to be complete.
For the Variables.GlobalVariables we'll need to allow for a number of variables which plugins/themes are allowed to override.

we should probably have a small $overrule_allowed list in the Global Var Override sniff and do an array_diff() to prime the list for usage in that sniff.

@JDGrimes has created an initial diff between WP core and the list currently in WPCS which is a good starting point:

I've just checked over trunk and come up with a new list of WordPress globals, and there are some changes from the old list: https://www.diffchecker.com/jOhQZYHl

But take note of:

While searching for global and $GLOBALS gives us a good starting point, any variable created in the global namespace and not unset should be on the list.

Some more references about WP global vars (which may well be out of date):

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Variables.GlobalVariables and NamingConventions.PrefixAllGlobals sniffs, then compare their current WordPress global-variable list with the core globals and the initial diff linked in the issue. Done means the PrefixAllGlobals list is complete and GlobalVariables permits the documented override exceptions without false positives.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.