Skip to content

Commit 3c5f30b

Browse files
authored
Merge pull request #132 from craigfrancis/Issue-103
Update wpdb::prepare() placeholder notes
2 parents 79f8ab4 + 16e1a0e commit 3c5f30b

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

  • wordpress-coding-standards

wordpress-coding-standards/php.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -866,7 +866,14 @@ $id = some_foo_number(); // Data we expect to be an integer, but we're not certa
866866
$wpdb->query( $wpdb->prepare( "UPDATE $wpdb->posts SET post_title = %s WHERE ID = %d", $var, $id ) );
867867
```
868868

869-
`%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 it is easy to see at a glance whether something has been escaped or not because it happens right when the query happens.
869+
The following placeholders can be used in the query string:
870+
871+
- %d (integer)
872+
- %f (float)
873+
- %s (string)
874+
- %i (identifier, e.g. table/field names)
875+
876+
Note that these placeholders should not be 'quoted'! `$wpdb->prepare()` will take care of escaping and quoting for us. This makes it easy to see at a glance whether something has been escaped or not because it happens right when the query happens.
870877

871878
See [Data Validation](https://developer.wordpress.org/plugins/security/data-validation/) in the Plugin Handbook for further details.
872879

0 commit comments

Comments
 (0)