WordPress.org

Make WordPress Core

Changeset 20435


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

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

Location:
trunk/wp-includes
Files:
4 edited

Legend:

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

    r20423 r20435  
    981981
    982982    // Delete metadata
    983     $meta_ids = $wpdb->get_col( $wpdb->prepare( "SELECT meta_id FROM $wpdb->commentmeta WHERE comment_id = %d ", $comment_id ) );
    984     if ( !empty($meta_ids) ) {
    985         do_action( 'delete_commentmeta', $meta_ids );
    986         $in_meta_ids = "'" . implode("', '", $meta_ids) . "'";
    987         $wpdb->query( "DELETE FROM $wpdb->commentmeta WHERE meta_id IN ($in_meta_ids)" );
    988         do_action( 'deleted_commentmeta', $meta_ids );
    989     }
     983    $meta_ids = $wpdb->get_col( $wpdb->prepare( "SELECT meta_id FROM $wpdb->commentmeta WHERE comment_id = %d", $comment_id ) );
     984    foreach ( $meta_ids as $mid )
     985        delete_metadata_by_mid( 'comment', $mid );
    990986
    991987    if ( ! $wpdb->delete( $wpdb->comments, array( 'comment_ID' => $comment_id ) ) )
  • trunk/wp-includes/functions.php

    r20209 r20435  
    427427    foreach ( $pung as $link_test ) {
    428428        if ( !in_array( $link_test, $post_links_temp[0] ) ) { // link no longer in post
    429             $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, like_escape( $link_test ) . '%') );
    430             do_action( 'delete_postmeta', $mid );
    431             $wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->postmeta WHERE meta_id IN(%s)", implode( ',', $mid ) ) );
    432             do_action( 'deleted_postmeta', $mid );
     429            $mids = $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, like_escape( $link_test ) . '%') );
     430            foreach ( $mids as $mid )
     431                delete_metadata_by_mid( 'post', $mid );
    433432        }
    434433    }
     
    470469
    471470                if ( in_array( substr( $type, 0, strpos( $type, "/" ) ), $allowed_types ) ) {
    472                     $meta_value = "$url\n$len\n$type\n";
    473                     $wpdb->insert($wpdb->postmeta, array('post_id' => $post_ID, 'meta_key' => 'enclosure', 'meta_value' => $meta_value) );
    474                     do_action( 'added_postmeta', $wpdb->insert_id, $post_ID, 'enclosure', $meta_value );
     471                    add_post_meta( $post_ID, 'enclosure', "$url\n$len\n$mime\n" );
    475472                }
    476473            }
  • trunk/wp-includes/meta.php

    r20287 r20435  
    224224    do_action( "delete_{$meta_type}_meta", $meta_ids, $object_id, $meta_key, $_meta_value );
    225225
     226    // Old-style action.
    226227    if ( 'post' == $meta_type )
    227228        do_action( 'delete_postmeta', $meta_ids );
     
    244245    do_action( "deleted_{$meta_type}_meta", $meta_ids, $object_id, $meta_key, $_meta_value );
    245246
     247    // Old-style action.
    246248    if ( 'post' == $meta_type )
    247249        do_action( 'deleted_postmeta', $meta_ids );
     
    486488        do_action( "delete_{$meta_type}_meta", (array) $meta_id, $object_id, $meta->meta_key, $meta->meta_value );
    487489
    488         if ( 'post' == $meta_type )
    489             do_action( 'delete_postmeta', $meta_id );
     490        // Old-style action.
     491        if ( 'post' == $meta_type || 'comment' == $meta_type )
     492            do_action( "delete_{$meta_type}meta", $meta_id );
    490493
    491494        // Run the query, will return true if deleted, false otherwise
     
    497500        do_action( "deleted_{$meta_type}_meta", (array) $meta_id, $object_id, $meta->meta_key, $meta->meta_value );
    498501
    499         if ( 'post' == $meta_type )
    500             do_action( 'deleted_postmeta', $meta_id );
     502        // Old-style action.
     503        if ( 'post' == $meta_type || 'comment' == $meta_type )
     504            do_action( "deleted_{$meta_type}meta", $meta_id );
    501505
    502506        return $result;
  • 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.