File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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 >
You can’t perform that action at this time.
0 commit comments