@@ -258,7 +258,7 @@ echo esc_html_x( $some_nasty_var, 'context' ); // Ok.
258258 <input type="hidden" name="some-action" value="<?php echo esc_attr_x ( 'none ' , 'context ' ); ?> " /><!-- OK. -->
259259<?php
260260
261- echo PHP_VERSION_ID , PHP_VERSION , PHP_EOL , PHP_EXTRA_VERSION ; // OK.
261+ echo PHP_VERSION_ID , PHP_VERSION , \ PHP_EOL , PHP_EXTRA_VERSION ; // OK.
262262
263263trigger_error ( 'DEBUG INFO - ' . __METHOD__ . '::internal_domains: domain = ' . $ domain ); // Bad.
264264Trigger_ERROR ( $ domain ); // Bad.
@@ -661,7 +661,7 @@ exit( status: esc_html( $foo ) ); // Ok.
661661die ( status: esc_html ( $ foo ) ); // Ok.
662662
663663exit ( status: $ foo ); // Bad.
664- die ( status: $ foo ); // Bad.
664+ \ die ( status: $ foo ); // Bad.
665665
666666/*
667667 * Issue https://github.com/WordPress/WordPress-Coding-Standards/issues/2552
@@ -687,3 +687,58 @@ _deprecated_function( __METHOD__, 'x.x.x', \ClassName::class ); // OK.
687687die ( \MyNamespace \ClassName::class . ' has been abandoned ' ); // OK.
688688echo 'Do not use ' . MyNamespace \ClassName::class; // OK.
689689_deprecated_function ( __METHOD__ , 'x.x.x ' , namespace \ClassName::class ); // OK.
690+
691+ /*
692+ * Safeguard correct handling of all types of namespaced escaping and printing function calls.
693+ */
694+ \printf ( 'Hello %s ' , $ foo ); // Bad.
695+ MyNamespace \printf ( 'Hello %s ' , $ foo ); // Ok.
696+ \MyNamespace \printf ( 'Hello %s ' , $ foo ); // Ok.
697+ namespace \printf ( 'Hello %s ' , $ foo ); // Ok.
698+ \printf ( 'Hello %s ' , \esc_html ( $ foo ) ); // Ok.
699+ \printf ( 'Hello %s ' , MyNamespace \esc_html ( $ foo ) ); // Bad.
700+ \printf ( 'Hello %s ' , \MyNamespace \esc_html ( $ foo ) ); // Bad.
701+ \printf ( 'Hello %s ' , namespace \esc_html ( $ foo ) ); // Bad.
702+
703+ /*
704+ * Safeguard correct handling of namespaced auto-escaped functions.
705+ */
706+ echo \bloginfo ( $ var ); // Ok.
707+ echo MyNamespace \bloginfo ( $ var ); // Bad.
708+ echo \MyNamespace \bloginfo ( $ var ); // Bad.
709+ echo namespace \bloginfo ( $ var ); // Bad.
710+
711+ /*
712+ * Safeguard correct handling of namespaced unsafe printing functions.
713+ */
714+ \_e ( $ text , 'my-domain ' ); // Bad.
715+ MyNamespace \_e ( $ text , 'my-domain ' ); // Ok.
716+ \MyNamespace \_e ( $ text , 'my-domain ' ); // Ok.
717+ namespace \_e ( $ text , 'my-domain ' ); // Ok.
718+
719+ /*
720+ * Safeguard correct handling of namespaced formatting functions.
721+ */
722+ echo \sprintf ( '%s ' , $ var ); // Bad.
723+ echo \sprintf ( '%s ' , esc_html ( $ var ) ); // Ok.
724+ echo MyNamespace \sprintf ( '%s ' , esc_html ( $ var ) ); // Bad.
725+ echo \MyNamespace \sprintf ( '%s ' , esc_html ( $ var ) ); // Bad.
726+ echo namespace \sprintf ( '%s ' , esc_html ( $ var ) ); // Bad.
727+
728+ /*
729+ * Safeguard correct handling of get_search_query() as the sniff has special logic to check the $escaped parameter.
730+ */
731+ echo \get_search_query ( true ); // Ok.
732+ echo \get_search_query ( false ); // Bad.
733+ echo MyNamespace \get_search_query ( true ); // Bad.
734+ echo \MyNamespace \get_search_query ( true ); // Bad.
735+ echo namespace \get_search_query ( true ); // Bad.
736+
737+ /*
738+ * Safeguard correct handling of fully qualified functions with special parameter handling.
739+ * These should still be recognized as WordPress functions and use their special logic.
740+ */
741+ \trigger_error ( 'This is fine ' ); // Ok.
742+ \trigger_error ( error_level: E_USER_NOTICE ); // Ok from the sniff perspective (required $message parameter missing, but that's not our concern)
743+ \trigger_error ( esc_html ( $ message ) ); // Ok.
744+ \trigger_error ( $ message ); // Bad.
0 commit comments