Make WordPress Core


Ignore:
Timestamp:
09/24/2009 05:10:28 PM (15 years ago)
Author:
ryan
Message:

Actions for postmeta updates. Props Demitrious Kelly. see #10750

File:
1 edited

Legend:

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

    r11948 r11968  
    5858    $meta_key = stripslashes($meta_key);
    5959
    60     if ( ! $wpdb->get_var( $wpdb->prepare( "SELECT meta_key FROM $table WHERE meta_key = %s AND $column = %d", $meta_key, $object_id ) ) )
     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 ) ) )
    6161        return add_metadata($meta_type, $object_id, $meta_key, $meta_value);
    6262
     
    7171    }
    7272
    73     do_action( "update_{$meta_type}_meta", $object_id, $meta_key, $meta_value );
     73    do_action( "update_{$meta_type}_meta", $object_id, $meta_key, $meta_value, $meta_id );
    7474
    7575    $wpdb->update( $table, $data, $where );
    7676    wp_cache_delete($object_id, $meta_type . '_meta');
    7777
    78     do_action( "updated_{$meta_type}_meta", $object_id, $meta_key, $meta_value );
     78    do_action( "updated_{$meta_type}_meta", $object_id, $meta_key, $meta_value, $meta_id );
    7979
    8080    return true;
     
    9696    $meta_value = maybe_serialize( stripslashes_deep($meta_value) );
    9797
    98     $query = $wpdb->prepare( "DELETE FROM $table WHERE meta_key = %s", $meta_key );
    99 
     98    $query = $wpdb->prepare( "SELECT meta_id FROM $table WHERE meta_key = %s", $meta_key );
     99   
    100100    if ( $meta_value )
    101101        $query .= $wpdb->prepare("AND meta_value = %s", $meta_value );
     102
     103    $meta_ids = $wpdb->get_col( $query );
     104    if ( !count( $meta_ids ) )
     105        return false;
     106
     107    $query = "DELETE FROM $table WHERE meta_id IN( " . implode( ',', $meta_ids ) . " )";
    102108   
    103109    $count = $wpdb->query($query);
     
    108114    wp_cache_delete($object_id, $meta_type . '_meta');
    109115
    110     do_action( "deleted_{$meta_type}_meta", $object_id, $meta_key, $meta_value );
     116    do_action( "deleted_{$meta_type}_meta", $object_id, $meta_key, $meta_value, $meta_ids );
    111117
    112118    return true;
Note: See TracChangeset for help on using the changeset viewer.