@@ -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,68 @@ _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 \wp_die ( $ message ); // Ok.
696+ \MyNamespace \vprintf ( 'Hello %s ' , array ( $ foo ) ); // Ok.
697+ namespace \wp_dropdown_pages ( $ args ); // Ok. The sniff should start flagging this once it can resolve relative namespaces.
698+ namespace \Sub \_deprecated_function ( __FUNCTION__ , '1.3.0 ' , $ another_func ); // Ok.
699+ \printf ( 'Hello %s ' , \esc_html ( $ foo ) ); // Ok.
700+ \wp_die ( MyNamespace \number_format ( $ foo ) ); // Bad.
701+ \vprintf ( 'Hello %s ' , array ( \MyNamespace \sanitize_user_field ( $ foo ) ) ); // Bad.
702+ \wp_dropdown_pages ( namespace \sanitize_key ( $ foo ) ); // Bad. The sniff should stop flagging this once it can resolve relative namespaces.
703+ \_deprecated_function ( __FUNCTION__ , '1.3.0 ' , namespace \Sub \wp_kses ( $ another_func ) ); // Bad.
704+
705+ /*
706+ * Safeguard correct handling of namespaced auto-escaped functions.
707+ */
708+ echo \bloginfo ( $ var ); // Ok.
709+ echo MyNamespace \count ( $ var ); // Bad.
710+ echo \MyNamespace \get_archives_link ( $ url , 'link ' ); // Bad.
711+ echo namespace \get_search_form (); // Bad. The sniff should stop flagging this once it can resolve relative namespaces.
712+ echo namespace \Sub \the_author (); // Bad.
713+
714+ /*
715+ * Safeguard correct handling of namespaced unsafe printing functions.
716+ */
717+ \_e ( $ text , 'my-domain ' ); // Bad.
718+ MyNamespace \_ex ( $ text , 'context ' ); // Ok.
719+ \MyNamespace \_e ( $ text , 'my-domain ' ); // Ok.
720+ namespace \_ex ( $ text , 'context ' ); // Ok. The sniff should start flagging this once it can resolve relative namespaces.
721+ namespace \Sub \_e ( $ text , 'my-domain ' ); // Ok.
722+
723+ /*
724+ * Safeguard correct handling of namespaced formatting functions.
725+ */
726+ echo \sprintf ( '%s ' , $ var ); // Bad.
727+ echo \sprintf ( '%s ' , esc_html ( $ var ) ); // Ok.
728+ echo MyNamespace \antispambot ( esc_html ( $ email ) ); // Bad.
729+ echo \MyNamespace \ent2ncr ( esc_html ( $ _data ) ); // Bad.
730+ echo namespace \vsprintf ( 'Hello %s ' , array ( esc_html ( $ foo ) ) ); // Bad. The sniff should stop flagging this once it can resolve relative namespaces.
731+ echo namespace \Sub \wp_sprintf ( 'Hello %s ' , array ( esc_html ( $ foo ) ) ); // Bad.
732+
733+ /*
734+ * Safeguard correct handling of get_search_query() as the sniff has special logic to check the $escaped parameter.
735+ */
736+ echo \get_search_query ( true ); // Ok.
737+ echo \get_search_query ( false ); // Bad.
738+ echo MyNamespace \get_search_query ( true ); // Bad.
739+ echo \MyNamespace \get_search_query ( true ); // Bad.
740+ echo namespace \get_search_query ( true ); // Bad. The sniff should stop flagging this once it can resolve relative namespaces.
741+ echo namespace \Sub \get_search_query ( true ); // Bad.
742+
743+ /*
744+ * Safeguard correct handling of fully qualified and namespace relative functions with special parameter handling.
745+ */
746+ \trigger_error ( esc_html ( $ message ), $ second_param_should_be_ignored ); // Ok.
747+ \User_Error ( $ message ); // Bad.
748+ namespace \trigger_error ( $ message ); // Ok. The sniff should start flagging this once it can resolve relative namespaces.
749+ namespace \Sub \user_error ( $ message ); // Ok.
750+ \_deprecated_file ( basename ( __FILE__ ), '1.3.0 ' ); // Ok.
751+ \_deprecated_file ( $ file , '1.3.0 ' ); // Error.
752+ namespace \_deprecated_file ( basename ( __FILE__ ), '1.3.0 ' ); // Ok.
753+ namespace \_DEPRECATED_FILE ( $ file , '1.3.0 ' ); // Ok. The sniff should start flagging this once it can resolve relative namespaces.
754+ namespace \Sub \_deprecated_file ( $ file , '1.3.0 ' ); // Ok.
0 commit comments