Skip to content

Commit e69282e

Browse files
committed
Apply changes suggested during PR review and a few more
This commit makes a few changes to the original commit that suggested adding documentation for `AlternativeFunctions`: - Use a single generic description without specific reasons, as the reasons vary by function and may change as new functions are added. - Remove the translation and escaping examples, which are not flagged by this sniff. - Include a few examples using the main "categories" of functions flagged by the sniff, without including every single group to avoid having too many examples. - Use generic titles for the code comparison blocks.
1 parent 2c48e09 commit e69282e

File tree

1 file changed

+16
-58
lines changed

1 file changed

+16
-58
lines changed

WordPress/Docs/WP/AlternativeFunctionsStandard.xml

Lines changed: 16 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,32 @@
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="WordPress Alternative Functions"
4+
title="Alternative Functions"
55
>
66
<standard>
77
<![CDATA[
8-
Use WordPress functions instead of native PHP functions to maintain compatibility and benefit from WordPress's additional security and performance improvements.
8+
Use WordPress functions instead of certain native PHP functions.
99
]]>
1010
</standard>
1111
<code_comparison>
12-
<code title="Valid: Using wp_json_encode() to encode JSON data.">
12+
<code title="Valid: Using the WordPress alternatives.">
1313
<![CDATA[
14-
<em>wp_json_encode( $data );</em>
14+
$response = <em>wp_remote_get</em>( $url );
15+
$json = <em>wp_json_encode</em>( $data );
16+
$parts = <em>wp_parse_url</em>( $url );
17+
$text = <em>wp_strip_all_tags</em>( $html );
18+
$number = <em>wp_rand</em>( 1, 100 );
19+
$deleted = <em>wp_delete_file</em>( $file );
1520
]]>
1621
</code>
17-
<code title="Invalid: Using PHP's json_encode() to encode JSON data.">
22+
<code title="Invalid: Using the discouraged PHP functions.">
1823
<![CDATA[
19-
<em>json_encode( $data );</em>
20-
]]>
21-
</code>
22-
</code_comparison>
23-
<standard>
24-
<![CDATA[
25-
WordPress provides the wp_remote_* functions for making HTTP requests. Avoid using file_get_contents() or cURL directly.
26-
]]>
27-
</standard>
28-
<code_comparison>
29-
<code title="Valid: Using wp_remote_get() for HTTP requests.">
30-
<![CDATA[
31-
$response = <em>wp_remote_get( $url );</em>
32-
]]>
33-
</code>
34-
<code title="Invalid: Using file_get_contents() for HTTP requests.">
35-
<![CDATA[
36-
$response = <em>file_get_contents( $url );</em>
37-
]]>
38-
</code>
39-
</code_comparison>
40-
<standard>
41-
<![CDATA[
42-
Use WordPress's translation functions to ensure text is translatable and localized.
43-
]]>
44-
</standard>
45-
<code_comparison>
46-
<code title="Valid: Using _e() or __() for translatable text.">
47-
<![CDATA[
48-
<em>_e( 'Hello, World!', 'text-domain' );</em>
49-
$hello = <em>__( 'Hello, World!', 'text-domain' );</em>
50-
]]>
51-
</code>
52-
<code title="Invalid: Echoing plain text strings.">
53-
<![CDATA[
54-
<em>echo 'Hello, World!';</em>
55-
]]>
56-
</code>
57-
</code_comparison>
58-
<standard>
59-
<![CDATA[
60-
Always use WordPress functions for escaping output to prevent XSS vulnerabilities.
61-
]]>
62-
</standard>
63-
<code_comparison>
64-
<code title="Valid: Using esc_html() to escape HTML output.">
65-
<![CDATA[
66-
<em>echo esc_html( $user_input );</em>
67-
]]>
68-
</code>
69-
<code title="Invalid: Outputting user input without escaping.">
70-
<![CDATA[
71-
<em>echo $user_input;</em>
24+
$response = <em>file_get_contents</em>( $url );
25+
$json = <em>json_encode</em>( $data );
26+
$parts = <em>parse_url</em>( $url );
27+
$text = <em>strip_tags</em>( $html );
28+
$number = <em>rand</em>( 1, 100 );
29+
$deleted = <em>unlink</em>( $file );
7230
]]>
7331
</code>
7432
</code_comparison>

0 commit comments

Comments
 (0)