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
This commit is contained in:
Boone Gorges 2015-05-01 16:38:29 +00:00
parent 2807b7146f
commit 11226f02a8
2 changed files with 13 additions and 10 deletions

View File

@ -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 );

View File

@ -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.