Make WordPress Core


Ignore:
Timestamp:
03/06/2009 05:06:15 AM (18 years ago)
Author:
ryan
Message:

Use wpdb::insert() and update(). see #6836

File:
1 edited

Legend:

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

    r10730 r10731  
    881881                $comment_type = '';
    882882
    883         $result = $wpdb->query( $wpdb->prepare("INSERT INTO $wpdb->comments
    884         (comment_post_ID, comment_author, comment_author_email, comment_author_url, comment_author_IP, comment_date, comment_date_gmt, comment_content, comment_karma, comment_approved, comment_agent, comment_type, comment_parent, user_id)
    885         VALUES (%d, %s, %s, %s, %s, %s, %s, %s, %d, %s, %s, %s, %d, %d)",
    886         $comment_post_ID, $comment_author, $comment_author_email, $comment_author_url, $comment_author_IP, $comment_date, $comment_date_gmt, $comment_content, $comment_karma, $comment_approved, $comment_agent, $comment_type, $comment_parent, $user_id) );
     883        $data = compact('comment_post_ID', 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_author_IP', 'comment_date', 'comment_date_gmt', 'comment_content', 'comment_karma', 'comment_approved', 'comment_agent', 'comment_type', 'comment_parent', 'user_id');
     884        $wpdb->insert($wpdb->comments, $data);
    887885
    888886        $id = (int) $wpdb->insert_id;
    889887
    890         if ( $comment_approved == 1)
     888        if ( $comment_approved == 1 )
    891889                wp_update_comment_count($comment_post_ID);
    892890
    … …  
    10811079
    10821080        // Escape data pulled from DB.
    1083         foreach ( (array) $comment as $key => $value )
    1084                 $comment[$key] = $wpdb->escape($value);
     1081        $comment = $wpdb->escape($comment);
    10851082
    10861083        // Merge old and new fields with new fields overwriting old ones.
    … …  
    11031100                $comment_approved = 1;
    11041101
    1105         $wpdb->query( $wpdb->prepare("UPDATE $wpdb->comments SET
    1106                         comment_content      = %s,
    1107                         comment_author       = %s,
    1108                         comment_author_email = %s,
    1109                         comment_approved     = %s,
    1110                         comment_karma        = %d,
    1111                         comment_author_url   = %s,
    1112                         comment_date         = %s,
    1113                         comment_date_gmt     = %s
    1114                 WHERE comment_ID = %d",
    1115                         $comment_content,
    1116                         $comment_author,
    1117                         $comment_author_email,
    1118                         $comment_approved,
    1119                         $comment_karma,
    1120                         $comment_author_url,
    1121                         $comment_date,
    1122                         $comment_date_gmt,
    1123                         $comment_ID) );
     1102        $data = compact('comment_content', 'comment_author', 'comment_author_email', 'comment_approved', 'comment_karma', 'comment_author_url', 'comment_date', 'comment_date_gmt');
     1103        $wpdb->update($wpdb->comments, $data, compact('comment_ID'));
    11241104
    11251105        $rval = $wpdb->rows_affected;
    … …  
    12201200        $old = (int) $post->comment_count;
    12211201        $new = (int) $wpdb->get_var( $wpdb->prepare("SELECT COUNT(*) FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_approved = '1'", $post_id) );
    1222         $wpdb->query( $wpdb->prepare("UPDATE $wpdb->posts SET comment_count = %d WHERE ID = %d", $new, $post_id) );
     1202        $wpdb->update( $wpdb->posts, array('comment_count' => $new), array('ID' => $post_id) );
    12231203
    12241204        if ( 'page' == $post->post_type )
Note: See TracChangeset for help on using the changeset viewer.