Make WordPress Core

Changeset 11968


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

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

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/post.php

    r11930 r11968  
    589589
    590590        $wpdb->query( $wpdb->prepare("INSERT INTO $wpdb->postmeta (post_id,meta_key,meta_value ) VALUES (%s, %s, %s)", $post_ID, $metakey, $metavalue) );
     591        do_action( 'added_postmeta', $wpdb->insert_id, $post_ID, $metakey, $metavalue );
     592       
    591593        return $wpdb->insert_id;
    592594    }
     
    609611    wp_cache_delete($post_id, 'post_meta');
    610612
    611     return $wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->postmeta WHERE meta_id = %d", $mid) );
     613    do_action( 'delete_postmeta', $mid );
     614    $rval = $wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->postmeta WHERE meta_id = %d", $mid) );
     615    do_action( 'deleted_postmeta', $mid );
     616
     617    return $rval;
    612618}
    613619
     
    698704    $where = compact( 'meta_id' );
    699705
    700     return $wpdb->update( $wpdb->postmeta, $data, $where );
     706    do_action( 'update_postmeta', $meta_id, $post_id, $meta_key, $meta_value );
     707    $rval = $wpdb->update( $wpdb->postmeta, $data, $where );
     708    do_action( 'updated_postmeta', $meta_id, $post_id, $meta_key, $meta_value );
     709
     710    return $rval;
    701711}
    702712
  • trunk/wp-includes/comment.php

    r11945 r11968  
    14501450    // Do pingbacks
    14511451    while ($ping = $wpdb->get_row("SELECT * FROM {$wpdb->posts}, {$wpdb->postmeta} WHERE {$wpdb->posts}.ID = {$wpdb->postmeta}.post_id AND {$wpdb->postmeta}.meta_key = '_pingme' LIMIT 1")) {
    1452         $wpdb->query("DELETE FROM {$wpdb->postmeta} WHERE post_id = {$ping->ID} AND meta_key = '_pingme';");
     1452        $mid = $wpdb->get_var( "SELECT meta_id FROM {$wpdb->postmeta} WHERE post_id = {$ping->ID} AND meta_key = '_pingme' LIMIT 1");
     1453        do_action( 'delete_postmeta', $mid );
     1454        $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->postmeta} WHERE meta_id = %d", $mid ) );
     1455        do_action( 'deleted_postmeta', $mid );
    14531456        pingback($ping->post_content, $ping->ID);
    14541457    }
     
    14561459    // Do Enclosures
    14571460    while ($enclosure = $wpdb->get_row("SELECT * FROM {$wpdb->posts}, {$wpdb->postmeta} WHERE {$wpdb->posts}.ID = {$wpdb->postmeta}.post_id AND {$wpdb->postmeta}.meta_key = '_encloseme' LIMIT 1")) {
    1458         $wpdb->query( $wpdb->prepare("DELETE FROM {$wpdb->postmeta} WHERE post_id = %d AND meta_key = '_encloseme';", $enclosure->ID) );
     1461        $mid = $wpdb->get_var( $wpdb->prepare("SELECT meta_id FROM {$wpdb->postmeta} WHERE post_id = %d AND meta_key = '_encloseme'", $enclosure->ID) );
     1462        do_action( 'delete_postmeta', $mid );
     1463        $wpdb->query( $wpdb->prepare("DELETE FROM {$wpdb->postmeta} WHERE meta_id =  %d", $mid) );
     1464        do_action( 'deleted_postmeta', $mid );
    14591465        do_enclose($enclosure->post_content, $enclosure->ID);
    14601466    }
  • trunk/wp-includes/functions.php

    r11961 r11968  
    11641164    foreach ( $pung as $link_test ) {
    11651165        if ( !in_array( $link_test, $post_links_temp[0] ) ) { // link no longer in post
    1166             $wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->postmeta WHERE post_id = %d AND meta_key = 'enclosure' AND meta_value LIKE (%s)", $post_ID, $link_test . '%') );
     1166            $mid = $wpdb->get_col( $wpdb->prepare("SELECT meta_id FROM $wpdb->postmeta WHERE post_id = %d AND meta_key = 'enclosure' AND meta_value LIKE (%s)", $post_ID, $link_test . '%') );
     1167            do_action( 'delete_postmeta', $mid );
     1168            $wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->postmeta WHERE post_id IN(%s)", implode( ',', $mid ) ) );
     1169            do_action( 'deleted_postmeta', $mid );
    11671170        }
    11681171    }
     
    11871190                    $meta_value = "$url\n$len\n$type\n";
    11881191                    $wpdb->insert($wpdb->postmeta, array('post_id' => $post_ID, 'meta_key' => 'enclosure', 'meta_value' => $meta_value) );
     1192                    do_action( 'added_postmeta', $wpdb->insert_id, $post_ID, 'enclosure', $meta_value );
    11891193                }
    11901194            }
  • 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;
  • trunk/wp-includes/post.php

    r11965 r11968  
    602602    $post_ids = $wpdb->get_col($wpdb->prepare("SELECT DISTINCT post_id FROM $wpdb->postmeta WHERE meta_key = %s", $post_meta_key));
    603603    if ( $post_ids ) {
    604         $wpdb->query($wpdb->prepare("DELETE FROM $wpdb->postmeta WHERE meta_key = %s", $post_meta_key));
     604        $postmetaids = $wpdb->get_col( $wpdb->prepare( "SELECT meta_id FROM $wpdb->postmeta WHERE meta_key = %s", $post_meta_key ) );
     605        do_action( 'delete_postmeta', $postmetaids );
     606        $wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->postmeta WHERE meta_id IN(%s)", implode( ',', $postmetaids) ) );
     607        do_action( 'deleted_postmeta', $postmetaids );
    605608        foreach ( $post_ids as $post_id )
    606609            wp_cache_delete($post_id, 'post_meta');
     
    11031106    $wpdb->update( $wpdb->posts, $parent_data, $parent_where + array( 'post_type' => 'attachment' ) );
    11041107
    1105     $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->comments WHERE comment_post_ID = %d", $postid ));
    1106 
    1107     $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->postmeta WHERE post_id = %d", $postid ));
    1108 
     1108    $commentids = $wpdb->get_col( $wpdb->prepare( "SELECT comment_ID FROM $wpdb->comments WHERE comment_post_ID = %d", $postid ));
     1109    do_action( 'delete_comment', $commentids );
     1110    $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->comments WHERE comment_ID IN(%s)", implode( ',', $commentids ) ));
     1111    do_action( 'deleted_comment', $commentids );
     1112
     1113    $postmetaids = $wpdb->get_col( $wpdb->prepare( "SELECT meta_id FROM $wpdb->postmeta WHERE post_id = %d ", $post_id ));
     1114    do_action( 'delete_postmeta', $postmetaids );
     1115    $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->postmeta WHERE meta_id IN(%s)", implode( ',', $postmetaids ) ));
     1116    do_action( 'deleted_postmeta', $postmetaids );
     1117
     1118    do_action( 'delete_post', $post_id );
    11091119    $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->posts WHERE ID = %d", $postid ));
     1120    do_action( 'deleted_post', $post_id );
    11101121
    11111122    if ( 'page' == $post->post_type ) {
     
    25852596    wp_delete_object_term_relationships($post_id, array('category', 'post_tag'));
    25862597
    2587     $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->comments WHERE comment_post_ID = %d", $post_id ));
    2588 
    2589     $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->postmeta WHERE post_id = %d ", $post_id ));
    2590 
     2598    $commentids = $wpdb->get_col( $wpdb->prepare( "SELECT comment_ID FROM $wpdb->comments WHERE comment_post_ID = %d", $post_id ));
     2599    do_action( 'delete_comment', $commentids );
     2600    $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->comments WHERE comment_ID IN(%s)", implode( ',', $commentids ) ));
     2601    do_action( 'deleted_comment', $commentids );
     2602
     2603    $postmetaids = $wpdb->get_col( $wpdb->prepare( "SELECT meta_id FROM $wpdb->postmeta WHERE post_id = %d ", $post_id ));
     2604    do_action( 'delete_postmeta', $postmetaids );
     2605    $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->postmeta WHERE meta_id IN(%s)", implode( ',', $postmetaids ) ));
     2606    do_action( 'deleted_postmeta', $postmetaids );
     2607
     2608    do_action( 'delete_post', $post_id );
    25912609    $wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->posts WHERE ID = %d", $post_id ));
     2610    do_action( 'deleted_post', $post_id );
    25922611
    25932612    $uploadpath = wp_upload_dir();
     
    32713290
    32723291    $data = array( 'post_id' => $post_id, 'meta_value' => '1' );
    3273     if ( get_option('default_pingback_flag') )
     3292    if ( get_option('default_pingback_flag') ) {
    32743293        $wpdb->insert( $wpdb->postmeta, $data + array( 'meta_key' => '_pingme' ) );
     3294        do_action( 'added_postmeta', $wpdb->insert_id, $post_id, '_pingme', 1 );
     3295    }
    32753296    $wpdb->insert( $wpdb->postmeta, $data + array( 'meta_key' => '_encloseme' ) );
     3297    do_action( 'added_postmeta', $wpdb->insert_id, $post_id, '_encloseme', 1 );
     3298
    32763299    wp_schedule_single_event(time(), 'do_pings');
    32773300}
Note: See TracChangeset for help on using the changeset viewer.