From 681ca37c6307fb79a3211e10208dd24531833aa0 Mon Sep 17 00:00:00 2001 From: Andrew Nacin Date: Mon, 17 Mar 2014 19:39:31 +0000 Subject: [PATCH] Return false from metadata_exists() if the get_$type_metadata filter returns a false value. props xknown. fixes #22746. git-svn-id: https://develop.svn.wordpress.org/trunk@27562 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/meta.php | 2 +- tests/phpunit/tests/meta.php | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/wp-includes/meta.php b/src/wp-includes/meta.php index e8bc2acdd3..dc19833612 100644 --- a/src/wp-includes/meta.php +++ b/src/wp-includes/meta.php @@ -323,7 +323,7 @@ function metadata_exists( $meta_type, $object_id, $meta_key ) { $check = apply_filters( "get_{$meta_type}_metadata", null, $object_id, $meta_key, true ); if ( null !== $check ) - return true; + return (bool) $check; $meta_cache = wp_cache_get( $object_id, $meta_type . '_meta' ); diff --git a/tests/phpunit/tests/meta.php b/tests/phpunit/tests/meta.php index d9e0e903dd..5d6413a5f6 100644 --- a/tests/phpunit/tests/meta.php +++ b/tests/phpunit/tests/meta.php @@ -83,6 +83,17 @@ class Tests_Meta extends WP_UnitTestCase { $this->assertFalse( metadata_exists( 'user', 1234567890, 'meta_key' ) ); } + /** + * @ticket 22746 + */ + function test_metadata_exists_with_filter() { + // Let's see if it returns the correct value when adding a filter. + add_filter( 'get_user_metadata', '__return_zero' ); + $this->assertFalse( metadata_exists( 'user', $this->author->ID, 'meta_key' ) ); // existing meta key + $this->assertFalse( metadata_exists( 'user', 1234567890, 'meta_key' ) ); + remove_filter( 'get_user_metadata', '__return_zero' ); + } + /** * @ticket 18158 */