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
This commit is contained in:
John Blackbourn 2019-03-28 21:58:45 +00:00
parent 502784dbd1
commit 8af4ca2f4c
2 changed files with 18 additions and 1 deletions

View File

@ -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 );

View File

@ -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 )
);
}
}