From 11226f02a8248016d082ca35987bf4d03c8d50e9 Mon Sep 17 00:00:00 2001 From: Boone Gorges Date: Fri, 1 May 2015 16:38:29 +0000 Subject: [PATCH] Allow metadata to be deleted when meta_value matches 0 or '0'. In `delete_metadata()`, be stricter about when to ignore a falsey value of `$meta_value`. For backward compatibility, an empty string for `$meta_value` is equivalent to `null` or `false`. Props sc0ttkclark. Fixes #32224. Built from https://develop.svn.wordpress.org/trunk@32331 git-svn-id: http://core.svn.wordpress.org/trunk@32302 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/meta.php | 21 ++++++++++++--------- wp-includes/version.php | 2 +- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/wp-includes/meta.php b/wp-includes/meta.php index b57e761f46..bcfc847e80 100644 --- a/wp-includes/meta.php +++ b/wp-includes/meta.php @@ -294,14 +294,17 @@ function update_metadata($meta_type, $object_id, $meta_key, $meta_value, $prev_v * * @global wpdb $wpdb WordPress database abstraction object. * - * @param string $meta_type Type of object metadata is for (e.g., comment, post, or user) - * @param int $object_id ID of the object metadata is for - * @param string $meta_key Metadata key - * @param mixed $meta_value Optional. Metadata value. Must be serializable if non-scalar. If specified, only delete metadata entries - * with this value. Otherwise, delete all entries with the specified meta_key. - * @param bool $delete_all Optional, default is false. If true, delete matching metadata entries - * for all objects, ignoring the specified object_id. Otherwise, only delete matching - * metadata entries for the specified object_id. + * @param string $meta_type Type of object metadata is for (e.g., comment, post, or user) + * @param int $object_id ID of the object metadata is for + * @param string $meta_key Metadata key + * @param mixed $meta_value Optional. Metadata value. Must be serializable if non-scalar. If specified, only delete + * metadata entries with this value. Otherwise, delete all entries with the specified meta_key. + * Pass `null, `false`, or an empty string to skip this check. (For backward compatibility, + * it is not possible to pass an empty string to delete those entries with an empty string + * for a value.) + * @param bool $delete_all Optional, default is false. If true, delete matching metadata entries for all objects, + * ignoring the specified object_id. Otherwise, only delete matching metadata entries for + * the specified object_id. * @return bool True on successful delete, false on failure. */ function delete_metadata($meta_type, $object_id, $meta_key, $meta_value = '', $delete_all = false) { @@ -356,7 +359,7 @@ function delete_metadata($meta_type, $object_id, $meta_key, $meta_value = '', $d if ( !$delete_all ) $query .= $wpdb->prepare(" AND $type_column = %d", $object_id ); - if ( $meta_value ) + if ( '' !== $meta_value && null !== $meta_value && false !== $meta_value ) $query .= $wpdb->prepare(" AND meta_value = %s", $meta_value ); $meta_ids = $wpdb->get_col( $query ); diff --git a/wp-includes/version.php b/wp-includes/version.php index 2cbebc9a82..54b9775bbe 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.3-alpha-32330'; +$wp_version = '4.3-alpha-32331'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.