From 8af4ca2f4c01e3a3799330d5bf47d9d867e3f383 Mon Sep 17 00:00:00 2001 From: John Blackbourn Date: Thu, 28 Mar 2019 21:58:45 +0000 Subject: [PATCH] Options, Meta APIs: Ensure the `$object_id` parameter passed to the `delete_{$meta_type}_meta` and `deleted_{$meta_type}_meta` filters is always an integer. Props salcode Fixes #43561 git-svn-id: https://develop.svn.wordpress.org/trunk@45064 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/meta.php | 2 +- tests/phpunit/tests/meta/deleteMetadata.php | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/wp-includes/meta.php b/src/wp-includes/meta.php index 188d12f8c7..2332d9b5af 100644 --- a/src/wp-includes/meta.php +++ b/src/wp-includes/meta.php @@ -812,7 +812,7 @@ function delete_metadata_by_mid( $meta_type, $meta_id ) { // Fetch the meta and go on if it's found. if ( $meta = get_metadata_by_mid( $meta_type, $meta_id ) ) { - $object_id = $meta->{$column}; + $object_id = (int) $meta->{$column}; /** This action is documented in wp-includes/meta.php */ do_action( "delete_{$meta_type}_meta", (array) $meta_id, $object_id, $meta->meta_key, $meta->meta_value ); diff --git a/tests/phpunit/tests/meta/deleteMetadata.php b/tests/phpunit/tests/meta/deleteMetadata.php index 5527d1f02f..3b75aacdb5 100644 --- a/tests/phpunit/tests/meta/deleteMetadata.php +++ b/tests/phpunit/tests/meta/deleteMetadata.php @@ -144,4 +144,21 @@ class Tests_Meta_DeleteMetadata extends WP_UnitTestCase { $p2_cache = wp_cache_get( $p2, 'post_meta' ); $this->assertFalse( $p2_cache ); } + + /** + * @ticket 43561 + */ + public function test_object_id_is_int_inside_delete_post_meta() { + $post_id = self::factory()->post->create(); + $meta_id = add_metadata( 'post', $post_id, 'my_key', 'my_value' ); + add_action( 'delete_post_meta', [ $this, 'action_check_object_id_is_int' ], 10, 2 ); + delete_metadata_by_mid( 'post', $meta_id ); + } + + public function action_check_object_id_is_int( $meta_type, $object_id ) { + $this->assertEquals( + 'integer', + gettype( $object_id ) + ); + } }