You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: wordpress-coding-standards/php.md
+9-9Lines changed: 9 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -133,7 +133,7 @@ Note that requiring the use of braces just means that _single-statement inline c
133
133
134
134
Using long array syntax ( `array( 1, 2, 3 )` ) for declaring arrays is generally more readable than short array syntax ( `[ 1, 2, 3 ]` ), particularly for those with vision difficulties. Additionally, it's much more descriptive for beginners.
135
135
136
-
Arrays must be declared using long array syntax.
136
+
Arrays must be declared using the long array syntax.
137
137
138
138
### Closures (Anonymous Functions)
139
139
@@ -237,11 +237,11 @@ Incorrect:
237
237
238
238
### Remove Trailing Spaces
239
239
240
-
Remove trailing whitespace at the end of each line of code. Omitting the closing PHP tag at the end of a file is preferred. If you use the tag, make sure you remove trailing whitespace.
240
+
Remove trailing whitespace at the end of each line of code. Omitting the closing PHP tag at the end of a file is preferred. If you use the tag, make sure you remove the trailing whitespace.
241
241
242
242
### Space Usage
243
243
244
-
Always put spaces after commas, and on both sides of logical, comparison, string and assignment operators.
244
+
Always put spaces after commas, and on both sides of the logical, comparison, string, and assignment operators.
When formatting SQL statements you may break it into several lines and indent if it is sufficiently complex to warrant it. Most statements work well as one line though. Always capitalize the SQL parts of the statement like `UPDATE` or `WHERE`.
330
+
When formatting SQL statements you may break them into several lines and indent if it is sufficiently complex to warrant it. Most statements work well as one line though. Always capitalize the SQL parts of the statement like `UPDATE` or `WHERE`.
331
331
332
332
Functions that update the database should expect their parameters to lack SQL slash escaping when passed. Escaping should be done as close to the time of the query as possible, preferably by using `$wpdb->prepare()`
333
333
@@ -340,7 +340,7 @@ $id = some_foo_number(); // data we expect to be an integer, but we're not certa
340
340
$wpdb->query( $wpdb->prepare( "UPDATE $wpdb->posts SET post_title = %s WHERE ID = %d", $var, $id ) );
341
341
```
342
342
343
-
`%s` is used for string placeholders and `%d` is used for integer placeholders. Note that they are not 'quoted'! `$wpdb->prepare()` will take care of escaping and quoting for us. The benefit of this is that we don't have to remember to manually use [`esc_sql()`](https://developer.wordpress.org/reference/functions/esc_sql/), and also that it is easy to see at a glance whether something has been escaped or not, because it happens right when the query happens.
343
+
`%s` is used for string placeholders and `%d` is used for integer placeholders. Note that they are not 'quoted'! `$wpdb->prepare()` will take care of escaping and quoting for us. The benefit of this is that we don't have to remember to manually use [`esc_sql()`](https://developer.wordpress.org/reference/functions/esc_sql/), and also that it is easy to see at a glance whether something has been escaped or not because it happens right when the query happens.
344
344
345
345
See [Data Validation](https://developer.wordpress.org/plugins/security/data-validation/) in the Plugin Handbook for further details.
346
346
@@ -377,7 +377,7 @@ Files should be named descriptively using lowercase letters. Hyphens should sepa
377
377
my-plugin-name.php
378
378
```
379
379
380
-
Class file names should be based on the class name with `class-` prepended and the underscores in the class name replaced with hyphens, for example `WP_Error` becomes:
380
+
Class file names should be based on the class name with `class-` prepended and the underscores in the class name replaced with hyphens, for example,`WP_Error` becomes:
381
381
382
382
```php
383
383
class-wp-error.php
@@ -456,7 +456,7 @@ Dynamic hooks should be named using interpolation rather than concatenation for
456
456
457
457
Dynamic hooks are hooks that include dynamic values in their tag name, e.g. `{$new_status}_{$post->post_type}` (publish_post).
458
458
459
-
Variables used in hook tags should be wrapped in curly braces `{` and `}`, with the complete outer tag name wrapped in doublequotes. This is to ensure PHP can correctly parse the given variables' types within the interpolated string.
459
+
Variables used in hook tags should be wrapped in curly braces `{` and `}`, with the complete outer tag name wrapped in double-quotes. This is to ensure PHP can correctly parse the given variables' types within the interpolated string.
The `eval()` construct is _very dangerous_, and is impossible to secure. Additionally, the `create_function()` function, which internally performs an `eval()`, is deprecated in PHP 7.2. Neither of these must be used.
571
+
The `eval()` construct is _very dangerous_ and is impossible to secure. Additionally, the `create_function()` function, which internally performs an `eval()`, is deprecated in PHP 7.2. Neither of these must be used.
572
572
573
573
### Error Control Operator `@`
574
574
@@ -584,6 +584,6 @@ While this operator does exist in Core, it is often used lazily instead of doing
584
584
585
585
Per [#22400](https://core.trac.wordpress.org/ticket/22400"Remove all, or at least most, uses of extract() within WordPress"):
586
586
587
-
> `extract()` is a terrible function that makes code harder to debug and harder to understand. We should discourage it's [sic] use and remove all of our uses of it.
587
+
> `extract()` is a terrible function that makes code harder to debug and harder to understand. We should discourage its (sic) use and remove all of our uses of it.
588
588
589
589
Joseph Scott has [a good write-up of why it's bad](https://blog.josephscott.org/2009/02/05/i-dont-like-phps-extract-function/).
0 commit comments