|
1 | 1 | <?xml version="1.0"?> |
2 | 2 | <documentation xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
3 | 3 | xsi:noNamespaceSchemaLocation="https://phpcsstandards.github.io/PHPCSDevTools/phpcsdocs.xsd" |
4 | | - title="WordPress Alternative Functions" |
| 4 | + title="Alternative Functions" |
5 | 5 | > |
6 | 6 | <standard> |
7 | 7 | <![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. |
9 | 9 | ]]> |
10 | 10 | </standard> |
11 | 11 | <code_comparison> |
12 | | - <code title="Valid: Using wp_json_encode() to encode JSON data."> |
| 12 | + <code title="Valid: Using the WordPress alternatives."> |
13 | 13 | <![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 ); |
15 | 20 | ]]> |
16 | 21 | </code> |
17 | | - <code title="Invalid: Using PHP's json_encode() to encode JSON data."> |
| 22 | + <code title="Invalid: Using the discouraged PHP functions."> |
18 | 23 | <![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 ); |
72 | 30 | ]]> |
73 | 31 | </code> |
74 | 32 | </code_comparison> |
|
0 commit comments