Skip to content

Commit da8f3b2

Browse files
authored
Merge pull request #2676 from rodrigoprimo/docs-restricted-functions
DB/RestrictedFunctions: add XML documentation
2 parents 2f331db + 86ea20d commit da8f3b2

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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="Restricted Database Functions"
5+
>
6+
<standard>
7+
<![CDATA[
8+
Avoid touching the database directly with PHP library functions. Use the $wpdb object and associated functions instead.
9+
]]>
10+
</standard>
11+
<code_comparison>
12+
<code title="Valid: Using a WordPress function to fetch posts.">
13+
<![CDATA[
14+
$results = <em>get_posts()</em>;
15+
]]>
16+
</code>
17+
<code title="Invalid: Using the MySQLi library to fetch posts.">
18+
<![CDATA[
19+
$results = <em>mysqli_query</em>(
20+
$mysql,
21+
"SELECT * FROM wp_posts LIMIT 5"
22+
);
23+
]]>
24+
</code>
25+
</code_comparison>
26+
<code_comparison>
27+
<code title="Valid: Using WordPress functions to insert a post.">
28+
<![CDATA[
29+
<em>wp_insert_post</em>(
30+
array( 'post_title' => 'Title' )
31+
);
32+
33+
// or...
34+
35+
global $wpdb;
36+
<em>$wpdb->insert</em>(
37+
$wpdb->posts,
38+
array( 'post_title' => 'Title' ),
39+
array( '%s' )
40+
);
41+
]]>
42+
</code>
43+
<code title="Invalid: Using MySQLi library to insert a post.">
44+
<![CDATA[
45+
<em>mysqli_query</em>(
46+
$mysql,
47+
"INSERT INTO wp_posts (post_title)
48+
VALUES ('Title')"
49+
);
50+
]]>
51+
</code>
52+
</code_comparison>
53+
</documentation>

0 commit comments

Comments
 (0)