Make WordPress Core

Opened 3 years ago

Last modified 3 years ago

#58993 new defect (bug)

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

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

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

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