WordPress.org

Make WordPress Core

Opened 3 months ago

Last modified 3 months ago

#43561 new defect (bug)

$object_id parameter is string instead of integer in delete_{$meta_type}_meta inside delete_metadata_by_mid()

Reported by: salcode Owned by:
Milestone: 5.0 Priority: normal
Severity: normal Version: trunk
Component: Options, Meta APIs Keywords: has-patch
Focuses: Cc:

Description

In wp-includes/meta.php inside the function delete_metadata_by_mid() the hook do_action( "delete_{$meta_type}_meta" ) is called.

While not documented here, earlier in the same same file this hook also appears and is documented as

 * @param null|bool $delete     Whether to allow metadata deletion of the given type.
 * @param int       $object_id  Object ID.
 * @param string    $meta_key   Meta key.
 * @param mixed     $meta_value Meta value. Must be serializable if non-scalar.
 * @param bool      $delete_all Whether to delete the matching metadata entries
 *                              for all objects, ignoring the specified $object_id.
 *                              Default false.

however when the hook is called inside delete_metadata_by_mid() the $object_id is passed as a string not an int.

It looks like this happens inside delete_metadata_by_mid() because $object_id is defined in these lines

if ( $meta = get_metadata_by_mid( $meta_type, $meta_id ) ) {
	$object_id = $meta->{$column};

Attachments (1)

43561.diff (1.5 KB) - added by salcode 3 months ago.
Patch with test.

Download all attachments as: .zip

Change History (3)

#1 @salcode
3 months ago

I've made this branch on GitHub we're I'm looking into this, sf/object-id-string-not-int-43561

I've added a failing test in b848118 to illustrate the problem.

Here is the result of the test

1) Tests_Meta_DeleteMetadata::test_object_id_is_int_inside_delete_post_meta
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-'integer'
+'string'

And I've added a patch to cast $object_id to an int in d70e520eea

@salcode
3 months ago

Patch with test.

#2 @SergeyBiryukov
3 months ago

  • Component changed from General to Options, Meta APIs
  • Keywords has-patch added
  • Milestone changed from Awaiting Review to 5.0
Note: See TracTickets for help on using tickets.