[wp-trac] [WordPress Trac] #58992: get_metadata_raw() "get_{$meta_type}_metadata" filter can return incorrect value for $single = true

WordPress Trac noreply at wordpress.org
Mon Aug 7 14:52:21 UTC 2023


#58992: get_metadata_raw() "get_{$meta_type}_metadata" filter can return incorrect
value for $single = true
--------------------------+-----------------------------
 Reporter:  jsmoriss      |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  General       |    Version:  6.2.2
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 The "get_{$meta_type}_metadata" filter includes the $single argument for
 the filter to return a single element or the complete metadata array. **If
 the single element happens to be an array**, and that array is returned
 because $single = true, then **the following code breaks the returned
 value** (it returns the first element instead of the array). If the array
 is an associative array, then it also breaks the returned value as
 `$check[0]` is not a valid element.

 {{{
         $check = apply_filters( "get_{$meta_type}_metadata", null,
 $object_id, $meta_key, $single, $meta_type );
         if ( null !== $check ) {
                 if ( $single && is_array( $check ) ) {
                         return $check[0];
                 } else {
                         return $check;
                 }
         }
 }}}

 Since $single is provided to the filter, the code should respect the
 returned value:

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

 js.

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


More information about the wp-trac mailing list