File tree 1 file changed +53
-0
lines changed
1 file changed +53
-0
lines changed Original file line number Diff line number Diff line change
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 =" Invalid: Using MySQLi library to fetch posts" >
13
+ <![CDATA[
14
+ $results = <em>mysqli_query</em>(
15
+ $mysql,
16
+ "SELECT * FROM wp_posts LIMIT 5"
17
+ );
18
+ ]]>
19
+ </code >
20
+ <code title =" Valid: Use WordPress functions" >
21
+ <![CDATA[
22
+ $results = <em>get_posts()</em>;
23
+ ]]>
24
+ </code >
25
+ </code_comparison >
26
+ <code_comparison >
27
+ <code title =" Invalid: Using MySQLi library to insert a post" >
28
+ <![CDATA[
29
+ <em>mysqli_query</em>(
30
+ $mysql,
31
+ "INSERT INTO wp_posts (post_title)
32
+ VALUES ('Title')"
33
+ );
34
+ ]]>
35
+ </code >
36
+ <code title =" Valid: Use WordPress functions" >
37
+ <![CDATA[
38
+ <em>wp_insert_post</em>(
39
+ array( 'post_title' => 'Title' )
40
+ );
41
+
42
+ // or...
43
+
44
+ global $wpdb;
45
+ <em>$wpdb->insert</em>(
46
+ "{$wpdb->prefix}_posts",
47
+ array( 'post_title' => 'Title' ),
48
+ array( '%s' )
49
+ );
50
+ ]]>
51
+ </code >
52
+ </code_comparison >
53
+ </documentation >
You can’t perform that action at this time.
0 commit comments