Skip to content

Commit 40fae80

Browse files
committed
Apply suggestion made during PR review
- Swap "Valid" and "Invalid" blocks. - Add periods to titles and make them more descriptive. - Highlight class instantiation, not method calls. - Fix incorrect `$mysqli->query()` call that had extra argument. - Change `{$wpdb->prefix}_posts` to `$wpdb->posts`. - Remove trailing whitespace. - Add trailing newline. - Simplify standard description by removing "and methods". - Fix indentation of <standard> description.
1 parent 4b2fd2c commit 40fae80

File tree

1 file changed

+36
-37
lines changed

1 file changed

+36
-37
lines changed
Lines changed: 36 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,66 @@
11
<?xml version="1.0"?>
22
<documentation xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
33
xsi:noNamespaceSchemaLocation="https://phpcsstandards.github.io/PHPCSDevTools/phpcsdocs.xsd"
4-
title="Restricted Database Classes and Methods"
4+
title="Restricted Database Classes"
55
>
66
<standard>
77
<![CDATA[
8-
Avoid touching the database directly with PHP library classes and methods. Use the $wpdb object and associated functions instead.
8+
Avoid touching the database directly with PHP library classes. Use the $wpdb object and associated functions instead.
99
]]>
1010
</standard>
1111
<code_comparison>
12-
<code title="Invalid: Using the object-orientated mysqli interface">
12+
<code title="Valid: Using a WordPress function to fetch posts.">
1313
<![CDATA[
14-
$mysqli = new mysqli(
15-
"example.com",
16-
$db_user,
17-
$db_pass,
18-
$db_name
19-
);
20-
21-
$result = <em>$mysqli->query</em>(
22-
$mysqli,
23-
"SELECT * FROM wp_posts LIMIT 5"
24-
);
25-
]]>
26-
</code>
27-
<code title="Valid: Use WordPress functions">
28-
<![CDATA[
29-
$result = <em>get_posts()</em>;
14+
$results = <em>get_posts()</em>;
3015
]]>
3116
</code>
32-
</code_comparison>
33-
<code_comparison>
34-
<code title="Invalid: Using the object-orientated PDO and PDOStatement interfaces to insert a post">
17+
<code title="Invalid: Using the mysqli class to fetch posts.">
3518
<![CDATA[
36-
$pdo = new PDO(
37-
$dsn,
38-
$db_user,
39-
$db_pass
19+
$mysqli = <em>new mysqli</em>(
20+
'localhost',
21+
$user,
22+
$pass,
23+
$db
4024
);
4125
42-
$stmnt = $pdo->prepare(
43-
"INSERT INTO wp_posts (post_title)
44-
VALUES (?)"
26+
$results = $mysqli->query(
27+
"SELECT * FROM wp_posts LIMIT 5"
4528
);
46-
47-
$stmnt->execute( ['Title'] );
4829
]]>
4930
</code>
50-
<code title="Valid: Use WordPress functions">
31+
</code_comparison>
32+
<code_comparison>
33+
<code title="Valid: Using WordPress functions to insert a post.">
5134
<![CDATA[
52-
<em>wp_insert_post</em>(
35+
<em>wp_insert_post</em>(
5336
array( 'post_title' => 'Title' )
5437
);
5538
5639
// or...
5740
5841
global $wpdb;
59-
<em>$wpdb->insert</em>(
60-
"{$wpdb->prefix}_posts",
42+
<em>$wpdb->insert</em>(
43+
$wpdb->posts,
6144
array( 'post_title' => 'Title' ),
62-
array( '%s' )
45+
array( '%s' )
46+
);
47+
]]>
48+
</code>
49+
<code title="Invalid: Using PDO class to insert a post.">
50+
<![CDATA[
51+
$pdo = <em>new PDO</em>(
52+
$dsn,
53+
$user,
54+
$pass
6355
);
56+
57+
$stmt = $pdo->prepare(
58+
"INSERT INTO wp_posts (post_title)
59+
VALUES (?)"
60+
);
61+
62+
$stmt->execute( array( 'Title' ) );
6463
]]>
6564
</code>
6665
</code_comparison>
67-
</documentation>
66+
</documentation>

0 commit comments

Comments
 (0)