@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | _n_noop( 'I have %d cat.', 'I have %d cats.' ); // Bad, no text domain. |
51 | 51 | _n_noop( 'I have %d cat.', 'I have %d cats.', 'my-slug' ); // OK. |
52 | 52 | _n_noop( 'I have %d cat.', 'I have %d cats.', "illegal $string" ); // Bad. |
53 | -_n_noop( 'I have %d cat.', 'I have %d cats.', SOMETHING ); // Bad. |
|
53 | +_n_noop( 'I have %d cat.', 'I have %d cats.', SOMETHING ); // Bad. |
|
54 | 54 | |
55 | 55 | _nx( 'I have %d cat.', 'I have %d cats.', $number, 'Not really.' ); // Bad, no text domain. |
56 | 56 | _nx( 'I have %d cat.', 'I have %d cats.', $number, $context ); // Bad. |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | really.', 'my-slug' ); // OK. |
85 | 85 | |
86 | 86 | // Ensure lack of spaces doesn't cause i18n error. |
87 | -_n_noop('I have %d cat.', 'I have %d cats.', 'my-slug'); // OK. |
|
87 | +_n_noop( 'I have %d cat.', 'I have %d cats.', 'my-slug' ); // OK. |
|
88 | 88 | |
89 | 89 | // Dollar sign in literal string is not interpolated, so OK. |
90 | 90 | _n_noop( 'I have %d cat.', 'I have %d cats literal-string-so-$variable-not-interpolated.', 'my-slug' ); // OK. |
@@ -1,21 +1,21 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | -$wpdb->query( "SELECT * FROM $wpdb->posts WHERE post_title LIKE '" . $_GET['title'] . "';" ); // Bad. |
|
4 | -$wpdb->query( "SELECT * FROM $wpdb->posts WHERE post_title LIKE '{$_GET['title']}';" ); // Bad. |
|
3 | +$wpdb->query( "SELECT * FROM $wpdb->posts WHERE post_title LIKE '" . $_GET[ 'title' ] . "';" ); // Bad. |
|
4 | +$wpdb->query( "SELECT * FROM $wpdb->posts WHERE post_title LIKE '{$_GET[ 'title' ]}';" ); // Bad. |
|
5 | 5 | $wpdb->query( "SELECT * FROM $wpdb->posts WHERE post_title LIKE '$var';" ); // Bad. |
6 | 6 | $wpdb->query( "SELECT * FROM $wpdb->posts WHERE post_title LIKE 'Hello World!';" ); // Ok. |
7 | -$wpdb->query( $wpdb->prepare( "SELECT * FROM $wpdb->posts WHERE post_title LIKE '{$_GET['title']}';" ) ); // Bad. |
|
7 | +$wpdb->query( $wpdb->prepare( "SELECT * FROM $wpdb->posts WHERE post_title LIKE '{$_GET[ 'title' ]}';" ) ); // Bad. |
|
8 | 8 | $wpdb->query( $wpdb->prepare( "SELECT * FROM $wpdb->posts WHERE post_title LIKE '$var';" ) ); // Bad. |
9 | -$wpdb->query( $wpdb->prepare( "SELECT * FROM $wpdb->posts WHERE post_title LIKE %s;", $_GET['title'] ) ); // Ok. |
|
9 | +$wpdb->query( $wpdb->prepare( "SELECT * FROM $wpdb->posts WHERE post_title LIKE %s;", $_GET[ 'title' ] ) ); // Ok. |
|
10 | 10 | |
11 | 11 | $wpdb->query( "SELECT * FROM $wpdb->posts WHERE post_title LIKE '" . $escaped_var . "';" ); // WPCS: unprepared SQL OK. |
12 | 12 | $wpdb->query( "SELECT * FROM $wpdb->posts WHERE post_title LIKE '{$escaped_var}';" ); // WPCS: unprepared SQL OK. |
13 | 13 | |
14 | 14 | $wpdb->query( $wpdb->prepare( "SELECT SUBSTRING( post_name, %d + 1 ) REGEXP '^[0-9]+$'", array( 123 ) ) ); // Ok. |
15 | 15 | $wpdb->query( $wpdb->prepare( "SELECT * FROM $wpdb->posts WHERE post_title = 'The \$_GET var can be evil.' AND ID = %s", array( 123 ) ) ); // Ok. |
16 | -$wpdb->query( $wpdb->prepare( "SELECT * FROM $wpdb->posts WHERE post_title = 'The $_GET[foo] var is evil.' AND ID = %s", array( 123 ) ) ); // Bad. |
|
17 | -$wpdb->query( $wpdb->prepare( "SELECT * FROM $wpdb->posts WHERE post_title = 'The \\$_GET[foo]// var is evil again.' AND ID = %s", array( 123 ) ) ); // Bad. |
|
18 | -$wpdb->query( $wpdb->prepare( "SELECT * FROM $wpdb->posts WHERE post_title = 'The \$_GET var can be evil, but $_GET[foo] var is evil.' AND ID = %s", array( 123 ) ) ); // Bad. |
|
16 | +$wpdb->query( $wpdb->prepare( "SELECT * FROM $wpdb->posts WHERE post_title = 'The $_GET[ foo ] var is evil.' AND ID = %s", array( 123 ) ) ); // Bad. |
|
17 | +$wpdb->query( $wpdb->prepare( "SELECT * FROM $wpdb->posts WHERE post_title = 'The \\$_GET[ foo ]// var is evil again.' AND ID = %s", array( 123 ) ) ); // Bad. |
|
18 | +$wpdb->query( $wpdb->prepare( "SELECT * FROM $wpdb->posts WHERE post_title = 'The \$_GET var can be evil, but $_GET[ foo ] var is evil.' AND ID = %s", array( 123 ) ) ); // Bad. |
|
19 | 19 | |
20 | 20 | $wpdb->query( "SELECT * FROM $wpdb->posts WHERE post_title LIKE '" . foo() . "';" ); // Bad. |
21 | 21 | $wpdb->query( $wpdb->prepare( "SELECT * FROM $wpdb->posts WHERE post_title LIKE '" . foo() . "';" ) ); // Bad. |
@@ -1,31 +1,31 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | // Variable keys. |
4 | -foo( $arr[$test] ); // Bad. |
|
5 | -bar( $arr[ $test] ); // Bad. |
|
6 | -foo( $arr[$test ] ); // Bad. |
|
4 | +foo( $arr[ $test ] ); // Bad. |
|
5 | +bar( $arr[ $test ] ); // Bad. |
|
6 | +foo( $arr[ $test ] ); // Bad. |
|
7 | 7 | bar( $arr[ $test ] ); // Good. |
8 | 8 | |
9 | 9 | // The opposite with strings. |
10 | -foo( $arr['test'] ); // Good. |
|
11 | -bar( $arr[ 'test'] ); // Bad. |
|
12 | -foo( $arr['test' ] ); // Bad. |
|
10 | +foo( $arr[ 'test' ] ); // Good. |
|
11 | +bar( $arr[ 'test' ] ); // Bad. |
|
12 | +foo( $arr[ 'test' ] ); // Bad. |
|
13 | 13 | bar( $arr[ 'test' ] ); // Bad. |
14 | 14 | |
15 | 15 | // Nested ones. |
16 | -foo( $arr[ $test[$taz] ] ); // Bad. |
|
16 | +foo( $arr[ $test[ $taz ] ] ); // Bad. |
|
17 | 17 | bar( $arr[ $test[ 'taz' ] ] ); // Bad. |
18 | -foo( $arr[$test[ 'taz' ]] ); // Bad. |
|
19 | -bar( $arr[ $test['taz'] ] ); // Good. |
|
18 | +foo( $arr[ $test[ 'taz' ] ] ); // Bad. |
|
19 | +bar( $arr[ $test[ 'taz' ] ] ); // Good. |
|
20 | 20 | |
21 | 21 | // Mixed key. |
22 | 22 | foo( $arr[ 'string' . $var ] ); // Good, should have spaces. |
23 | -bar( $arr['string'.$var] ); // Bad. |
|
23 | +bar( $arr[ 'string' . $var ] ); // Bad. |
|
24 | 24 | |
25 | 25 | // Non-string/int. |
26 | -$arr[FooClass::FOO_KEY]; // Bad. |
|
26 | +$arr[ FooClass::FOO_KEY ]; // Bad. |
|
27 | 27 | |
28 | -$arr[0]; // Good. |
|
28 | +$arr[ 0 ]; // Good. |
|
29 | 29 | $arr[ 0 ]; // Bad. |
30 | -$arr[-1]; // Good. |
|
30 | +$arr[-1 ]; // Good. |
|
31 | 31 | $arr[ -1 ]; // Bad. |
@@ -4,12 +4,12 @@ discard block |
||
4 | 4 | |
5 | 5 | $array_keyword_must_be_lower_case = array(); // Good. |
6 | 6 | |
7 | -$array_declaration_with_space_after_keyword = array (); // Bad. |
|
7 | +$array_declaration_with_space_after_keyword = array(); // Bad. |
|
8 | 8 | |
9 | 9 | $space_between_parantheses_on_empty_array = array( ); // Bad. |
10 | 10 | |
11 | 11 | $query_vars = array_merge( |
12 | - array('post_type' => 'food'), // Bad, no spaces after opening and before closing paranthesis. |
|
12 | + array( 'post_type' => 'food' ), // Bad, no spaces after opening and before closing paranthesis. |
|
13 | 13 | // ... |
14 | 14 | array( |
15 | 15 | 'post_status' => 'private', |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | 'orderby' => 'title', // Good. |
27 | 27 | ), |
28 | 28 | array( |
29 | - 'closure' => function () { // Good, closures allowed. |
|
29 | + 'closure' => function() { // Good, closures allowed. |
|
30 | 30 | return array(); |
31 | 31 | }, |
32 | 32 | ), |
@@ -44,13 +44,13 @@ discard block |
||
44 | 44 | function to_markdown( $params = array() ) { |
45 | 45 | // Parse sections. |
46 | 46 | $section_formatters = array( |
47 | - 'Description' => function ( $body ) use ( $params ) { |
|
48 | - if ( isset( $params['travis_ci_url'] ) ) { |
|
49 | - $body .= sprintf( "\n\n[](%s)", $params['travis_ci_url'], $params['travis_ci_url'] ); |
|
47 | + 'Description' => function( $body ) use ( $params ) { |
|
48 | + if ( isset( $params[ 'travis_ci_url' ] ) ) { |
|
49 | + $body .= sprintf( "\n\n[](%s)", $params[ 'travis_ci_url' ], $params[ 'travis_ci_url' ] ); |
|
50 | 50 | } |
51 | 51 | return $body; |
52 | 52 | }, |
53 | - 'Screenshots' => function ( $body ) { |
|
53 | + 'Screenshots' => function( $body ) { |
|
54 | 54 | foreach ( $screenshot_matches as $i => $screenshot_match ) { |
55 | 55 | print (int) $i; |
56 | 56 | } |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | } |
69 | 69 | } |
70 | 70 | |
71 | -$primary_order = array( |
|
71 | +$primary_order = array( |
|
72 | 72 | 'n', // Null. |
73 | 73 | 'b', // Boolean. |
74 | 74 | 'i', // Integer. |
@@ -93,15 +93,15 @@ discard block |
||
93 | 93 | $section_args = array( |
94 | 94 | 'title' => sprintf( |
95 | 95 | __( 'Sidebar: %s', 'widget-customizer' ), |
96 | - $GLOBALS['wp_registered_sidebars'][ $sidebar_id ]['name'] |
|
96 | + $GLOBALS[ 'wp_registered_sidebars' ][ $sidebar_id ][ 'name' ] |
|
97 | 97 | ), |
98 | - 'description' => $GLOBALS['wp_registered_sidebars'][ $sidebar_id ]['description'], |
|
98 | + 'description' => $GLOBALS[ 'wp_registered_sidebars' ][ $sidebar_id ][ 'description' ], |
|
99 | 99 | ); |
100 | 100 | |
101 | 101 | $strings = array( |
102 | - 'hidethings' => ( ( true === $this->settings['enable_hidden_class'] && ( is_array( $this->settings['hidden_classname'] ) && array() !== $this->settings['hidden_classname'] ) ) ? true : false ), |
|
103 | - 'enable_async' => ( ( true === $this->settings['enable_async'] && ( is_array( $this->active_mimetypes ) && array() !== $this->active_mimetypes ) ) ? true : false ), |
|
104 | - 'enable_async_debug' => ( ( true === $this->settings['enable_async_debug'] && ( is_array( $this->active_mimetypes ) && array() !== $this->active_mimetypes ) ) ? true : false ), |
|
102 | + 'hidethings' => ( ( true === $this->settings[ 'enable_hidden_class' ] && ( is_array( $this->settings[ 'hidden_classname' ] ) && array() !== $this->settings[ 'hidden_classname' ] ) ) ? true : false ), |
|
103 | + 'enable_async' => ( ( true === $this->settings[ 'enable_async' ] && ( is_array( $this->active_mimetypes ) && array() !== $this->active_mimetypes ) ) ? true : false ), |
|
104 | + 'enable_async_debug' => ( ( true === $this->settings[ 'enable_async_debug' ] && ( is_array( $this->active_mimetypes ) && array() !== $this->active_mimetypes ) ) ? true : false ), |
|
105 | 105 | ); |
106 | 106 | |
107 | 107 | $actions = array( |
@@ -111,16 +111,16 @@ discard block |
||
111 | 111 | add_query_arg( |
112 | 112 | array( |
113 | 113 | 'page' => TGM_Plugin_Activation::$instance->menu, |
114 | - 'plugin' => $item['slug'], |
|
115 | - 'plugin_name' => $item['sanitized_plugin'], |
|
116 | - 'plugin_source' => $item['url'], |
|
114 | + 'plugin' => $item[ 'slug' ], |
|
115 | + 'plugin_name' => $item[ 'sanitized_plugin' ], |
|
116 | + 'plugin_source' => $item[ 'url' ], |
|
117 | 117 | 'tgmpa-install' => 'install-plugin', |
118 | 118 | ), |
119 | 119 | admin_url( TGM_Plugin_Activation::$instance->parent_url_slug ) |
120 | 120 | ), |
121 | 121 | 'tgmpa-install' |
122 | 122 | ), |
123 | - $item['sanitized_plugin'] |
|
123 | + $item[ 'sanitized_plugin' ] |
|
124 | 124 | ), |
125 | 125 | ); |
126 | 126 | |
@@ -205,4 +205,4 @@ discard block |
||
205 | 205 | array( 1, 2 ); |
206 | 206 | |
207 | 207 | // Test for fixing of extra whitespace. |
208 | -array( 1, 2 ); |
|
208 | +array( 1, 2 ); |
@@ -26,7 +26,8 @@ |
||
26 | 26 | 'orderby' => 'title', // Good. |
27 | 27 | ), |
28 | 28 | array( |
29 | - 'closure' => function () { // Good, closures allowed. |
|
29 | + 'closure' => function () { |
|
30 | +// Good, closures allowed. |
|
30 | 31 | return array(); |
31 | 32 | }, |
32 | 33 | ), |
@@ -2,6 +2,6 @@ |
||
2 | 2 | |
3 | 3 | $foo = array( 'bar' => 1 ); // Bad. |
4 | 4 | |
5 | -$foo['bar'] = 1; // Bad. |
|
5 | +$foo[ 'bar' ] = 1; // Bad. |
|
6 | 6 | |
7 | 7 | $foo = 'test' . 'bar=1&taz=5&bar=2'; // Bad. |
@@ -1,20 +1,20 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | -foo( $_GET['bar'] ); |
|
3 | +foo( $_GET[ 'bar' ] ); |
|
4 | 4 | |
5 | -foo( $_GET['whitelisted'] ); // Input var okay. |
|
5 | +foo( $_GET[ 'whitelisted' ] ); // Input var okay. |
|
6 | 6 | |
7 | -foo( $_POST['whitelisted_with_prefix'] ); // WPCS: input var okay. |
|
7 | +foo( $_POST[ 'whitelisted_with_prefix' ] ); // WPCS: input var okay. |
|
8 | 8 | |
9 | -if ( $_GET['test'] && foo() && $bar ) { // input var okay |
|
9 | +if ( $_GET[ 'test' ] && foo() && $bar ) { // input var okay |
|
10 | 10 | taz(); |
11 | 11 | } |
12 | 12 | |
13 | -bar( $_POST['foo'] ); // Warning. |
|
13 | +bar( $_POST[ 'foo' ] ); // Warning. |
|
14 | 14 | |
15 | -quux( $_REQUEST['quux'] ); // Warning. |
|
15 | +quux( $_REQUEST[ 'quux' ] ); // Warning. |
|
16 | 16 | |
17 | -$_REQUEST['wp_customize'] = 'on'; // Ok. |
|
17 | +$_REQUEST[ 'wp_customize' ] = 'on'; // Ok. |
|
18 | 18 | |
19 | 19 | // Issue: https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues/542 |
20 | -if ( isset( $_GET['updated'] ) ) { // input var okay ?> |
|
20 | +if ( isset( $_GET[ 'updated' ] ) ) { // input var okay ?> |
@@ -6,7 +6,8 @@ discard block |
||
6 | 6 | |
7 | 7 | foo( $_POST['whitelisted_with_prefix'] ); // WPCS: input var okay. |
8 | 8 | |
9 | -if ( $_GET['test'] && foo() && $bar ) { // input var okay |
|
9 | +if ( $_GET['test'] && foo() && $bar ) { |
|
10 | +// input var okay |
|
10 | 11 | taz(); |
11 | 12 | } |
12 | 13 | |
@@ -17,4 +18,5 @@ discard block |
||
17 | 18 | $_REQUEST['wp_customize'] = 'on'; // Ok. |
18 | 19 | |
19 | 20 | // Issue: https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues/542 |
20 | -if ( isset( $_GET['updated'] ) ) { // input var okay ?> |
|
21 | +if ( isset( $_GET['updated'] ) ) { |
|
22 | +// input var okay ?> |
@@ -10,9 +10,9 @@ |
||
10 | 10 | |
11 | 11 | _query_posts( 'nopaging=true&posts_per_page=999' ); // Bad. |
12 | 12 | |
13 | -$query_args['posts_per_page'] = -1; // Bad. |
|
14 | -$query_args['posts_per_page'] = 1; // Ok. |
|
15 | -$query_args['posts_per_page'] = '1'; // Ok. |
|
16 | -$query_args['posts_per_page'] = '-1'; // Bad. |
|
13 | +$query_args[ 'posts_per_page' ] = -1; // Bad. |
|
14 | +$query_args[ 'posts_per_page' ] = 1; // Ok. |
|
15 | +$query_args[ 'posts_per_page' ] = '1'; // Ok. |
|
16 | +$query_args[ 'posts_per_page' ] = '-1'; // Bad. |
|
17 | 17 | |
18 | -$query_args['my_posts_per_page'] = -1; // Ok. |
|
18 | +$query_args[ 'my_posts_per_page' ] = -1; // Ok. |
@@ -1,13 +1,13 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | function my_add_weekly( $schedules ) { |
4 | - $schedules['every_6_mins'] = array( |
|
4 | + $schedules[ 'every_6_mins' ] = array( |
|
5 | 5 | 'interval' => 360, |
6 | 6 | 'display' => __( 'Once every 6 minutes' ) |
7 | 7 | ); |
8 | 8 | return $schedules; |
9 | 9 | } |
10 | -add_filter( 'cron_schedules', 'my_add_weekly'); |
|
10 | +add_filter( 'cron_schedules', 'my_add_weekly' ); |
|
11 | 11 | |
12 | 12 | |
13 | 13 | class Foo { |
@@ -16,7 +16,7 @@ discard block |
||
16 | 16 | } |
17 | 17 | |
18 | 18 | function my_add_quickly( $schedules ) { |
19 | - $schedules['every_10_mins'] = array( |
|
19 | + $schedules[ 'every_10_mins' ] = array( |
|
20 | 20 | 'interval' => 10 * 60, |
21 | 21 | 'display' => __( 'Once every 10 minutes' ) |
22 | 22 | ); |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | } |
25 | 25 | |
26 | 26 | static function my_add_quicklier( $schedules ) { |
27 | - $schedules['every_5_mins'] = array( |
|
27 | + $schedules[ 'every_5_mins' ] = array( |
|
28 | 28 | 'interval' => 20 * 60 - 15 * 60, // Sneaky 5 minute interval. |
29 | 29 | 'display' => __( 'Once every 5 minutes' ) |
30 | 30 | ); |
@@ -36,8 +36,8 @@ discard block |
||
36 | 36 | |
37 | 37 | add_filter( 'cron_schedules', array( $some_other_place, 'some_other_method' ) ); |
38 | 38 | |
39 | -add_filter( 'cron_schedules', function ( $schedules ) { |
|
40 | - $schedules['every_9_mins'] = array( |
|
39 | +add_filter( 'cron_schedules', function( $schedules ) { |
|
40 | + $schedules[ 'every_9_mins' ] = array( |
|
41 | 41 | 'interval' => 9 * 60, |
42 | 42 | 'display' => __( 'Once every 9 minutes' ) |
43 | 43 | ); |
@@ -10,10 +10,10 @@ |
||
10 | 10 | |
11 | 11 | $query = "SELECT * FROM $wpdb->posts"; // Ok. |
12 | 12 | |
13 | -if ( isset( $_SERVER['REMOTE_ADDR'] ) ) { // Bad. |
|
14 | - foo( $_SERVER['HTTP_USER_AGENT'] ); // Bad. |
|
13 | +if ( isset( $_SERVER[ 'REMOTE_ADDR' ] ) ) { // Bad. |
|
14 | + foo( $_SERVER[ 'HTTP_USER_AGENT' ] ); // Bad. |
|
15 | 15 | } |
16 | 16 | |
17 | -$x = $_COOKIE['bar']; // Bad. |
|
17 | +$x = $_COOKIE[ 'bar' ]; // Bad. |
|
18 | 18 | |
19 | -$y = $_SERVER['REQUEST_URI']; // Ok. |
|
19 | +$y = $_SERVER[ 'REQUEST_URI' ]; // Ok. |
@@ -10,7 +10,8 @@ |
||
10 | 10 | |
11 | 11 | $query = "SELECT * FROM $wpdb->posts"; // Ok. |
12 | 12 | |
13 | -if ( isset( $_SERVER['REMOTE_ADDR'] ) ) { // Bad. |
|
13 | +if ( isset( $_SERVER['REMOTE_ADDR'] ) ) { |
|
14 | +// Bad. |
|
14 | 15 | foo( $_SERVER['HTTP_USER_AGENT'] ); // Bad. |
15 | 16 | } |
16 | 17 |