[wp-trac] [WordPress Trac] #48843: wpdb::placeholder_escape fails to conditionally add a remove_placeholder_escape hook to query

WordPress Trac noreply at wordpress.org
Sat Nov 30 23:31:44 UTC 2019


#48843: wpdb::placeholder_escape fails to conditionally add a
remove_placeholder_escape hook to query
--------------------------+-----------------------------
 Reporter:  pcfreak30     |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Database      |    Version:  4.8.3
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 Found this edge case issue while doing some hacking around the wp hook
 structures/API.


 You have:

 {{{#!php
 <?php
 if ( ! has_filter( 'query', array( $this, 'remove_placeholder_escape' ) )
 ) {
                         add_filter( 'query', array( $this,
 'remove_placeholder_escape' ), 0 );
                 }
 }}}

 However, has_filter returns the priority of hook if it exists, which
 happens to be 0... 0 is falsely in PHP, so every call to
 placeholder_escape re-sets the array hook ad add_filter doesn't do an
 exists check, and not sure it even should?

 Since we are adding to a priority 0, we need to do a strict {{{#!php false
 !== }}}.

 I will probably submit a patch shortly.

 The function in question was committed with the bug in ticket #41925.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/48843>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list