Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GlobalVariablesOverride/PrefixAllGlobals: handle WP variables intende…
…d to be overwritten WP Core contains the global `$content_width` variable which is intended to be set/overwritten by plugins and themes. For that reason the variable was previously removed from the `Sniff::$wp_globals` list in WPCS 0.4.0. See 276, 331. The downside of the variable not being in the list is that the `PrefixAllGlobals` sniff complains about it not being prefixed, as it doesn't realize it is a WP native global variable. The upside was that the `GlobalVariablesOverride` sniff did not complain about the variable being overwritten. Adding the variable to the `Sniff::$wp_globals` list would reverse that situation with the `PrefixAllGlobals` sniff staying silent and the `GlobalVariablesOverride` sniff starting to complain. This PR intends to solve this conundrum. * The list of WP Core globals in `Sniff::$wp_globals` should be complete and not intentionally miss certain variables without there being any documentation on why there are not listed there. * To still allow for the `GlobalVariablesOverride` sniff to function correctly, a new `$override_allowed` property has been added to that sniff, as well as logic to handle this. Unit tests confirming that this fixes the issue have been added to both sniffs. Additional notes: * There may be more variables in WP Core which are intended to be overwritten by plugins/themes. I have not verified this. If we do come across additional ones, it will now be easy enough to add them to the whitelist anyway. For now, only `content_width` and `wp_cockneyreplace` have been added. Also see: #924 (comment) and https://core.trac.wordpress.org/browser/trunk/src/wp-includes/formatting.php#L123 * This PR does not address the fact that the `Sniff::$wp_globals` list is grossly out of date. See 924 Fixes 1043
- Loading branch information