WordPress.org

Make WordPress Core

Changeset 27562


Ignore:
Timestamp:
03/17/2014 07:39:31 PM (7 years ago)
Author:
nacin
Message:

Return false from metadata_exists() if the get_$type_metadata filter returns a false value.

props xknown.
fixes #22746.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/meta.php

    r27191 r27562  
    324324    $check = apply_filters( "get_{$meta_type}_metadata", null, $object_id, $meta_key, true );
    325325    if ( null !== $check )
    326         return true;
     326        return (bool) $check;
    327327
    328328    $meta_cache = wp_cache_get( $object_id, $meta_type . '_meta' );
  • trunk/tests/phpunit/tests/meta.php

    r26307 r27562  
    8282        $this->assertFalse( metadata_exists( 'user',  1234567890, 'foobarbaz' ) );
    8383        $this->assertFalse( metadata_exists( 'user',  1234567890, 'meta_key' ) );
     84    }
     85
     86    /**
     87     * @ticket 22746
     88     */
     89    function test_metadata_exists_with_filter() {
     90        // Let's see if it returns the correct value when adding a filter.
     91        add_filter( 'get_user_metadata', '__return_zero' );
     92        $this->assertFalse( metadata_exists( 'user', $this->author->ID, 'meta_key' ) ); // existing meta key
     93        $this->assertFalse( metadata_exists( 'user', 1234567890, 'meta_key' ) );
     94        remove_filter( 'get_user_metadata', '__return_zero' );
    8495    }
    8596
Note: See TracChangeset for help on using the changeset viewer.