Meta: Improve ID casting when getting, updating or deleting meta data.

Blindly casting IDs to absolute integers in `get_metadata_by_mid()`, `update_metadata_by_mid()` and `delete_metadata_by_mid()` can cause unexpected behaviour when a floating or negative number is passed.

Fixes #37746.

Built from https://develop.svn.wordpress.org/trunk@38699


git-svn-id: http://core.svn.wordpress.org/trunk@38642 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Peter Wilson 2016-10-01 06:28:30 +00:00
parent b84023ea33
commit 3c814b5468
2 changed files with 10 additions and 10 deletions

View File

@ -567,12 +567,12 @@ function metadata_exists( $meta_type, $object_id, $meta_key ) {
function get_metadata_by_mid( $meta_type, $meta_id ) {
global $wpdb;
if ( ! $meta_type || ! is_numeric( $meta_id ) ) {
if ( ! $meta_type || ! is_numeric( $meta_id ) || floor( $meta_id ) != $meta_id ) {
return false;
}
$meta_id = absint( $meta_id );
if ( ! $meta_id ) {
$meta_id = intval( $meta_id );
if ( $meta_id <= 0 ) {
return false;
}
@ -611,12 +611,12 @@ function update_metadata_by_mid( $meta_type, $meta_id, $meta_value, $meta_key =
global $wpdb;
// Make sure everything is valid.
if ( ! $meta_type || ! is_numeric( $meta_id ) ) {
if ( ! $meta_type || ! is_numeric( $meta_id ) || floor( $meta_id ) != $meta_id ) {
return false;
}
$meta_id = absint( $meta_id );
if ( ! $meta_id ) {
$meta_id = intval( $meta_id );
if ( $meta_id <= 0 ) {
return false;
}
@ -702,12 +702,12 @@ function delete_metadata_by_mid( $meta_type, $meta_id ) {
global $wpdb;
// Make sure everything is valid.
if ( ! $meta_type || ! is_numeric( $meta_id ) ) {
if ( ! $meta_type || ! is_numeric( $meta_id ) || floor( $meta_id ) != $meta_id ) {
return false;
}
$meta_id = absint( $meta_id );
if ( ! $meta_id ) {
$meta_id = intval( $meta_id );
if ( $meta_id <= 0 ) {
return false;
}

View File

@ -4,7 +4,7 @@
*
* @global string $wp_version
*/
$wp_version = '4.7-alpha-38698';
$wp_version = '4.7-alpha-38699';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.