Make WordPress Core


Ignore:
Timestamp:
08/03/2011 04:48:37 PM (13 years ago)
Author:
ryan
Message:

Turn delete_meta() , get_post_meta_by_id(), update_meta(), delete_post_meta_by_key() into wrappers around the metadata API. Add back compat *_postmeta actions to metadata API. Props jgadbois. see #18196

File:
1 edited

Legend:

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

    r18494 r18500  
    150150
    151151    do_action( "update_{$meta_type}_meta", $meta_id, $object_id, $meta_key, $_meta_value );
     152   
     153    if ( 'post' == $meta_type )
     154        do_action( 'update_postmeta', $meta_id, $object_id, $meta_key, $meta_value );   
    152155
    153156    $wpdb->update( $table, $data, $where );
     
    159162
    160163    do_action( "updated_{$meta_type}_meta", $meta_id, $object_id, $meta_key, $_meta_value );
     164   
     165    if ( 'post' == $meta_type )
     166        do_action( 'updated_postmeta', $meta_id, $object_id, $meta_key, $meta_value );     
    161167
    162168    return true;
     
    205211    $_meta_value = $meta_value;
    206212    $meta_value = maybe_serialize( $meta_value );
    207 
     213       
    208214    $query = $wpdb->prepare( "SELECT $id_column FROM $table WHERE meta_key = %s", $meta_key );
    209215
     
    218224        return false;
    219225
     226    if ( $delete_all )
     227        $object_ids = $wpdb->get_col( $wpdb->prepare( "SELECT $type_column FROM $table WHERE meta_key = %s", $meta_key ) );
     228
    220229    do_action( "delete_{$meta_type}_meta", $meta_ids, $object_id, $meta_key, $_meta_value );
     230   
     231    if ( 'post' == $meta_type )
     232        do_action( 'delete_postmeta', $meta_ids );
    221233
    222234    $query = "DELETE FROM $table WHERE $id_column IN( " . implode( ',', $meta_ids ) . " )";
     
    227239        return false;
    228240
    229     wp_cache_delete($object_id, $meta_type . '_meta');
     241    if ( $delete_all ) {
     242        foreach ( (array) $object_ids as $o_id ) {
     243            wp_cache_delete($o_id, $meta_type . '_meta');
     244        }
     245    } else {
     246        wp_cache_delete($object_id, $meta_type . '_meta');
     247    }
     248
    230249    // users cache stores usermeta that must be cleared.
    231250    if ( 'user' == $meta_type )
     
    233252
    234253    do_action( "deleted_{$meta_type}_meta", $meta_ids, $object_id, $meta_key, $_meta_value );
     254   
     255    if ( 'post' == $meta_type )
     256        do_action( 'deleted_postmeta', $meta_ids );
    235257
    236258    return true;
     
    382404
    383405        do_action( "update_{$meta_type}_meta", $meta_id, $object_id, $meta_key, $_meta_value );
     406
     407        if ( 'post' == $meta_type )
     408            do_action( 'update_postmeta', $meta_id, $object_id, $meta_key, $meta_value );
    384409       
    385410        // Run the update query, all fields in $data are %s, $where is a %d.
     
    395420        do_action( "updated_{$meta_type}_meta", $meta_id, $object_id, $meta_key, $_meta_value );
    396421
     422        if ( 'post' == $meta_type )
     423            do_action( 'updated_postmeta', $meta_id, $object_id, $meta_key, $meta_value );
     424
    397425        return $result;
    398426    }
     
    437465        do_action( "delete_{$meta_type}_meta", (array) $meta_id, $object_id, $meta->meta_key, $meta->meta_value );
    438466
     467        if ( 'post' == $meta_type )
     468            do_action( 'delete_postmeta', $object_id );
     469
    439470        // Run the query, will return true if deleted, false otherwise
    440471        $result = (bool) $wpdb->query( $wpdb->prepare( "DELETE FROM $table WHERE $id_column = %d LIMIT 1;", $meta_id ) );
     
    442473        // Clear the caches.
    443474        wp_cache_delete($object_id, $meta_type . '_meta');
    444        
     475
    445476        // Users cache stores usermeta that must be cleared.
    446477        if ( 'user' == $meta_type )
     
    448479
    449480        do_action( "deleted_{$meta_type}_meta", (array) $meta_id, $object_id, $meta->meta_key, $meta->meta_value );
     481
     482        if ( 'post' == $meta_type )
     483            do_action( 'delete_postmeta', $object_id );
    450484
    451485        return $result;
Note: See TracChangeset for help on using the changeset viewer.