WordPress.org

Make WordPress Core

Changeset 11996


Ignore:
Timestamp:
10/05/2009 01:08:06 AM (10 years ago)
Author:
azaozz
Message:

Fix delete_metadata(), see #2659

File:
1 edited

Legend:

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

    r11971 r11996  
    8181}
    8282
    83 function delete_metadata($meta_type, $object_id, $meta_key, $meta_value = '') {
    84     if ( !$meta_type || !$meta_key )
    85         return false;
    86 
    87     if ( ! $table = _get_meta_table($meta_type) )
    88         return false;
    89 
    90     global $wpdb;
    91 
    92     $column = esc_sql($meta_type . '_id');
     83function delete_metadata($meta_type, $object_id, $meta_key, $meta_value = '', $delete_all = false) {
     84    if ( !$meta_type || !$meta_key || (!$delete_all && ! (int)$object_id) )
     85        return false;
     86
     87    if ( ! $table = _get_meta_table($meta_type) )
     88        return false;
     89
     90    global $wpdb;
    9391
    9492    // expected_slashed ($meta_key)
     
    9896    $query = $wpdb->prepare( "SELECT meta_id FROM $table WHERE meta_key = %s", $meta_key );
    9997
     98    if ( !$delete_all )
     99        $query .= $wpdb->prepare(" AND %s = %d", $meta_type . '_id', $object_id );
     100
    100101    if ( $meta_value )
    101         $query .= $wpdb->prepare("AND meta_value = %s", $meta_value );
     102        $query .= $wpdb->prepare(" AND meta_value = %s", $meta_value );
    102103
    103104    $meta_ids = $wpdb->get_col( $query );
Note: See TracChangeset for help on using the changeset viewer.