WordPress.org

Make WordPress Core

Ticket #43561: 43561.diff

File 43561.diff, 1.5 KB (added by salcode, 3 years ago)

Patch with test.

  • src/wp-includes/meta.php

    diff --git src/wp-includes/meta.php src/wp-includes/meta.php
    index 010822fdc8..3f311bdb14 100644
    function delete_metadata_by_mid( $meta_type, $meta_id ) { 
    748748
    749749        // Fetch the meta and go on if it's found.
    750750        if ( $meta = get_metadata_by_mid( $meta_type, $meta_id ) ) {
    751                 $object_id = $meta->{$column};
     751                $object_id = (int) $meta->{$column};
    752752
    753753                /** This action is documented in wp-includes/meta.php */
    754754                do_action( "delete_{$meta_type}_meta", (array) $meta_id, $object_id, $meta->meta_key, $meta->meta_value );
  • tests/phpunit/tests/meta/deleteMetadata.php

    diff --git tests/phpunit/tests/meta/deleteMetadata.php tests/phpunit/tests/meta/deleteMetadata.php
    index 5527d1f02f..3b75aacdb5 100644
    class Tests_Meta_DeleteMetadata extends WP_UnitTestCase { 
    144144                $p2_cache = wp_cache_get( $p2, 'post_meta' );
    145145                $this->assertFalse( $p2_cache );
    146146        }
     147
     148        /**
     149         * @ticket 43561
     150         */
     151        public function test_object_id_is_int_inside_delete_post_meta() {
     152                $post_id = self::factory()->post->create();
     153                $meta_id = add_metadata( 'post', $post_id, 'my_key', 'my_value' );
     154                add_action( 'delete_post_meta', [ $this, 'action_check_object_id_is_int' ], 10, 2 );
     155                delete_metadata_by_mid( 'post', $meta_id );
     156        }
     157
     158        public function action_check_object_id_is_int( $meta_type, $object_id ) {
     159                $this->assertEquals(
     160                        'integer',
     161                        gettype( $object_id )
     162                );
     163        }
    147164}