Make WordPress Core


Ignore:
Timestamp:
05/01/2015 04:37:35 PM (10 years ago)
Author:
boonebgorges
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/meta.php

    r32044 r32331  
    295295 * @global wpdb $wpdb WordPress database abstraction object.
    296296 *
    297  * @param string $meta_type Type of object metadata is for (e.g., comment, post, or user)
    298  * @param int $object_id ID of the object metadata is for
    299  * @param string $meta_key Metadata key
    300  * @param mixed $meta_value Optional. Metadata value. Must be serializable if non-scalar. If specified, only delete metadata entries
    301  *      with this value. Otherwise, delete all entries with the specified meta_key.
    302  * @param bool $delete_all Optional, default is false. If true, delete matching metadata entries
    303  *      for all objects, ignoring the specified object_id. Otherwise, only delete matching
    304  *      metadata entries for the specified object_id.
     297 * @param string $meta_type  Type of object metadata is for (e.g., comment, post, or user)
     298 * @param int    $object_id  ID of the object metadata is for
     299 * @param string $meta_key   Metadata key
     300 * @param mixed  $meta_value Optional. Metadata value. Must be serializable if non-scalar. If specified, only delete
     301 *                           metadata entries with this value. Otherwise, delete all entries with the specified meta_key.
     302 *                           Pass `null, `false`, or an empty string to skip this check. (For backward compatibility,
     303 *                           it is not possible to pass an empty string to delete those entries with an empty string
     304 *                           for a value.)
     305 * @param bool   $delete_all Optional, default is false. If true, delete matching metadata entries for all objects,
     306 *                           ignoring the specified object_id. Otherwise, only delete matching metadata entries for
     307 *                           the specified object_id.
    305308 * @return bool True on successful delete, false on failure.
    306309 */
     
    357360        $query .= $wpdb->prepare(" AND $type_column = %d", $object_id );
    358361
    359     if ( $meta_value )
     362    if ( '' !== $meta_value && null !== $meta_value && false !== $meta_value )
    360363        $query .= $wpdb->prepare(" AND meta_value = %s", $meta_value );
    361364
Note: See TracChangeset for help on using the changeset viewer.