Make WordPress Core

Opened 3 years ago

Closed 2 years ago

Last modified 2 years ago

#58992 closed defect (bug) (duplicate)

get_metadata_raw() "get_{$meta_type}_metadata" filter can return incorrect value for $single = true

Reported by: jsmoriss Owned by:
Priority: normal Milestone:
Component: Options, Meta APIs Version: 6.2.2
Severity: normal Keywords:
Cc: Focuses:

Description

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.

Change History (3)

#1 @sabernhardt
3 years ago

  • Component General → Options, Meta APIs

#2 @nowhaile
2 years ago

  • Resolution → duplicate
  • Status new → closed

Duplicate of #58249.

#3 @sabernhardt
2 years ago

  • Milestone Awaiting Review

Thanks for finding the earlier report!

Note: See TracTickets for help on using tickets.