From df427c78cb222a01dc3d24f487bc4e605a39e92e Mon Sep 17 00:00:00 2001 From: Pamela Ribeiro Date: Tue, 17 Sep 2024 17:10:03 -0700 Subject: [PATCH 1/5] WP/AlternativeFunctions: add XML documentation Co-authored-by: pamprn09 Co-authored-by: bhubbard --- .../Docs/WP/AlternativeFunctionsStandard.xml | 75 +++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 WordPress/Docs/WP/AlternativeFunctionsStandard.xml diff --git a/WordPress/Docs/WP/AlternativeFunctionsStandard.xml b/WordPress/Docs/WP/AlternativeFunctionsStandard.xml new file mode 100644 index 0000000000..d667a08a76 --- /dev/null +++ b/WordPress/Docs/WP/AlternativeFunctionsStandard.xml @@ -0,0 +1,75 @@ + + + + + + + + wp_json_encode( $data ); + ]]> + + + json_encode( $data ); + ]]> + + + + + + + + wp_remote_get( $url ); + ]]> + + + file_get_contents( $url ); + ]]> + + + + + + + + _e( 'Hello, World!', 'text-domain' ); +$hello = __( 'Hello, World!', 'text-domain' ); + ]]> + + + echo 'Hello, World!'; + ]]> + + + + + + + + echo esc_html( $user_input ); + ]]> + + + echo $user_input; + ]]> + + + From a1e0e5d86fedfb6a2cdee1fb69ba8583e463eeef Mon Sep 17 00:00:00 2001 From: Rodrigo Primo Date: Fri, 30 Jan 2026 09:23:34 -0300 Subject: [PATCH 2/5] 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. --- .../Docs/WP/AlternativeFunctionsStandard.xml | 74 ++++--------------- 1 file changed, 16 insertions(+), 58 deletions(-) diff --git a/WordPress/Docs/WP/AlternativeFunctionsStandard.xml b/WordPress/Docs/WP/AlternativeFunctionsStandard.xml index d667a08a76..177c8debd7 100644 --- a/WordPress/Docs/WP/AlternativeFunctionsStandard.xml +++ b/WordPress/Docs/WP/AlternativeFunctionsStandard.xml @@ -1,74 +1,32 @@ - + wp_json_encode( $data ); +$response = wp_remote_get( $url ); +$json = wp_json_encode( $data ); +$parts = wp_parse_url( $url ); +$text = wp_strip_all_tags( $html ); +$number = wp_rand( 1, 100 ); +$deleted = wp_delete_file( $file ); ]]> - + json_encode( $data ); - ]]> - - - - - - - - wp_remote_get( $url ); - ]]> - - - file_get_contents( $url ); - ]]> - - - - - - - - _e( 'Hello, World!', 'text-domain' ); -$hello = __( 'Hello, World!', 'text-domain' ); - ]]> - - - echo 'Hello, World!'; - ]]> - - - - - - - - echo esc_html( $user_input ); - ]]> - - - echo $user_input; +$response = file_get_contents( $url ); +$json = json_encode( $data ); +$parts = parse_url( $url ); +$text = strip_tags( $html ); +$number = rand( 1, 100 ); +$deleted = unlink( $file ); ]]> From 89b4c19b1df5c3c9fcef5ab82ef5dd155048e256 Mon Sep 17 00:00:00 2001 From: Rodrigo Primo Date: Tue, 3 Feb 2026 11:33:16 -0300 Subject: [PATCH 3/5] Use a single code comparison with one representative example --- WordPress/Docs/WP/AlternativeFunctionsStandard.xml | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/WordPress/Docs/WP/AlternativeFunctionsStandard.xml b/WordPress/Docs/WP/AlternativeFunctionsStandard.xml index 177c8debd7..9758ac636a 100644 --- a/WordPress/Docs/WP/AlternativeFunctionsStandard.xml +++ b/WordPress/Docs/WP/AlternativeFunctionsStandard.xml @@ -9,24 +9,14 @@ ]]> - + wp_remote_get( $url ); -$json = wp_json_encode( $data ); -$parts = wp_parse_url( $url ); -$text = wp_strip_all_tags( $html ); -$number = wp_rand( 1, 100 ); -$deleted = wp_delete_file( $file ); ]]> - + file_get_contents( $url ); -$json = json_encode( $data ); -$parts = parse_url( $url ); -$text = strip_tags( $html ); -$number = rand( 1, 100 ); -$deleted = unlink( $file ); ]]> From ebc0db8a4b2a095761d8838c76637c4c0e19009d Mon Sep 17 00:00:00 2001 From: Rodrigo Primo Date: Thu, 5 Feb 2026 15:42:28 -0300 Subject: [PATCH 4/5] Explain why WP alternatives should be preferred in the standard description --- WordPress/Docs/WP/AlternativeFunctionsStandard.xml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/WordPress/Docs/WP/AlternativeFunctionsStandard.xml b/WordPress/Docs/WP/AlternativeFunctionsStandard.xml index 9758ac636a..474f4f46ac 100644 --- a/WordPress/Docs/WP/AlternativeFunctionsStandard.xml +++ b/WordPress/Docs/WP/AlternativeFunctionsStandard.xml @@ -6,6 +6,8 @@ From 290ac34994a7e5c388522feff23a82727c02d999 Mon Sep 17 00:00:00 2001 From: Rodrigo Primo Date: Mon, 23 Feb 2026 15:01:23 -0300 Subject: [PATCH 5/5] Use an unconditionally flagged function in the code example Replace the file_get_contents()/wp_remote_get() example with mt_rand()/wp_rand() as suggested during the review of the PR. --- WordPress/Docs/WP/AlternativeFunctionsStandard.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/WordPress/Docs/WP/AlternativeFunctionsStandard.xml b/WordPress/Docs/WP/AlternativeFunctionsStandard.xml index 474f4f46ac..bf2f5f3a95 100644 --- a/WordPress/Docs/WP/AlternativeFunctionsStandard.xml +++ b/WordPress/Docs/WP/AlternativeFunctionsStandard.xml @@ -13,12 +13,12 @@ wp_remote_get( $url ); +$number = wp_rand( 1, 100 ); ]]> file_get_contents( $url ); +$number = mt_rand( 1, 100 ); ]]>