Changeset 7645 for trunk/wp-admin/includes/upgrade.php
- Timestamp:
- 04/14/2008 04:13:25 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/includes/upgrade.php
r7628 r7645 219 219 if ('' == $post->post_name) { 220 220 $newtitle = sanitize_title($post->post_title); 221 $wpdb->query( "UPDATE $wpdb->posts SET post_name = '$newtitle' WHERE ID = '$post->ID'");221 $wpdb->query( $wpdb->prepare("UPDATE $wpdb->posts SET post_name = %s WHERE ID = %d", $newtitle, $post->ID) ); 222 222 } 223 223 } … … 228 228 if ('' == $category->category_nicename) { 229 229 $newtitle = sanitize_title($category->cat_name); 230 $wpdb->query( "UPDATE $wpdb->categories SET category_nicename = '$newtitle' WHERE cat_ID = '$category->cat_ID'");230 $wpdb->query( $wpdb->prepare("UPDATE $wpdb->categories SET category_nicename = %s WHERE cat_ID = %d", $newtitle, $category->cat_ID) ); 231 231 } 232 232 } … … 251 251 foreach ($allposts as $post) { 252 252 // Check to see if it's already been imported 253 $cat = $wpdb->get_row( "SELECT * FROM $wpdb->post2cat WHERE post_id = $post->ID AND category_id = $post->post_category");253 $cat = $wpdb->get_row( $wpdb->("SELECT * FROM $wpdb->post2cat WHERE post_id = %d AND category_id = %d", $post->ID, $post->post_category) ); 254 254 if (!$cat && 0 != $post->post_category) { // If there's no result 255 $wpdb->query(" 256 INSERT INTO $wpdb->post2cat 255 $wpdb->query( $wpdb->prepare("INSERT INTO $wpdb->post2cat 257 256 (post_id, category_id) 258 VALUES 259 ('$post->ID', '$post->post_category') 260 "); 257 VALUES (%s, %s) 258 ", $post->ID, $post->post_category) ); 261 259 } 262 260 } … … 286 284 if ('' == $user->user_nicename) { 287 285 $newname = sanitize_title($user->user_nickname); 288 $wpdb->query( "UPDATE $wpdb->users SET user_nicename = '$newname' WHERE ID = '$user->ID'");286 $wpdb->query( $wpdb->prepare("UPDATE $wpdb->users SET user_nicename = %s WHERE ID = %d", $newname, $user->ID) ); 289 287 } 290 288 } … … 402 400 if ( 1 != $option->dupes ) { // Could this be done in the query? 403 401 $limit = $option->dupes - 1; 404 $dupe_ids = $wpdb->get_col( "SELECT option_id FROM $wpdb->options WHERE option_name = '$option->option_name' LIMIT $limit");402 $dupe_ids = $wpdb->get_col( $wpdb->prepare("SELECT option_id FROM $wpdb->options WHERE option_name = %s LIMIT %d", $option->option_name, $limit) ); 405 403 $dupe_ids = join($dupe_ids, ','); 406 404 $wpdb->query("DELETE FROM $wpdb->options WHERE option_id IN ($dupe_ids)"); … … 446 444 if ($idmode == 'namelf') $id = $user->user_lastname.' '.$user->user_firstname; 447 445 if (!$idmode) $id = $user->user_nickname; 448 $id = $wpdb->escape( $id ); 449 $wpdb->query("UPDATE $wpdb->users SET display_name = '$id' WHERE ID = '$user->ID'"); 446 $wpdb->query( $wpdb->prepare("UPDATE $wpdb->users SET display_name = %s WHERE ID = %d", $id, $user->ID) ); 450 447 endif; 451 448 … … 469 466 if( is_array( $comments ) ) { 470 467 foreach ($comments as $comment) { 471 $wpdb->query( "UPDATE $wpdb->posts SET comment_count = $comment->c WHERE ID = '$comment->comment_post_ID'");468 $wpdb->query( $wpdb->prepare("UPDATE $wpdb->posts SET comment_count = %d WHERE ID = %d", $comment->c, $comment->comment_post_ID) ); 472 469 } 473 470 } … … 478 475 $objects = $wpdb->get_results("SELECT ID, post_type FROM $wpdb->posts WHERE post_status = 'object'"); 479 476 foreach ($objects as $object) { 480 $wpdb->query( "UPDATE $wpdb->posts SET post_status = 'attachment',481 post_mime_type = '$object->post_type',477 $wpdb->query( $wpdb->prepare("UPDATE $wpdb->posts SET post_status = 'attachment', 478 post_mime_type = %s, 482 479 post_type = '' 483 WHERE ID = $object->ID");480 WHERE ID = %d", $object->post_type, $object->ID) ); 484 481 485 482 $meta = get_post_meta($object->ID, 'imagedata', true); … … 509 506 } 510 507 511 $wpdb->query( "UPDATE $wpdb->posts SET post_status = '$status', post_type = '$type' WHERE ID = '$post->ID'");508 $wpdb->query( $wpdb->prepare("UPDATE $wpdb->posts SET post_status = %s, post_type = %s WHERE ID = %d", $status, $type, $post->ID) ); 512 509 } 513 510 } … … 542 539 foreach ($categories as $category) { 543 540 $term_id = (int) $category->cat_ID; 544 $name = $wpdb->escape($category->cat_name);545 $description = $wpdb->escape($category->category_description);546 $slug = $wpdb->escape($category->category_nicename);547 $parent = $wpdb->escape($category->category_parent);548 541 $term_group = 0; 549 542 550 543 // Associate terms with the same slug in a term group and make slugs unique. 551 if ( $exists = $wpdb->get_results( "SELECT term_id, term_group FROM $wpdb->terms WHERE slug = '$slug'") ) {544 if ( $exists = $wpdb->get_results( $wpdb->prepare("SELECT term_id, term_group FROM $wpdb->terms WHERE slug = %s", $slug) ) ) { 552 545 $term_group = $exists[0]->term_group; 553 546 $id = $exists[0]->term_id; … … 556 549 $alt_slug = $slug . "-$num"; 557 550 $num++; 558 $slug_check = $wpdb->get_var( "SELECT slug FROM $wpdb->terms WHERE slug = '$alt_slug'");551 $slug_check = $wpdb->get_var( $wpdb->prepare("SELECT slug FROM $wpdb->terms WHERE slug = %s", $alt_slug) ); 559 552 } while ( $slug_check ); 560 553 … … 563 556 if ( empty( $term_group ) ) { 564 557 $term_group = $wpdb->get_var("SELECT MAX(term_group) FROM $wpdb->terms GROUP BY term_group") + 1; 565 $wpdb->query( "UPDATE $wpdb->terms SET term_group = '$term_group' WHERE term_id = '$id'");558 $wpdb->query( $wpdb->prepare("UPDATE $wpdb->terms SET term_group = %d WHERE term_id = %d", $term_group, $id) ); 566 559 } 567 560 } 568 561 569 $wpdb->query("INSERT INTO $wpdb->terms (term_id, name, slug, term_group) VALUES ('$term_id', '$name', '$slug', '$term_group')"); 562 $wpdb->query( $wpdb->prepare("INSERT INTO $wpdb->terms (term_id, name, slug, term_group) VALUES 563 (%d, %s, %s, %d)", $term_id, $name, $slug, $term_group) ); 570 564 571 565 $count = 0; … … 573 567 $count = (int) $category->category_count; 574 568 $taxonomy = 'category'; 575 $wpdb->query( "INSERT INTO $wpdb->term_taxonomy (term_id, taxonomy, description, parent, count) VALUES ('$term_id', '$taxonomy', '$description', '$parent', '$count')");569 $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) ); 576 570 $tt_ids[$term_id][$taxonomy] = (int) $wpdb->insert_id; 577 571 } … … 580 574 $count = (int) $category->link_count; 581 575 $taxonomy = 'link_category'; 582 $wpdb->query( "INSERT INTO $wpdb->term_taxonomy (term_id, taxonomy, description, parent, count) VALUES ('$term_id', '$taxonomy', '$description', '$parent', '$count')");576 $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) ); 583 577 $tt_ids[$term_id][$taxonomy] = (int) $wpdb->insert_id; 584 578 } … … 588 582 $count = (int) $category->tag_count; 589 583 $taxonomy = 'post_tag'; 590 $wpdb->query( "INSERT INTO $wpdb->term_taxonomy (term_id, taxonomy, description, parent, count) VALUES ('$term_id', '$taxonomy', '$description', '$parent', '$count')");584 $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) ); 591 585 $tt_ids[$term_id][$taxonomy] = (int) $wpdb->insert_id; 592 586 } … … 595 589 $count = 0; 596 590 $taxonomy = 'category'; 597 $wpdb->query( "INSERT INTO $wpdb->term_taxonomy (term_id, taxonomy, description, parent, count) VALUES ('$term_id', '$taxonomy', '$description', '$parent', '$count')");591 $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) ); 598 592 $tt_ids[$term_id][$taxonomy] = (int) $wpdb->insert_id; 599 593 } … … 615 609 continue; 616 610 617 $wpdb->query( "INSERT INTO $wpdb->term_relationships (object_id, term_taxonomy_id) VALUES ('$post_id', '$tt_id')");611 $wpdb->query( $wpdb->prepare("INSERT INTO $wpdb->term_relationships (object_id, term_taxonomy_id) VALUES ( %d, %d)", $post_id, $tt_id) ); 618 612 } 619 613 … … 634 628 635 629 // Associate terms with the same slug in a term group and make slugs unique. 636 if ( $exists = $wpdb->get_results( "SELECT term_id, term_group FROM $wpdb->terms WHERE slug = '$slug'") ) {630 if ( $exists = $wpdb->get_results( $wpdb->prepare("SELECT term_id, term_group FROM $wpdb->terms WHERE slug = %s", $slug) ) ) { 637 631 $term_group = $exists[0]->term_group; 638 632 $term_id = $exists[0]->term_id; … … 640 634 641 635 if ( empty($term_id) ) { 642 $wpdb->query( "INSERT INTO $wpdb->terms (name, slug, term_group) VALUES ('$name', '$slug', '$term_group')");636 $wpdb->query( $wpdb->prepare("INSERT INTO $wpdb->terms (name, slug, term_group) VALUES (%s, %s, %d)", $name, $slug, $term_group) ); 643 637 $term_id = (int) $wpdb->insert_id; 644 638 } … … 647 641 $default_link_cat = $term_id; 648 642 649 $wpdb->query( "INSERT INTO $wpdb->term_taxonomy (term_id, taxonomy, description, parent, count) VALUES ('$term_id', 'link_category', '', '0', '0')");643 $wpdb->query( $wpdb->prepare("INSERT INTO $wpdb->term_taxonomy (term_id, taxonomy, description, parent, count) VALUES (%d, 'link_category', '', '0', '0')", $term_id) ); 650 644 $tt_ids[$term_id] = (int) $wpdb->insert_id; 651 645 } … … 663 657 continue; 664 658 665 $wpdb->query( "INSERT INTO $wpdb->term_relationships (object_id, term_taxonomy_id) VALUES ('$link->link_id', '$tt_id')");659 $wpdb->query( $wpdb->prepare("INSERT INTO $wpdb->term_relationships (object_id, term_taxonomy_id) VALUES ( %d, %d)", $link->link_id, $tt_id) ); 666 660 } 667 661 … … 678 672 continue; 679 673 680 $wpdb->query("INSERT INTO $wpdb->term_relationships (object_id, term_taxonomy_id) VALUES ( '$link_id', '$tt_id')");674 $wpdb->query("INSERT INTO $wpdb->term_relationships (object_id, term_taxonomy_id) VALUES ( %d, %d)", $link_id, $tt_id) ); 681 675 } 682 676 } … … 691 685 foreach ( (array) $terms as $term ) { 692 686 if ( ('post_tag' == $term->taxonomy) || ('category' == $term->taxonomy) ) 693 $count = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->term_relationships, $wpdb->posts WHERE $wpdb->posts.ID = $wpdb->term_relationships.object_id AND post_status = 'publish' AND post_type = 'post' AND term_taxonomy_id = '$term->term_taxonomy_id'");687 $count = $wpdb->get_var( $wpdb->prepare("SELECT COUNT(*) FROM $wpdb->term_relationships, $wpdb->posts WHERE $wpdb->posts.ID = $wpdb->term_relationships.object_id AND post_status = 'publish' AND post_type = 'post' AND term_taxonomy_id = %d", $term->term_taxonomy_id) ); 694 688 else 695 $count = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->term_relationships WHERE term_taxonomy_id = '$term->term_taxonomy_id'");696 $wpdb->query( "UPDATE $wpdb->term_taxonomy SET count = '$count' WHERE term_taxonomy_id = '$term->term_taxonomy_id'");689 $count = $wpdb->get_var( $wpdb->prepare("SELECT COUNT(*) FROM $wpdb->term_relationships WHERE term_taxonomy_id = %d", $term->term_taxonomy_id) ); 690 $wpdb->query( $wpdb->prepare("UPDATE $wpdb->term_taxonomy SET count = %d WHERE term_taxonomy_id = %d", $count, $term->term_taxonomy_id) ); 697 691 } 698 692 } … … 824 818 } 825 819 826 $option = $wpdb->get_var( "SELECT option_value FROM $wpdb->options WHERE option_name = '$setting'");820 $option = $wpdb->get_var( $wpdb->prepare("SELECT option_value FROM $wpdb->options WHERE option_name = %s", $setting) ); 827 821 828 822 if ( 'home' == $setting && '' == $option )
Note: See TracChangeset
for help on using the changeset viewer.