Make WordPress Core

Opened 3 years ago

Closed 19 months ago

Last modified 19 months ago

#58992 closed defect (bug) (duplicate)

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

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

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
2 years ago

  • Component changed from General to Options, Meta APIs

#2 @nowhaile
19 months ago

  • Resolution set to duplicate
  • Status changed from new to closed

Duplicate of #58249.

#3 @sabernhardt
19 months ago

  • Milestone Awaiting Review deleted

Thanks for finding the earlier report!

Note: See TracTickets for help on using tickets.