Make WordPress Core

Opened 12 months ago

Last modified 9 months ago

#58993 new defect (bug)

metadata_exists() returns incorrect value when "get_{$meta_type}_metadata" filter returns false.

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

Description

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.

Change History (1)

#1 @sabernhardt
9 months ago

  • Component changed from General to Options, Meta APIs
Note: See TracTickets for help on using tickets.