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

git-svn-id: http://svn.automattic.com/wordpress/trunk@10731 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2009-03-06 05:06:15 +00:00
parent d43bd8177c
commit c1886783d1
4 changed files with 12 additions and 32 deletions

View File

@ -216,7 +216,7 @@ case 'approvecomment' :
case 'editedcomment' :
$comment_id = absint( $_POST['comment_ID'] );
$comment_post_id = absint( $_POST['comment_post_id'] );
$comment_post_id = absint( $_POST['comment_post_ID'] );
check_admin_referer( 'update-comment_' . $comment_id );

View File

@ -47,10 +47,10 @@ if ( $response['response']['code'] != 200 )
$body = str_replace(array("\r\n", "\r"), "\n", $response['body']);
$returns = explode("\n", $body);
foreach ($returns as $return) :
foreach ($returns as $return) {
$time = substr($return, 0, 19);
$uri = preg_replace('/(.*?) | (.*?)/', '$2', $return);
$wpdb->query( $wpdb->prepare("UPDATE $wpdb->links SET link_updated = %s WHERE link_url = %s", $time, $uri) );
endforeach;
$wdpdb->update( $wpdb->links, array('link_updated' => $time), array('link_url' => $uri) );
}
?>

View File

@ -880,14 +880,12 @@ function wp_insert_comment($commentdata) {
if ( ! isset($comment_type) )
$comment_type = '';
$result = $wpdb->query( $wpdb->prepare("INSERT INTO $wpdb->comments
(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)
VALUES (%d, %s, %s, %s, %s, %s, %s, %s, %d, %s, %s, %s, %d, %d)",
$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) );
$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');
$wpdb->insert($wpdb->comments, $data);
$id = (int) $wpdb->insert_id;
if ( $comment_approved == 1)
if ( $comment_approved == 1 )
wp_update_comment_count($comment_post_ID);
$comment = get_comment($id);
@ -1080,8 +1078,7 @@ function wp_update_comment($commentarr) {
$comment = get_comment($commentarr['comment_ID'], ARRAY_A);
// Escape data pulled from DB.
foreach ( (array) $comment as $key => $value )
$comment[$key] = $wpdb->escape($value);
$comment = $wpdb->escape($comment);
// Merge old and new fields with new fields overwriting old ones.
$commentarr = array_merge($comment, $commentarr);
@ -1102,25 +1099,8 @@ function wp_update_comment($commentarr) {
else if ( 'approve' == $comment_approved )
$comment_approved = 1;
$wpdb->query( $wpdb->prepare("UPDATE $wpdb->comments SET
comment_content = %s,
comment_author = %s,
comment_author_email = %s,
comment_approved = %s,
comment_karma = %d,
comment_author_url = %s,
comment_date = %s,
comment_date_gmt = %s
WHERE comment_ID = %d",
$comment_content,
$comment_author,
$comment_author_email,
$comment_approved,
$comment_karma,
$comment_author_url,
$comment_date,
$comment_date_gmt,
$comment_ID) );
$data = compact('comment_content', 'comment_author', 'comment_author_email', 'comment_approved', 'comment_karma', 'comment_author_url', 'comment_date', 'comment_date_gmt');
$wpdb->update($wpdb->comments, $data, compact('comment_ID'));
$rval = $wpdb->rows_affected;
@ -1219,7 +1199,7 @@ function wp_update_comment_count_now($post_id) {
$old = (int) $post->comment_count;
$new = (int) $wpdb->get_var( $wpdb->prepare("SELECT COUNT(*) FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_approved = '1'", $post_id) );
$wpdb->query( $wpdb->prepare("UPDATE $wpdb->posts SET comment_count = %d WHERE ID = %d", $new, $post_id) );
$wpdb->update( $wpdb->posts, array('comment_count' => $new), array('ID' => $post_id) );
if ( 'page' == $post->post_type )
clean_page_cache( $post_id );

View File

@ -254,7 +254,7 @@ require (ABSPATH . WPINC . '/classes.php');
$db_field_types = array( 'post_author' => '%d', 'post_parent' => '%d', 'menu_order' => '%d', 'term_id' => '%d', 'term_group' => '%d', 'term_taxonomy_id' => '%d',
'parent' => '%d', 'count' => '%d','object_id' => '%d', 'term_order' => '%d', 'ID' => '%d', 'commment_ID' => '%d', 'comment_post_ID' => '%d', 'comment_parent' => '%d',
'user_id' => '%d', 'link_id' => '%d', 'link_owner' => '%d', 'link_rating' => '%d', 'option_id' => '%d', 'blog_id' => '%d', 'meta_id' => '%d', 'post_id' => '%d',
'user_status' => '%d', 'umeta_id' => '%d');
'user_status' => '%d', 'umeta_id' => '%d', 'comment_karma' => '%d', 'comment_count' => '%d');
require_wp_db();