-
-
Notifications
You must be signed in to change notification settings - Fork 490
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add documentation for WordPress.DB.RestrictedFunctions #2453
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,53 @@ | ||||||
<?xml version="1.0"?> | ||||||
<documentation xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||||||
xsi:noNamespaceSchemaLocation="https://phpcsstandards.github.io/PHPCSDevTools/phpcsdocs.xsd" | ||||||
title="Restricted Database Functions" | ||||||
> | ||||||
<standard> | ||||||
<![CDATA[ | ||||||
Avoid touching the database directly with PHP library functions. Use the $wpdb object and associated functions instead. | ||||||
]]> | ||||||
</standard> | ||||||
<code_comparison> | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you please reverse the examples ? The left side should always be the "Valid" code sample, the right side, the "Invalid" code sample. |
||||||
<code title="Invalid: Using MySQLi library to fetch posts"> | ||||||
<![CDATA[ | ||||||
$results = <em>mysqli_query</em>( | ||||||
$mysql, | ||||||
"SELECT * FROM wp_posts LIMIT 5" | ||||||
); | ||||||
]]> | ||||||
</code> | ||||||
<code title="Valid: Use WordPress functions"> | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
<![CDATA[ | ||||||
$results = <em>get_posts()</em>; | ||||||
]]> | ||||||
</code> | ||||||
</code_comparison> | ||||||
<code_comparison> | ||||||
<code title="Invalid: Using MySQLi library to insert a post"> | ||||||
<![CDATA[ | ||||||
<em>mysqli_query</em>( | ||||||
$mysql, | ||||||
"INSERT INTO wp_posts (post_title) | ||||||
VALUES ('Title')" | ||||||
); | ||||||
]]> | ||||||
</code> | ||||||
<code title="Valid: Use WordPress functions"> | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
<![CDATA[ | ||||||
<em>wp_insert_post</em>( | ||||||
array( 'post_title' => 'Title' ) | ||||||
); | ||||||
|
||||||
// or... | ||||||
|
||||||
global $wpdb; | ||||||
<em>$wpdb->insert</em>( | ||||||
"{$wpdb->prefix}_posts", | ||||||
array( 'post_title' => 'Title' ), | ||||||
array( '%s' ) | ||||||
); | ||||||
]]> | ||||||
</code> | ||||||
</code_comparison> | ||||||
</documentation> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The indentation should always be multiples of 4, so this should either have 8 spaces or 4 spaces indentation, not 6.