-
-
Notifications
You must be signed in to change notification settings - Fork 518
Add GlobalVariablesOverride standard doc #2586
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
base: develop
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,41 @@ | ||||||
<?xml version="1.0"?> | ||||||
<documentation xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||||||
xsi:noNamespaceSchemaLocation="https://phpcsstandards.github.io/PHPCSDevTools/phpcsdocs.xsd" | ||||||
title="Global Variables Override" | ||||||
> | ||||||
<standard> | ||||||
<![CDATA[ | ||||||
WordPress global variables should not be overridden. This includes variables imported with | ||||||
the `global` statement within functions, variables assigned via the `$GLOBALS` superglobal array, | ||||||
and variables assigned in the global namespace. | ||||||
|
||||||
A few select WordPress global variables like `$content_width` and `$wp_cockneyreplace` are | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since those are the two only WP global variables that can be overriden, I think this paragraph could be rephrased to remove the "like". |
||||||
specifically intended to be overridden by themes/plugins and are exempt from this rule. | ||||||
]]> | ||||||
</standard> | ||||||
<code_comparison> | ||||||
<code title="Valid: Different variable name."> | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure about this title. Maybe The concern that I have with |
||||||
<![CDATA[ | ||||||
$my_query = new WP_Query( $args ); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Following the pattern that I suggested below, I think that here you can highlight the |
||||||
]]> | ||||||
</code> | ||||||
<code title="Invalid: Global variable overridden."> | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
I think it is important to mention that this is about WordPress globals and not any globals. |
||||||
<![CDATA[ | ||||||
<em>global $wp_query;</em> | ||||||
<em>$wp_query = new WP_Query( $args );</em> | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For this code example, I would suggest highlighting with the |
||||||
]]> | ||||||
</code> | ||||||
</code_comparison> | ||||||
<code_comparison> | ||||||
<code title="Valid: Custom Superglobal variable."> | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The superglobal is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I ended up simplifying it. |
||||||
<![CDATA[ | ||||||
$GLOBALS['my_data'] = array( 'key' => 'value' ); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See my remarks above regarding the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This line has 49 characters and the maximum is 48. |
||||||
]]> | ||||||
</code> | ||||||
<code title="Invalid: WordPress Superglobal variable overridden."> | ||||||
<![CDATA[ | ||||||
<em>$GLOBALS['wp_query'] = new WP_Query( $args );</em> | ||||||
]]> | ||||||
</code> | ||||||
</code_comparison> | ||||||
</documentation> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In my opinion, just saying "WordPress global variables should not be overridden." is enough and second phrase is not necessary, but other reviewers might disagree with me, so feel free to leave it for now if you prefer.