WordPress.org

Make WordPress Core

Changeset 10730


Ignore:
Timestamp:
03/06/2009 04:27:51 AM (9 years ago)
Author:
ryan
Message:

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

Location:
trunk
Files:
11 edited

Legend:

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

    r10723 r10730  
    757757    $old_ID = (int) $old_ID;
    758758    $new_ID = (int) $new_ID;
    759     return $wpdb->query( $wpdb->prepare("UPDATE $wpdb->posts SET post_parent = %d WHERE post_parent = %d", $new_ID, $old_ID) );
     759    return $wpdb->update($wpdb->posts, array('post_parent' => $new_ID), array('post_parent' => $old_ID) );
    760760}
    761761
  • trunk/wp-admin/includes/schema.php

    r10553 r10730  
    311311    // Set up a few options not to load by default
    312312    $fatoptions = array( 'moderation_keys', 'recently_edited', 'blacklist_keys' );
    313     foreach ($fatoptions as $fatoption) :
    314         $wpdb->query("UPDATE $wpdb->options SET `autoload` = 'no' WHERE option_name = '$fatoption'");
    315     endforeach;
     313    foreach ($fatoptions as $fatoption)
     314        $wpdb->update( $wpdb->options, array('autoload' => 'no'), array('option_name' => $fatoption) );
    316315}
    317316
  • trunk/wp-admin/includes/upgrade.php

    r10575 r10730  
    9494
    9595    // Default category
    96     $cat_name = $wpdb->escape(__('Uncategorized'));
     96    $cat_name = __('Uncategorized');
    9797    $cat_slug = sanitize_title(_c('Uncategorized|Default category slug'));
    98     $wpdb->query("INSERT INTO $wpdb->terms (name, slug, term_group) VALUES ('$cat_name', '$cat_slug', '0')");
    99     $wpdb->query("INSERT INTO $wpdb->term_taxonomy (term_id, taxonomy, description, parent, count) VALUES ('1', 'category', '', '0', '1')");
     98   
     99    $wpdb->insert( $wpdb->terms, array('name' => $cat_name, 'slug' => $cat_slug, 'term_group' => 0) );
     100    $wpdb->insert( $wpdb->term_taxonomy, array('term_id' => '1', 'taxonomy' => 'category', 'description' => '', 'parent' => 0, 'count' => 1));
    100101
    101102    // Default link category
    102     $cat_name = $wpdb->escape(__('Blogroll'));
     103    $cat_name = __('Blogroll');
    103104    $cat_slug = sanitize_title(_c('Blogroll|Default link category slug'));
    104     $wpdb->query("INSERT INTO $wpdb->terms (name, slug, term_group) VALUES ('$cat_name', '$cat_slug', '0')");
    105     $wpdb->query("INSERT INTO $wpdb->term_taxonomy (term_id, taxonomy, description, parent, count) VALUES ('2', 'link_category', '', '0', '7')");
     105   
     106    $wpdb->insert( $wpdb->terms, array('name' => $cat_name, 'slug' => $cat_slug, 'term_group' => 0) );
     107    $wpdb->insert( $wpdb->term_taxonomy, array('term_id' => '2', 'taxonomy' => 'link_category', 'description' => '', 'parent' => 0, 'count' => 7));
    106108
    107109    // Now drop in some default links
    108     $wpdb->query("INSERT INTO $wpdb->links (link_url, link_name, link_category, link_rss, link_notes) VALUES ('http://codex.wordpress.org/', 'Documentation', 0, '', '');");
    109     $wpdb->query( "INSERT INTO $wpdb->term_relationships (`object_id`, `term_taxonomy_id`) VALUES (1, 2)" );
    110 
    111     $wpdb->query("INSERT INTO $wpdb->links (link_url, link_name, link_category, link_rss, link_notes) VALUES ('http://wordpress.org/development/', 'Development Blog', 0, 'http://wordpress.org/development/feed/', '');");
    112     $wpdb->query( "INSERT INTO $wpdb->term_relationships (`object_id`, `term_taxonomy_id`) VALUES (2, 2)" );
    113 
    114     $wpdb->query("INSERT INTO $wpdb->links (link_url, link_name, link_category, link_rss, link_notes) VALUES ('http://wordpress.org/extend/ideas/', 'Suggest Ideas', 0, '', '');");
    115     $wpdb->query( "INSERT INTO $wpdb->term_relationships (`object_id`, `term_taxonomy_id`) VALUES (3, 2)" );
    116 
    117     $wpdb->query("INSERT INTO $wpdb->links (link_url, link_name, link_category, link_rss, link_notes) VALUES ('http://wordpress.org/support/', 'Support Forum', 0, '', '');");
    118     $wpdb->query( "INSERT INTO $wpdb->term_relationships (`object_id`, `term_taxonomy_id`) VALUES (4, 2)" );
    119 
    120     $wpdb->query("INSERT INTO $wpdb->links (link_url, link_name, link_category, link_rss, link_notes) VALUES ('http://wordpress.org/extend/plugins/', 'Plugins', 0, '', '');");
    121     $wpdb->query( "INSERT INTO $wpdb->term_relationships (`object_id`, `term_taxonomy_id`) VALUES (5, 2)" );
    122 
    123     $wpdb->query("INSERT INTO $wpdb->links (link_url, link_name, link_category, link_rss, link_notes) VALUES ('http://wordpress.org/extend/themes/', 'Themes', 0, '', '');");
    124     $wpdb->query( "INSERT INTO $wpdb->term_relationships (`object_id`, `term_taxonomy_id`) VALUES (6, 2)" );
    125 
    126     $wpdb->query("INSERT INTO $wpdb->links (link_url, link_name, link_category, link_rss, link_notes) VALUES ('http://planet.wordpress.org/', 'WordPress Planet', 0, '', '');");
    127     $wpdb->query( "INSERT INTO $wpdb->term_relationships (`object_id`, `term_taxonomy_id`) VALUES (7, 2)" );
     110    $default_links = array();
     111    $default_links[] = array(   'link_url' => 'http://codex.wordpress.org/',
     112                                'link_name' => 'Documentation',
     113                                'link_category' => 0,
     114                                'link_rss' => '',
     115                                'link_notes' => '');
     116
     117    $default_links[] = array(   'link_url' => 'http://wordpress.org/development/',
     118                                'link_name' => 'Development Blog',
     119                                'link_category' => 0,
     120                                'link_rss' => 'http://wordpress.org/development/feed/',
     121                                'link_notes' => '');
     122
     123    $default_links[] = array(   'link_url' => 'http://wordpress.org/extend/ideas/',
     124                                'link_name' => 'Suggest Ideas',
     125                                'link_category' => 0,
     126                                'link_rss' => '',
     127                                'link_notes' =>'');
     128
     129    $default_links[] = array(   'link_url' => 'http://wordpress.org/support/',
     130                                'link_name' => 'Support Forum',
     131                                'link_category' => 0,
     132                                'link_rss' => '',
     133                                'link_notes' =>'');
     134
     135    $default_links[] = array(   'link_url' => 'http://wordpress.org/extend/plugins/',
     136                                'link_name' => 'Plugins',
     137                                'link_category' => 0,
     138                                'link_rss' => '',
     139                                'link_notes' =>'');
     140
     141    $default_links[] = array(   'link_url' => 'http://wordpress.org/extend/themes/',
     142                                'link_name' => 'Themes',
     143                                'link_category' => 0,
     144                                'link_rss' => '',
     145                                'link_notes' =>'');
     146
     147    $default_links[] = array(   'link_url' => 'http://planet.wordpress.org/',
     148                                'link_name' => 'WordPress Planet',
     149                                'link_category' => 0,
     150                                'link_rss' => '',
     151                                'link_notes' =>'');
     152
     153    foreach ( default_links as $link ) {
     154        $wpdb->insert( $wpdb->links, $link);
     155        $wpdb->insert( $wpdb->term_relationships, array('term_taxonomy_id' => 2, 'object_id' => $wpdb->insert_id) );
     156    }
    128157
    129158    // First post
     
    131160    $now_gmt = gmdate('Y-m-d H:i:s');
    132161    $first_post_guid = get_option('home') . '/?p=1';
    133     $wpdb->query("INSERT INTO $wpdb->posts (post_author, post_date, post_date_gmt, post_content, post_excerpt, post_title, post_category, post_name, post_modified, post_modified_gmt, guid, comment_count, to_ping, pinged, post_content_filtered) VALUES ($user_id, '$now', '$now_gmt', '".$wpdb->escape(__('Welcome to WordPress. This is your first post. Edit or delete it, then start blogging!'))."', '', '".$wpdb->escape(__('Hello world!'))."', '0', '".$wpdb->escape(_c('hello-world|Default post slug'))."', '$now', '$now_gmt', '$first_post_guid', '1', '', '', '')");
    134     $wpdb->query( "INSERT INTO $wpdb->term_relationships (`object_id`, `term_taxonomy_id`) VALUES (1, 1)" );
     162   
     163    $wpdb->insert( $wpdb->posts, array(
     164                                'post_author' => $user_id,
     165                                'post_date' => $now,
     166                                'post_date_gmt' => $now_gmt,
     167                                'post_content' => __('Welcome to WordPress. This is your first post. Edit or delete it, then start blogging!'),
     168                                'post_excerpt' => '',
     169                                'post_title' => __('Hello world!'),
     170                                'post_category' => 0,
     171                                'post_name' => _c('hello-world|Default post slug'),
     172                                'post_modified' => $now,
     173                                'post_modified_gmt' => $now_gmt,
     174                                'guid' => $first_post_guid,
     175                                'comment_count' => 1,
     176                                'to_ping' => '',
     177                                'pinged' => '',
     178                                'post_content_filtered' => ''
     179                                ));
     180    $wpdb->insert( $wpdb->term_relationships, array('term_taxonomy_id' => 1, 'object_id' => 1) );
    135181
    136182    // Default comment
    137     $wpdb->query("INSERT INTO $wpdb->comments (comment_post_ID, comment_author, comment_author_email, comment_author_url, comment_date, comment_date_gmt, comment_content) VALUES ('1', '".$wpdb->escape(__('Mr WordPress'))."', '', 'http://wordpress.org/', '$now', '$now_gmt', '".$wpdb->escape(__('Hi, this is a comment.<br />To delete a comment, just log in and view the post&#039;s comments. There you will have the option to edit or delete them.'))."')");
    138 
     183    $wpdb->insert( $wpdb->comments, array(
     184                                'comment_post_ID' => 1,
     185                                'comment_author' => __('Mr WordPress'),
     186                                'comment_author_email' => '',
     187                                'comment_author_url' => 'http://wordpress.org/',
     188                                'comment_date' => $now,
     189                                'comment_date_gmt' => $now_gmt,
     190                                'comment_content' => __('Hi, this is a comment.<br />To delete a comment, just log in and view the post&#039;s comments. There you will have the option to edit or delete them.')
     191                                ));
    139192    // First Page
    140193    $first_post_guid = get_option('home') . '/?page_id=2';
    141     $wpdb->query("INSERT INTO $wpdb->posts (post_author, post_date, post_date_gmt, post_content, post_excerpt, post_title, post_category, post_name, post_modified, post_modified_gmt, guid, post_status, post_type, to_ping, pinged, post_content_filtered) VALUES ($user_id, '$now', '$now_gmt', '".$wpdb->escape(__('This is an example of a WordPress page, you could edit this to put information about yourself or your site so readers know where you are coming from. You can create as many pages like this one or sub-pages as you like and manage all of your content inside of WordPress.'))."', '', '".$wpdb->escape(__('About'))."', '0', '".$wpdb->escape(_c('about|Default page slug'))."', '$now', '$now_gmt','$first_post_guid', 'publish', 'page', '', '', '')");
     194    $wpdb->insert( $wpdb->posts, array(
     195                                'post_author' => $user_id,
     196                                'post_date' => $now,
     197                                'post_date_gmt' => $now_gmt,
     198                                'post_content' => __('This is an example of a WordPress page, you could edit this to put information about yourself or your site so readers know where you are coming from. You can create as many pages like this one or sub-pages as you like and manage all of your content inside of WordPress.'),
     199                                'post_excerpt' => '',
     200                                'post_title' => __('About'),
     201                                'post_category' => '',
     202                                'post_name' => _c('about|Default page slug'),
     203                                'post_modified' => $now,
     204                                'post_modified_gmt' => $now_gmt,
     205                                'guid' => $first_post_guid,
     206                                'post_type' => 'page',
     207                                'to_ping' => '',
     208                                'pinged' => '',
     209                                'post_content_filtered' => ''
     210                                ));
    142211}
    143212endif;
     
    307376        if ('' == $category->category_nicename) {
    308377            $newtitle = sanitize_title($category->cat_name);
    309             $wpdb->query( $wpdb->prepare("UPDATE $wpdb->categories SET category_nicename = %s WHERE cat_ID = %d", $newtitle, $category->cat_ID) );
     378            $wpdb>update( $wpdb->categories, array('category_nicename' => $newtitle), array('cat_ID' => $category->cat_ID) );
    310379        }
    311380    }
     
    331400            $cat = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->post2cat WHERE post_id = %d AND category_id = %d", $post->ID, $post->post_category) );
    332401            if (!$cat && 0 != $post->post_category) { // If there's no result
    333                 $wpdb->query( $wpdb->prepare("INSERT INTO $wpdb->post2cat
    334                     (post_id, category_id)
    335                     VALUES (%s, %s)
    336                     ", $post->ID, $post->post_category) );
     402                $wpdb->insert( $wpdb->post2cat, array('post_id' => $post->ID, 'category_id' => $post->post_category) );
    337403            }
    338404        }
     
    371437        if ('' == $user->user_nicename) {
    372438            $newname = sanitize_title($user->user_nickname);
    373             $wpdb->query( $wpdb->prepare("UPDATE $wpdb->users SET user_nicename = %s WHERE ID = %d", $newname, $user->ID) );
     439            $wpdb->update( $wpdb->users, array('user_nicename' => $newname), array('ID' => $user->ID) );
    374440        }
    375441    }
     
    378444    foreach ($users as $row) {
    379445        if (!preg_match('/^[A-Fa-f0-9]{32}$/', $row->user_pass)) {
    380             $wpdb->query('UPDATE '.$wpdb->users.' SET user_pass = MD5(\''.$row->user_pass.'\') WHERE ID = \''.$row->ID.'\'');
     446            $wpdb->update( $wpdb->users, array('user_pass' => md5($row->user_pass)), array('ID' => $row->ID) );
    381447        }
    382448    }
     
    438504                $guid = $post->guid;
    439505
    440             $wpdb->query("UPDATE $wpdb->posts SET post_title = '$post_title', post_content = '$post_content', post_excerpt = '$post_excerpt', guid = '$guid' WHERE ID = '$post->ID'");
     506            $wpdb->update( $wpdb->posts, compact('post_title', 'post_content', 'post_excerpt', 'guid'), array('ID' => $post->ID) );
     507
    441508        }
    442509    }
     
    446513    if ($comments) {
    447514        foreach($comments as $comment) {
    448             $comment_content = addslashes(deslash($comment->comment_content));
    449             $comment_author = addslashes(deslash($comment->comment_author));
    450             $wpdb->query("UPDATE $wpdb->comments SET comment_content = '$comment_content', comment_author = '$comment_author' WHERE comment_ID = '$comment->comment_ID'");
     515            $comment_content = deslash($comment->comment_content);
     516            $comment_author = deslash($comment->comment_author);
     517           
     518            $wpdb->update($wpdb->comments, compact('comment_content', 'comment_author'), array('comment_ID' => $comment->comment_ID) );
    451519        }
    452520    }
     
    456524    if ($links) {
    457525        foreach($links as $link) {
    458             $link_name = addslashes(deslash($link->link_name));
    459             $link_description = addslashes(deslash($link->link_description));
    460             $wpdb->query("UPDATE $wpdb->links SET link_name = '$link_name', link_description = '$link_description' WHERE link_id = '$link->link_id'");
     526            $link_name = deslash($link->link_name);
     527            $link_description = deslash($link->link_description);
     528           
     529            $wpdb->update( $wpdb->links, compact('link_name', 'link_description'), array('link_id' => $link->link_id) );
    461530        }
    462531    }
    463532
    464533    // The "paged" option for what_to_show is no more.
    465     if ($wpdb->get_var("SELECT option_value FROM $wpdb->options WHERE option_name = 'what_to_show'") == 'paged') {
    466         $wpdb->query("UPDATE $wpdb->options SET option_value = 'posts' WHERE option_name = 'what_to_show'");
    467     }
     534    if ($wpdb->get_var("SELECT option_value FROM $wpdb->options WHERE option_name = 'what_to_show'") == 'paged')
     535        $wpdb->update( $wpdb->options, array('option_value' => 'posts'), array('option_name' => 'what_to_show') );
    468536
    469537    $active_plugins = __get_option('active_plugins');
     
    540608            if ($idmode == 'namelf') $id = $user->user_lastname.' '.$user->user_firstname;
    541609            if (!$idmode) $id = $user->user_nickname;
    542             $wpdb->query( $wpdb->prepare("UPDATE $wpdb->users SET display_name = %s WHERE ID = %d", $id, $user->ID) );
     610            $wpdb->update( $wpdb->users, array('display_name' => $id), array('ID' => $user->ID) );
    543611        endif;
    544612
     
    560628    // populate comment_count field of posts table
    561629    $comments = $wpdb->get_results( "SELECT comment_post_ID, COUNT(*) as c FROM $wpdb->comments WHERE comment_approved = '1' GROUP BY comment_post_ID" );
    562     if( is_array( $comments ) ) {
    563         foreach ($comments as $comment) {
    564             $wpdb->query( $wpdb->prepare("UPDATE $wpdb->posts SET comment_count = %d WHERE ID = %d", $comment->c, $comment->comment_post_ID) );
    565         }
    566     }
     630    if( is_array( $comments ) )
     631        foreach ($comments as $comment)
     632            $wpdb->update( $wpdb->posts, array('comment_count' => $comment->c), array('ID' => $comment->comment_post_ID) );
    567633
    568634    // Some alpha versions used a post status of object instead of attachment and put
     
    571637        $objects = $wpdb->get_results("SELECT ID, post_type FROM $wpdb->posts WHERE post_status = 'object'");
    572638        foreach ($objects as $object) {
    573             $wpdb->query( $wpdb->prepare("UPDATE $wpdb->posts SET post_status = 'attachment',
    574             post_mime_type = %s,
    575             post_type = ''
    576             WHERE ID = %d", $object->post_type, $object->ID) );
     639            $wpdb->update( $wpdb->posts, array( 'post_status' => 'attachment',
     640                                                'post_mime_type' => $object->post_type,
     641                                                'post_type' => ''),
     642                                         array( 'ID' => $object->ID ) );
    577643
    578644            $meta = get_post_meta($object->ID, 'imagedata', true);
     
    692758            $count = (int) $category->tag_count;
    693759            $taxonomy = 'post_tag';
    694             $wpdb->query( $wpdb->prepare("INSERT INTO $wpdb->term_taxonomy (term_id, taxonomy, description, parent, count) VALUES ( %d, %s, %s, %d, %d)", $term_id, $taxonomy, $description, $parent, $count) );
     760            $wpdb->insert( $wpdb->term_taxonomy, compact('term_id', 'taxonomy', 'description', 'parent', 'count') );
    695761            $tt_ids[$term_id][$taxonomy] = (int) $wpdb->insert_id;
    696762        }
     
    699765            $count = 0;
    700766            $taxonomy = 'category';
    701             $wpdb->query( $wpdb->prepare("INSERT INTO $wpdb->term_taxonomy (term_id, taxonomy, description, parent, count) VALUES ( %d, %s, %s, %d, %d)", $term_id, $taxonomy, $description, $parent, $count) );
     767            $wpdb->insert( $wpdb->term_taxonomy, compact('term_id', 'taxonomy', 'description', 'parent', 'count') );
    702768            $tt_ids[$term_id][$taxonomy] = (int) $wpdb->insert_id;
    703769        }
     
    719785            continue;
    720786
    721         $wpdb->query( $wpdb->prepare("INSERT INTO $wpdb->term_relationships (object_id, term_taxonomy_id) VALUES ( %d, %d)", $post_id, $tt_id) );
     787        $wpdb->insert( $wpdb->term_relationships, array('object_id' => $post_id, 'term_taxonomy_id' => $tt_id) );
    722788    }
    723789
     
    744810
    745811            if ( empty($term_id) ) {
    746                 $wpdb->query( $wpdb->prepare("INSERT INTO $wpdb->terms (name, slug, term_group) VALUES (%s, %s, %d)", $name, $slug, $term_group) );
     812                $wpdb->insert( $wpdb->terms, compact('name', 'slug', 'term_group') );
    747813                $term_id = (int) $wpdb->insert_id;
    748814            }
     
    751817            $default_link_cat = $term_id;
    752818
    753             $wpdb->query( $wpdb->prepare("INSERT INTO $wpdb->term_taxonomy (term_id, taxonomy, description, parent, count) VALUES (%d, 'link_category', '', '0', '0')", $term_id) );
     819            $wpdb->insert( $wpdb->term_taxonomy, array('term_id' => $term_id, 'taxonomy' => 'link_category', 'description' => '', 'parent' => 0, 'count' => 0) );
    754820            $tt_ids[$term_id] = (int) $wpdb->insert_id;
    755821        }
     
    767833                continue;
    768834
    769             $wpdb->query( $wpdb->prepare("INSERT INTO $wpdb->term_relationships (object_id, term_taxonomy_id) VALUES ( %d, %d)", $link->link_id, $tt_id) );
     835            $wpdb->insert( $wpdb->term_relationships, array('object_id' => $link->link_id, 'term_taxonomy_id' => $tt_id) );
    770836        }
    771837
     
    781847            if ( empty($tt_id) )
    782848                continue;
    783 
    784             $wpdb->query( $wpdb->prepare("INSERT INTO $wpdb->term_relationships (object_id, term_taxonomy_id) VALUES ( %d, %d)", $link_id, $tt_id) );
     849            $wpdb->insert( $wpdb->term_relationships, array('object_id' => $link_id, 'term_taxonomy_id' => $tt_id) );
    785850        }
    786851    }
     
    798863        else
    799864            $count = $wpdb->get_var( $wpdb->prepare("SELECT COUNT(*) FROM $wpdb->term_relationships WHERE term_taxonomy_id = %d", $term->term_taxonomy_id) );
    800         $wpdb->query( $wpdb->prepare("UPDATE $wpdb->term_taxonomy SET count = %d WHERE term_taxonomy_id = %d", $count, $term->term_taxonomy_id) );
     865        $wpdb->update( $wpdb->term_taxonomy, array('count' => $count), array('term_taxonomy_id' => $term->term_taxonomy_id) );
    801866    }
    802867}
  • trunk/wp-includes/comment.php

    r10681 r10730  
    10211021    global $wpdb;
    10221022
     1023    $status = '0';
    10231024    switch ( $comment_status ) {
    10241025        case 'hold':
    1025             $query = $wpdb->prepare("UPDATE $wpdb->comments SET comment_approved='0' WHERE comment_ID = %d LIMIT 1", $comment_id);
     1026            $status = '0';
    10261027            break;
    10271028        case 'approve':
    1028             $query = $wpdb->prepare("UPDATE $wpdb->comments SET comment_approved='1' WHERE comment_ID = %d LIMIT 1", $comment_id);
     1029            $status = '1';
    10291030            if ( get_option('comments_notify') ) {
    10301031                $comment = get_comment($comment_id);
     
    10331034            break;
    10341035        case 'spam':
    1035             $query = $wpdb->prepare("UPDATE $wpdb->comments SET comment_approved='spam' WHERE comment_ID = %d LIMIT 1", $comment_id);
     1036            $status = 'spam';
    10361037            break;
    10371038        case 'delete':
     
    10421043    }
    10431044
    1044     if ( !$wpdb->query($query) ) {
     1045    if ( !$wpdb->update( $wpdb->comments, array('comment_approved' => $status), array('comment_ID' => $comment_id) ) ) {
    10451046        if ( $wp_error )
    10461047            return new WP_Error('db_update_error', __('Could not update comment status'), $wpdb->last_error);
     
    13511352    $pinged  = get_pung($post_id);
    13521353    if ( empty($to_ping) ) {
    1353         $wpdb->query( $wpdb->prepare("UPDATE $wpdb->posts SET to_ping = '' WHERE ID = %d", $post_id) );
     1354        $wpdb->update($wpdb->posts, array('to_ping' => ''), array('ID' => $post_id) );
    13541355        return;
    13551356    }
  • trunk/wp-includes/functions.php

    r10665 r10730  
    518518    }
    519519
    520     $wpdb->query( $wpdb->prepare( "UPDATE $wpdb->options SET option_value = %s WHERE option_name = %s", $newvalue, $option_name ) );
     520    $wpdb->update($wpdb->options, array('option_value' => $newvalue), array('option_name' => $option_name) );
     521
    521522    if ( $wpdb->rows_affected == 1 ) {
    522523        do_action( "update_option_{$option_name}", $oldvalue, $_newvalue );
     
    585586    }
    586587
    587     $wpdb->query( $wpdb->prepare( "INSERT INTO $wpdb->options (option_name, option_value, autoload) VALUES (%s, %s, %s)", $name, $value, $autoload ) );
     588    $wpdb->insert($wpdb->options, array('option_name' => $name, 'option_value' => $value, 'autoload' => $autoload) );
    588589
    589590    do_action( "add_option_{$name}", $name, $value );
     
    10911092            if ( $headers = wp_get_http_headers( $url) ) {
    10921093                $len = (int) $headers['content-length'];
    1093                 $type = $wpdb->escape( $headers['content-type'] );
     1094                $type = $headers['content-type'];
    10941095                $allowed_types = array( 'video', 'audio' );
    10951096                if ( in_array( substr( $type, 0, strpos( $type, "/" ) ), $allowed_types ) ) {
    10961097                    $meta_value = "$url\n$len\n$type\n";
    1097                     $wpdb->query( $wpdb->prepare( "INSERT INTO `$wpdb->postmeta` ( `post_id` , `meta_key` , `meta_value` )
    1098                     VALUES ( %d, 'enclosure' , %s)", $post_ID, $meta_value ) );
     1098                    $wpdb->insert($wpdb->postmeta, array('post_id' => $post_ID, 'meta_key' => 'enclosure', 'meta_value' => $meta_value) );
    10991099                }
    11001100            }
  • trunk/wp-includes/pluggable.php

    r10691 r10730  
    14591459
    14601460    $hash = wp_hash_password($password);
    1461     $query = $wpdb->prepare("UPDATE $wpdb->users SET user_pass = %s, user_activation_key = '' WHERE ID = %d", $hash, $user_id);
    1462     $wpdb->query($query);
     1461    $wpdb->update($wpdb->users, array('user_pass' => $hash, 'user_activation_key' => ''), array('ID' => $user_id) );
     1462
    14631463    wp_cache_delete($user_id, 'users');
    14641464}
  • trunk/wp-includes/post.php

    r10725 r10730  
    425425
    426426    $post_type = sanitize_post_field('post_type', $post_type, $post_id, 'db');
    427     $return = $wpdb->query( $wpdb->prepare("UPDATE $wpdb->posts SET post_type = %s WHERE ID = %d", $post_type, $post_id) );
     427    $return = $wpdb->update($wpdb->posts, array('post_type' => $post_type), array('ID' => $post_id) );
    428428
    429429    if ( 'page' == $post_type )
  • trunk/wp-includes/taxonomy.php

    r10637 r10730  
    13301330            // The alias isn't in a group, so let's create a new one and firstly add the alias term to it.
    13311331            $term_group = $wpdb->get_var("SELECT MAX(term_group) FROM $wpdb->terms") + 1;
    1332             $wpdb->query( $wpdb->prepare( "UPDATE $wpdb->terms SET term_group = %d WHERE term_id = %d", $term_group, $alias->term_id ) );
     1332            $wpdb->update($wpdb->terms, compact('term_group'), array('term_id' => $alias->term_id) );
    13331333        }
    13341334    }
  • trunk/wp-includes/user.php

    r10683 r10730  
    400400
    401401    $cur = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->usermeta WHERE user_id = %d AND meta_key = %s", $user_id, $meta_key) );
    402     if ( !$cur ) {
    403         $wpdb->query( $wpdb->prepare("INSERT INTO $wpdb->usermeta ( user_id, meta_key, meta_value )
    404         VALUES
    405         ( %d, %s, %s )", $user_id, $meta_key, $meta_value) );
    406     } else if ( $cur->meta_value != $meta_value ) {
    407         $wpdb->query( $wpdb->prepare("UPDATE $wpdb->usermeta SET meta_value = %s WHERE user_id = %d AND meta_key = %s", $meta_value, $user_id, $meta_key) );
    408     } else {
     402    if ( !$cur )
     403        $wpdb->insert($wpdb->usermeta, compact('user_id', 'meta_key', 'meta_value') );
     404    else if ( $cur->meta_value != $meta_value )
     405        $wpdb->update($wpdb->usermeta, compact('meta_value'), compact('user_id', 'meta_key') );
     406    else
    409407        return false;
    410     }
    411408
    412409    wp_cache_delete($user_id, 'users');
  • trunk/wp-login.php

    r10705 r10730  
    141141        do_action('retrieve_password_key', $user_login, $key);
    142142        // Now insert the new md5 key into the db
    143         $wpdb->query($wpdb->prepare("UPDATE $wpdb->users SET user_activation_key = %s WHERE user_login = %s", $key, $user_login));
     143        $wpdb->update($wpdb->users, array('user_activation_key' => $key), array('user_login' => $user_login));
    144144    }
    145145    $message = __('Someone has asked to reset the password for the following site and username.') . "\r\n\r\n";
  • trunk/xmlrpc.php

    r10587 r10730  
    22742274            foreach( $attachments as $file ) {
    22752275                if( strpos( $post_content, $file->guid ) !== false ) {
    2276                     $wpdb->query( $wpdb->prepare("UPDATE {$wpdb->posts} SET post_parent = %d WHERE ID = %d", $post_ID, $file->ID) );
     2276                    $wpdb->update($wpdb->posts, array('post_parent' => $post_ID), array('ID' => $file->ID) );
    22772277                }
    22782278            }
Note: See TracChangeset for help on using the changeset viewer.