[wp-trac] [WordPress Trac] #63854: Handle a non-string passed to WP_HTML_Tag_Processor gracefully

WordPress Trac noreply at wordpress.org
Wed Aug 20 22:19:25 UTC 2025


#63854: Handle a non-string passed to WP_HTML_Tag_Processor gracefully
--------------------------------------+---------------------
 Reporter:  kraftbj                   |       Owner:  (none)
     Type:  defect (bug)              |      Status:  new
 Priority:  normal                    |   Milestone:  6.9
Component:  HTML API                  |     Version:  6.2
 Severity:  normal                    |  Resolution:
 Keywords:  has-patch has-unit-tests  |     Focuses:
--------------------------------------+---------------------

Comment (by westonruter):

 What is the function/method that is constructing `WP_HTML_Tag_Processor`
 which is passing `null` to begin with?

 Personally I advocate to always start filter code with a type check since
 plugins can do bad things with violating the "contract" for the filtered
 value's type. In other words, I do the same thing as you propose, but in
 the filter callback:

 {{{#!php
 <?php
 add_filter( 'the_content', function ( $value ) {
     if ( ! is_string( $value ) ) {
         $value = '';
     }
     // ...
     return $value;
 } );
 }}}

 That's not to exclude what you're proposing in your PR.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/63854#comment:2>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list