#43561 closed defect (bug) (fixed)
$object_id parameter is string instead of integer in delete_{$meta_type}_meta inside delete_metadata_by_mid()
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | 5.2 | Priority: | normal |
Severity: | normal | Version: | |
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)
Change History (8)
#2
@
7 years ago
- Component changed from General to Options, Meta APIs
- Keywords has-patch added
- Milestone changed from Awaiting Review to 5.0
#4
@
6 years ago
- Milestone changed from 5.1 to 5.2
- Version trunk deleted
This patch needs further investigation and a decision. We've had weird side effect issues in the past when changing the type of a parameter.
#5
@
6 years ago
- Owner set to johnbillion
- Status changed from new to accepted
This change makes sense.
The delete_{$meta_type}_meta
action documents its $object_id
parameter as an integer. Inside delete_metadata()
it gets cast to an integer, but inside delete_metadata_by_mid()
it doesn't, and remains a string. The same goes for the subsequent deleted_{$meta_type}_meta
action.
The only place the $object_id
variable gets used in delete_metadata_by_mid()
is in the call to wp_cache_delete()
, in which case it's a benefit to ensure that the object key is also an integer so its type matches the key used in delete_metadata()
.
This means that casting $object_id
to an integer inside delete_metadata_by_mid()
is safe and correct.
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
And I've added a patch to cast
$object_id
to anint
in d70e520eea