Skip to content

Commit fa02bc4

Browse files
rodrigoprimopaulopmt1jrfnl
authored
WP/GlobalVariablesOverride: add XML documentation (#2679)
* Add GlobalVariableOverride standard doc --------- Co-authored-by: Paulo Trentin <paulo@paulotrentin.com.br> Co-authored-by: Juliette <663378+jrfnl@users.noreply.github.com>
1 parent 55dcb16 commit fa02bc4

1 file changed

Lines changed: 41 additions & 0 deletions

File tree

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?xml version="1.0"?>
2+
<documentation xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="https://phpcsstandards.github.io/PHPCSDevTools/phpcsdocs.xsd"
4+
title="Global Variables Override"
5+
>
6+
<standard>
7+
<![CDATA[
8+
Variables declared by WordPress in the global namespace should not be overridden by code extending WordPress.
9+
10+
Two WordPress global variables, `$content_width` and `$wp_cockneyreplace`, are
11+
specifically intended to be overridden by themes/plugins and are exempt from this rule.
12+
]]>
13+
</standard>
14+
<code_comparison>
15+
<code title="Valid: Declaring global variables with names not reserved for use by WordPress itself.">
16+
<![CDATA[
17+
<em>$prefix_query</em> = new WP_Query( $args );
18+
19+
<em>$GLOBALS['prefix_data']</em> = 'some data';
20+
21+
foreach ( $selected_posts as <em>$prefix_post</em> ) {
22+
// Do something.
23+
}
24+
]]>
25+
</code>
26+
<code title="Invalid: Overriding a WordPress defined global variable.">
27+
<![CDATA[
28+
function prefix_custom_query( $args ) {
29+
<em>global $wp_query;</em>
30+
<em>$wp_query</em> = new WP_Query( $args );
31+
32+
<em>$GLOBALS['post']</em> = get_post( 1 );
33+
}
34+
35+
foreach ( $selected_posts as <em>$post</em> ) {
36+
// Do something.
37+
}
38+
]]>
39+
</code>
40+
</code_comparison>
41+
</documentation>

0 commit comments

Comments
 (0)