Make WordPress Core


Ignore:
Timestamp:
04/11/2012 08:02:39 PM (13 years ago)
Author:
nacin
Message:

Use the metadata API rather than raw queries and direct do_action calls. see #20417.

File:
1 edited

Legend:

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

    r20423 r20435  
    20352035
    20362036    $comment_ids = $wpdb->get_col( $wpdb->prepare( "SELECT comment_ID FROM $wpdb->comments WHERE comment_post_ID = %d", $postid ));
    2037     if ( ! empty($comment_ids) ) {
    2038         do_action( 'delete_comment', $comment_ids );
    2039         foreach ( $comment_ids as $comment_id )
    2040             wp_delete_comment( $comment_id, true );
    2041         do_action( 'deleted_comment', $comment_ids );
    2042     }
     2037    foreach ( $comment_ids as $comment_id )
     2038        wp_delete_comment( $comment_id, true );
    20432039
    20442040    $post_meta_ids = $wpdb->get_col( $wpdb->prepare( "SELECT meta_id FROM $wpdb->postmeta WHERE post_id = %d ", $postid ));
    2045     if ( !empty($post_meta_ids) ) {
    2046         do_action( 'delete_postmeta', $post_meta_ids );
    2047         $in_post_meta_ids = "'" . implode("', '", $post_meta_ids) . "'";
    2048         $wpdb->query( "DELETE FROM $wpdb->postmeta WHERE meta_id IN($in_post_meta_ids)" );
    2049         do_action( 'deleted_postmeta', $post_meta_ids );
    2050     }
     2041    foreach ( $post_meta_ids as $mid )
     2042        delete_metadata_by_mid( 'post', $mid );
    20512043
    20522044    do_action( 'delete_post', $postid );
     
    38013793    wp_delete_object_term_relationships($post_id, get_object_taxonomies($post->post_type));
    38023794
    3803     $wpdb->delete( $wpdb->postmeta, array( 'meta_key' => '_thumbnail_id' , 'meta_value' => $post_id ) );
     3795    delete_metadata( 'post', null, '_thumbnail_id', $post_id, true ); // delete all for any posts.
    38043796
    38053797    $comment_ids = $wpdb->get_col( $wpdb->prepare( "SELECT comment_ID FROM $wpdb->comments WHERE comment_post_ID = %d", $post_id ));
    3806     if ( ! empty( $comment_ids ) ) {
    3807         do_action( 'delete_comment', $comment_ids );
    3808         foreach ( $comment_ids as $comment_id )
    3809             wp_delete_comment( $comment_id, true );
    3810         do_action( 'deleted_comment', $comment_ids );
    3811     }
     3798    foreach ( $comment_ids as $comment_id )
     3799        wp_delete_comment( $comment_id, true );
    38123800
    38133801    $post_meta_ids = $wpdb->get_col( $wpdb->prepare( "SELECT meta_id FROM $wpdb->postmeta WHERE post_id = %d ", $post_id ));
    3814     if ( !empty($post_meta_ids) ) {
    3815         do_action( 'delete_postmeta', $post_meta_ids );
    3816         $in_post_meta_ids = "'" . implode("', '", $post_meta_ids) . "'";
    3817         $wpdb->query( "DELETE FROM $wpdb->postmeta WHERE meta_id IN($in_post_meta_ids)" );
    3818         do_action( 'deleted_postmeta', $post_meta_ids );
    3819     }
     3802    foreach ( $post_meta_ids as $mid )
     3803        delete_metadata_by_mid( 'post', $mid );
    38203804
    38213805    do_action( 'delete_post', $post_id );
     
    45644548        return;
    45654549
    4566     $data = array( 'post_id' => $post_id, 'meta_value' => '1' );
    4567     if ( get_option('default_pingback_flag') ) {
    4568         $wpdb->insert( $wpdb->postmeta, $data + array( 'meta_key' => '_pingme' ) );
    4569         do_action( 'added_postmeta', $wpdb->insert_id, $post_id, '_pingme', 1 );
    4570     }
    4571     $wpdb->insert( $wpdb->postmeta, $data + array( 'meta_key' => '_encloseme' ) );
    4572     do_action( 'added_postmeta', $wpdb->insert_id, $post_id, '_encloseme', 1 );
     4550    if ( get_option('default_pingback_flag') )
     4551        add_post_meta( $post_id, '_pingme', '1' );
     4552    add_post_meta( $post_id, '_encloseme', '1' );
    45734553
    45744554    wp_schedule_single_event(time(), 'do_pings');
Note: See TracChangeset for help on using the changeset viewer.