[wp-trac] [WordPress Trac] #58993: metadata_exists() returns incorrect value when "get_{$meta_type}_metadata" filter returns false.

WordPress Trac noreply at wordpress.org
Mon Aug 7 14:58:38 UTC 2023


#58993: metadata_exists() returns incorrect value when "get_{$meta_type}_metadata"
filter returns false.
--------------------------+-----------------------------
 Reporter:  jsmoriss      |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  General       |    Version:  6.2.2
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 metadata_exists() applies the "get_{$meta_type}_metadata" filter. If the
 $single metadata value is false, 0, an empty string, or an empty array
 (see https://www.php.net/manual/en/language.types.boolean.php), then
 metadata_exists() will return false instead of true (ie. the metadata
 exists).


 {{{
 function metadata_exists( $meta_type, $object_id, $meta_key ) {
 .
 .
 .
         $check = apply_filters( "get_{$meta_type}_metadata", null,
 $object_id, $meta_key, true, $meta_type );
         if ( null !== $check ) {
                 return (bool) $check;
         }
 }}}

 If any value is returned, then the metadata exists, so the code should be:

 {{{
 function metadata_exists( $meta_type, $object_id, $meta_key ) {
 .
 .
 .
         $check = apply_filters( "get_{$meta_type}_metadata", null,
 $object_id, $meta_key, true, $meta_type );
         if ( null !== $check ) {
                 return true;
         }
 }}}

 js.

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


More information about the wp-trac mailing list