WordPress.org

Make WordPress Core

Ticket #11627: meta.diff

File meta.diff, 1.8 KB (added by wnorris, 8 years ago)
  • meta.php

     
    5353        global $wpdb;
    5454
    5555        $column = esc_sql($meta_type . '_id');
     56        $id_column = _get_meta_id_column($meta_type);
    5657
    5758        // expected_slashed ($meta_key)
    5859        $meta_key = stripslashes($meta_key);
    5960
    60         if ( ! $meta_id = $wpdb->get_var( $wpdb->prepare( "SELECT meta_id FROM $table WHERE meta_key = %s AND $column = %d", $meta_key, $object_id ) ) )
     61        if ( ! $meta_id = $wpdb->get_var( $wpdb->prepare( "SELECT $id_column FROM $table WHERE meta_key = %s AND $column = %d", $meta_key, $object_id ) ) )
    6162                return add_metadata($meta_type, $object_id, $meta_key, $meta_value);
    6263
    6364        $meta_value = maybe_serialize( stripslashes_deep($meta_value) );
     
    9091        global $wpdb;
    9192
    9293        $type_column = esc_sql($meta_type . '_id');
     94        $id_column = _get_meta_id_column($meta_type);
    9395        // expected_slashed ($meta_key)
    9496        $meta_key = stripslashes($meta_key);
    9597        $meta_value = maybe_serialize( stripslashes_deep($meta_value) );
    9698
    97         $query = $wpdb->prepare( "SELECT meta_id FROM $table WHERE meta_key = %s", $meta_key );
     99        $query = $wpdb->prepare( "SELECT $id_column FROM $table WHERE meta_key = %s", $meta_key );
    98100
    99101        if ( !$delete_all )
    100102                $query .= $wpdb->prepare(" AND $type_column = %d", $object_id );
     
    106108        if ( !count( $meta_ids ) )
    107109                return false;
    108110
    109         $query = "DELETE FROM $table WHERE meta_id IN( " . implode( ',', $meta_ids ) . " )";
     111        $query = "DELETE FROM $table WHERE $id_column IN( " . implode( ',', $meta_ids ) . " )";
    110112
    111113        $count = $wpdb->query($query);
    112114
     
    220222
    221223        return $wpdb->$table_name;
    222224}
     225
     226function _get_meta_id_column($type) {
     227        if ( $type == 'user' )
     228                return 'umeta_id';
     229        else
     230                return 'meta_id';
     231}
     232
    223233?>