Changeset 5827 for trunk/src/includes/admin/tools.php
- Timestamp:
- 07/14/2015 12:31:42 AM (11 years ago)
- File:
-
- 1 edited
-
trunk/src/includes/admin/tools.php (modified) (71 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/includes/admin/tools.php
r5783 r5827 241 241 */ 242 242 function bbp_admin_tools_feedback( $message, $class = false ) { 243 244 // Dismiss button 245 $dismiss = '<button type="button" class="notice-dismiss"><span class="screen-reader-text">' . __( 'Dismiss this notice.', 'bbpress' ) . '</span></button>'; 246 247 // One message as string 243 248 if ( is_string( $message ) ) { 244 249 $message = '<p>' . $message . '</p>'; 245 $class = $class ? $class : 'updated'; 250 $class = $class ? $class : 'updated'; 251 252 // Messages as objects 246 253 } elseif ( is_wp_error( $message ) ) { 247 $errors = $message->get_error_messages();254 $errors = $message->get_error_messages(); 248 255 249 256 switch ( count( $errors ) ) { … … 260 267 } 261 268 262 $class = $class ? $class : ' error';269 $class = $class ? $class : 'is-error'; 263 270 } else { 264 271 return false; 265 272 } 266 273 267 $message = '<div id="message" class="' . esc_attr( $class ) . '">' . $message . '</div>'; 274 // Assemble the message 275 $message = '<div id="message" class="is-dismissible notice ' . esc_attr( $class ) . '">' . $message . $dismiss . '</div>'; 268 276 $message = str_replace( "'", "\'", $message ); 277 278 // Ugh 269 279 $lambda = create_function( '', "echo '$message';" ); 270 271 280 add_action( 'admin_notices', $lambda ); 272 281 … … 323 332 */ 324 333 function bbp_admin_repair_topic_reply_count() { 325 global $wpdb; 326 334 335 // Define variables 336 $bbp_db = bbp_db(); 327 337 $statement = __( 'Counting the number of replies in each topic… %s', 'bbpress' ); 328 338 $result = __( 'Failed!', 'bbpress' ); … … 335 345 336 346 // Delete the meta key _bbp_reply_count for each topic 337 $sql_delete = "DELETE `postmeta` FROM `{$ wpdb->postmeta}` AS `postmeta`338 LEFT JOIN `{$ wpdb->posts}` AS `posts` ON `posts`.`ID` = `postmeta`.`post_id`347 $sql_delete = "DELETE `postmeta` FROM `{$bbp_db->postmeta}` AS `postmeta` 348 LEFT JOIN `{$bbp_db->posts}` AS `posts` ON `posts`.`ID` = `postmeta`.`post_id` 339 349 WHERE `posts`.`post_type` = '{$tpt}' 340 350 AND `postmeta`.`meta_key` = '_bbp_reply_count'"; 341 351 342 if ( is_wp_error( $ wpdb->query( $sql_delete ) ) ) {352 if ( is_wp_error( $bbp_db->query( $sql_delete ) ) ) { 343 353 return array( 1, sprintf( $statement, $result ) ); 344 354 } 345 355 346 356 // Recalculate the meta key _bbp_reply_count for each topic 347 $sql = "INSERT INTO `{$ wpdb->postmeta}` (`post_id`, `meta_key`, `meta_value`) (357 $sql = "INSERT INTO `{$bbp_db->postmeta}` (`post_id`, `meta_key`, `meta_value`) ( 348 358 SELECT `topics`.`ID` AS `post_id`, '_bbp_reply_count' AS `meta_key`, COUNT(`replies`.`ID`) As `meta_value` 349 FROM `{$ wpdb->posts}` AS `topics`350 LEFT JOIN `{$ wpdb->posts}` as `replies`359 FROM `{$bbp_db->posts}` AS `topics` 360 LEFT JOIN `{$bbp_db->posts}` as `replies` 351 361 ON `replies`.`post_parent` = `topics`.`ID` 352 362 AND `replies`.`post_status` = '{$pps}' … … 356 366 GROUP BY `topics`.`ID`);"; 357 367 358 if ( is_wp_error( $ wpdb->query( $sql ) ) ) {368 if ( is_wp_error( $bbp_db->query( $sql ) ) ) { 359 369 return array( 2, sprintf( $statement, $result ) ); 360 370 } … … 377 387 */ 378 388 function bbp_admin_repair_topic_voice_count() { 379 global $wpdb; 380 389 390 // Define variables 391 $bbp_db = bbp_db(); 381 392 $statement = __( 'Counting the number of voices in each topic… %s', 'bbpress' ); 382 393 $result = __( 'Failed!', 'bbpress' ); 383 394 384 $sql_delete = "DELETE FROM `{$ wpdb->postmeta}` WHERE `meta_key` = '_bbp_voice_count';";385 if ( is_wp_error( $ wpdb->query( $sql_delete ) ) ) {395 $sql_delete = "DELETE FROM `{$bbp_db->postmeta}` WHERE `meta_key` = '_bbp_voice_count';"; 396 if ( is_wp_error( $bbp_db->query( $sql_delete ) ) ) { 386 397 return array( 1, sprintf( $statement, $result ) ); 387 398 } … … 393 404 $cps = bbp_get_closed_status_id(); 394 405 395 $sql = "INSERT INTO `{$ wpdb->postmeta}` (`post_id`, `meta_key`, `meta_value`) (406 $sql = "INSERT INTO `{$bbp_db->postmeta}` (`post_id`, `meta_key`, `meta_value`) ( 396 407 SELECT `postmeta`.`meta_value`, '_bbp_voice_count', COUNT(DISTINCT `post_author`) as `meta_value` 397 FROM `{$ wpdb->posts}` AS `posts`398 LEFT JOIN `{$ wpdb->postmeta}` AS `postmeta`408 FROM `{$bbp_db->posts}` AS `posts` 409 LEFT JOIN `{$bbp_db->postmeta}` AS `postmeta` 399 410 ON `posts`.`ID` = `postmeta`.`post_id` 400 411 AND `postmeta`.`meta_key` = '_bbp_topic_id' … … 404 415 GROUP BY `postmeta`.`meta_value`);"; 405 416 406 if ( is_wp_error( $ wpdb->query( $sql ) ) ) {417 if ( is_wp_error( $bbp_db->query( $sql ) ) ) { 407 418 return array( 2, sprintf( $statement, $result ) ); 408 419 } … … 424 435 */ 425 436 function bbp_admin_repair_topic_hidden_reply_count() { 426 global $wpdb; 427 437 438 // Define variables 439 $bbp_db = bbp_db(); 428 440 $statement = __( 'Counting the number of spammed and trashed replies in each topic… %s', 'bbpress' ); 429 441 $result = __( 'Failed!', 'bbpress' ); 430 442 431 $sql_delete = "DELETE FROM `{$ wpdb->postmeta}` WHERE `meta_key` = '_bbp_reply_count_hidden';";432 if ( is_wp_error( $ wpdb->query( $sql_delete ) ) ) {443 $sql_delete = "DELETE FROM `{$bbp_db->postmeta}` WHERE `meta_key` = '_bbp_reply_count_hidden';"; 444 if ( is_wp_error( $bbp_db->query( $sql_delete ) ) ) { 433 445 return array( 1, sprintf( $statement, $result ) ); 434 446 } … … 439 451 $sps = bbp_get_spam_status_id(); 440 452 441 $sql = "INSERT INTO `{$ wpdb->postmeta}` (`post_id`, `meta_key`, `meta_value`) (SELECT `post_parent`, '_bbp_reply_count_hidden', COUNT(`post_status`) as `meta_value` FROM `{$wpdb->posts}` WHERE `post_type` = '{$rpt}' AND `post_status` IN ( '{$tps}', '{$sps}' ) GROUP BY `post_parent`);";442 if ( is_wp_error( $ wpdb->query( $sql ) ) ) {453 $sql = "INSERT INTO `{$bbp_db->postmeta}` (`post_id`, `meta_key`, `meta_value`) (SELECT `post_parent`, '_bbp_reply_count_hidden', COUNT(`post_status`) as `meta_value` FROM `{$bbp_db->posts}` WHERE `post_type` = '{$rpt}' AND `post_status` IN ( '{$tps}', '{$sps}' ) GROUP BY `post_parent`);"; 454 if ( is_wp_error( $bbp_db->query( $sql ) ) ) { 443 455 return array( 2, sprintf( $statement, $result ) ); 444 456 } … … 452 464 * @since bbPress (r4395) 453 465 * 454 * @global WPDB $wpdb455 466 * @uses bbp_get_forum_post_type() To get the forum post type 456 467 * @return If a wp_error() occurs and no converted forums are found 457 468 */ 458 469 function bbp_admin_repair_group_forum_relationship() { 459 global $wpdb; 460 470 471 // Define variables 472 $bbp_db = bbp_db(); 461 473 $statement = __( 'Repairing BuddyPress group-forum relationships… %s', 'bbpress' ); 462 $g_count = 0;463 $f_count = 0;464 $s_count = 0;474 $g_count = 0; 475 $f_count = 0; 476 $s_count = 0; 465 477 466 478 // Copy the BuddyPress filter here, incase BuddyPress is not active 467 $prefix = apply_filters( 'bp_core_get_table_prefix', $ wpdb->base_prefix );479 $prefix = apply_filters( 'bp_core_get_table_prefix', $bbp_db->base_prefix ); 468 480 $groups_table = $prefix . 'bp_groups'; 469 481 $groups_meta_table = $prefix . 'bp_groups_groupmeta'; 470 482 471 483 // Get the converted forum IDs 472 $forum_ids = $ wpdb->query( "SELECT `forum`.`ID`, `forummeta`.`meta_value`473 FROM `{$ wpdb->posts}` AS `forum`474 LEFT JOIN `{$ wpdb->postmeta}` AS `forummeta`484 $forum_ids = $bbp_db->query( "SELECT `forum`.`ID`, `forummeta`.`meta_value` 485 FROM `{$bbp_db->posts}` AS `forum` 486 LEFT JOIN `{$bbp_db->postmeta}` AS `forummeta` 475 487 ON `forum`.`ID` = `forummeta`.`post_id` 476 488 AND `forummeta`.`meta_key` = '_bbp_old_forum_id' … … 479 491 480 492 // Bail if forum IDs returned an error 481 if ( is_wp_error( $forum_ids ) || empty( $ wpdb->last_result ) ) {493 if ( is_wp_error( $forum_ids ) || empty( $bbp_db->last_result ) ) { 482 494 return array( 2, sprintf( $statement, __( 'Failed!', 'bbpress' ) ) ); 483 495 } 484 496 485 497 // Stash the last results 486 $results = $ wpdb->last_result;498 $results = $bbp_db->last_result; 487 499 488 500 // Update each group forum … … 495 507 496 508 // Attempt to update group meta 497 $updated = $ wpdb->query( "UPDATE `{$groups_meta_table}` SET `meta_value` = '{$group_forums->ID}' WHERE `meta_key` = 'forum_id' AND `meta_value` = '{$group_forums->meta_value}';" );509 $updated = $bbp_db->query( "UPDATE `{$groups_meta_table}` SET `meta_value` = '{$group_forums->ID}' WHERE `meta_key` = 'forum_id' AND `meta_value` = '{$group_forums->meta_value}';" ); 498 510 499 511 // Bump the count … … 503 515 504 516 // Update group to forum relationship data 505 $group_id = (int) $ wpdb->get_var( "SELECT `group_id` FROM `{$groups_meta_table}` WHERE `meta_key` = 'forum_id' AND `meta_value` = '{$group_forums->ID}';" );517 $group_id = (int) $bbp_db->get_var( "SELECT `group_id` FROM `{$groups_meta_table}` WHERE `meta_key` = 'forum_id' AND `meta_value` = '{$group_forums->ID}';" ); 506 518 if ( !empty( $group_id ) ) { 507 519 … … 510 522 511 523 // Get the group status 512 $group_status = $ wpdb->get_var( "SELECT `status` FROM `{$groups_table}` WHERE `id` = '{$group_id}';" );524 $group_status = $bbp_db->get_var( "SELECT `status` FROM `{$groups_table}` WHERE `id` = '{$group_id}';" ); 513 525 514 526 // Sync up forum visibility based on group status … … 597 609 */ 598 610 function bbp_admin_repair_forum_topic_count() { 599 global $wpdb; 600 611 612 // Define variables 613 $bbp_db = bbp_db(); 601 614 $statement = __( 'Counting the number of topics in each forum… %s', 'bbpress' ); 602 615 $result = __( 'Failed!', 'bbpress' ); 603 616 604 $sql_delete = "DELETE FROM {$ wpdb->postmeta} WHERE meta_key IN ( '_bbp_topic_count', '_bbp_total_topic_count', '_bbp_topic_count_hidden' );";605 if ( is_wp_error( $ wpdb->query( $sql_delete ) ) ) {617 $sql_delete = "DELETE FROM {$bbp_db->postmeta} WHERE meta_key IN ( '_bbp_topic_count', '_bbp_total_topic_count', '_bbp_topic_count_hidden' );"; 618 if ( is_wp_error( $bbp_db->query( $sql_delete ) ) ) { 606 619 return array( 1, sprintf( $statement, $result ) ); 607 620 } … … 633 646 */ 634 647 function bbp_admin_repair_forum_reply_count() { 635 global $wpdb; 636 648 649 // Define variables 650 $bbp_db = bbp_db(); 637 651 $statement = __( 'Counting the number of replies in each forum… %s', 'bbpress' ); 638 652 $result = __( 'Failed!', 'bbpress' ); … … 642 656 643 657 // Delete the meta keys _bbp_reply_count and _bbp_total_reply_count for each forum 644 $sql_delete = "DELETE `postmeta` FROM `{$ wpdb->postmeta}` AS `postmeta`645 LEFT JOIN `{$ wpdb->posts}` AS `posts` ON `posts`.`ID` = `postmeta`.`post_id`658 $sql_delete = "DELETE `postmeta` FROM `{$bbp_db->postmeta}` AS `postmeta` 659 LEFT JOIN `{$bbp_db->posts}` AS `posts` ON `posts`.`ID` = `postmeta`.`post_id` 646 660 WHERE `posts`.`post_type` = '{$fpt}' 647 661 AND `postmeta`.`meta_key` = '_bbp_reply_count' 648 662 OR `postmeta`.`meta_key` = '_bbp_total_reply_count'"; 649 663 650 if ( is_wp_error( $ wpdb->query( $sql_delete ) ) ) {664 if ( is_wp_error( $bbp_db->query( $sql_delete ) ) ) { 651 665 return array( 1, sprintf( $statement, $result ) ); 652 666 } … … 677 691 */ 678 692 function bbp_admin_repair_user_topic_count() { 679 global $wpdb; 680 693 694 // Define variables 695 $bbp_db = bbp_db(); 681 696 $statement = __( 'Counting the number of topics each user has created… %s', 'bbpress' ); 682 697 $result = __( 'Failed!', 'bbpress' ); 683 $sql_select = "SELECT `post_author`, COUNT(DISTINCT `ID`) as `_count` FROM `{$wpdb->posts}` WHERE `post_type` = '" . bbp_get_topic_post_type() . "' AND `post_status` = '" . bbp_get_public_status_id() . "' GROUP BY `post_author`;"; 684 $insert_rows = $wpdb->get_results( $sql_select ); 698 699 $sql_select = "SELECT `post_author`, COUNT(DISTINCT `ID`) as `_count` FROM `{$bbp_db->posts}` WHERE `post_type` = '" . bbp_get_topic_post_type() . "' AND `post_status` = '" . bbp_get_public_status_id() . "' GROUP BY `post_author`;"; 700 $insert_rows = $bbp_db->get_results( $sql_select ); 685 701 686 702 if ( is_wp_error( $insert_rows ) ) { … … 688 704 } 689 705 690 $key = $ wpdb->prefix . '_bbp_topic_count';706 $key = $bbp_db->prefix . '_bbp_topic_count'; 691 707 $insert_values = array(); 692 708 foreach ( $insert_rows as $insert_row ) { … … 698 714 } 699 715 700 $sql_delete = "DELETE FROM `{$ wpdb->usermeta}` WHERE `meta_key` = '{$key}';";701 if ( is_wp_error( $ wpdb->query( $sql_delete ) ) ) {716 $sql_delete = "DELETE FROM `{$bbp_db->usermeta}` WHERE `meta_key` = '{$key}';"; 717 if ( is_wp_error( $bbp_db->query( $sql_delete ) ) ) { 702 718 return array( 3, sprintf( $statement, $result ) ); 703 719 } … … 705 721 foreach ( array_chunk( $insert_values, 10000 ) as $chunk ) { 706 722 $chunk = "\n" . implode( ",\n", $chunk ); 707 $sql_insert = "INSERT INTO `{$ wpdb->usermeta}` (`user_id`, `meta_key`, `meta_value`) VALUES $chunk;";708 709 if ( is_wp_error( $ wpdb->query( $sql_insert ) ) ) {723 $sql_insert = "INSERT INTO `{$bbp_db->usermeta}` (`user_id`, `meta_key`, `meta_value`) VALUES {$chunk};"; 724 725 if ( is_wp_error( $bbp_db->query( $sql_insert ) ) ) { 710 726 return array( 4, sprintf( $statement, $result ) ); 711 727 } … … 727 743 */ 728 744 function bbp_admin_repair_user_reply_count() { 729 global $wpdb; 730 745 746 // Define variables 747 $bbp_db = bbp_db(); 731 748 $statement = __( 'Counting the number of topics to which each user has replied… %s', 'bbpress' ); 732 749 $result = __( 'Failed!', 'bbpress' ); 733 $sql_select = "SELECT `post_author`, COUNT(DISTINCT `ID`) as `_count` FROM `{$wpdb->posts}` WHERE `post_type` = '" . bbp_get_reply_post_type() . "' AND `post_status` = '" . bbp_get_public_status_id() . "' GROUP BY `post_author`;"; 734 $insert_rows = $wpdb->get_results( $sql_select ); 750 751 $sql_select = "SELECT `post_author`, COUNT(DISTINCT `ID`) as `_count` FROM `{$bbp_db->posts}` WHERE `post_type` = '" . bbp_get_reply_post_type() . "' AND `post_status` = '" . bbp_get_public_status_id() . "' GROUP BY `post_author`;"; 752 $insert_rows = $bbp_db->get_results( $sql_select ); 735 753 736 754 if ( is_wp_error( $insert_rows ) ) { … … 738 756 } 739 757 740 $key = $ wpdb->prefix . '_bbp_reply_count';758 $key = $bbp_db->prefix . '_bbp_reply_count'; 741 759 $insert_values = array(); 742 760 foreach ( $insert_rows as $insert_row ) { … … 748 766 } 749 767 750 $sql_delete = "DELETE FROM `{$ wpdb->usermeta}` WHERE `meta_key` = '{$key}';";751 if ( is_wp_error( $ wpdb->query( $sql_delete ) ) ) {768 $sql_delete = "DELETE FROM `{$bbp_db->usermeta}` WHERE `meta_key` = '{$key}';"; 769 if ( is_wp_error( $bbp_db->query( $sql_delete ) ) ) { 752 770 return array( 3, sprintf( $statement, $result ) ); 753 771 } … … 755 773 foreach ( array_chunk( $insert_values, 10000 ) as $chunk ) { 756 774 $chunk = "\n" . implode( ",\n", $chunk ); 757 $sql_insert = "INSERT INTO `{$ wpdb->usermeta}` (`user_id`, `meta_key`, `meta_value`) VALUES $chunk;";758 759 if ( is_wp_error( $ wpdb->query( $sql_insert ) ) ) {775 $sql_insert = "INSERT INTO `{$bbp_db->usermeta}` (`user_id`, `meta_key`, `meta_value`) VALUES {$chunk};"; 776 777 if ( is_wp_error( $bbp_db->query( $sql_insert ) ) ) { 760 778 return array( 4, sprintf( $statement, $result ) ); 761 779 } … … 777 795 */ 778 796 function bbp_admin_repair_user_favorites() { 779 global $wpdb; 780 797 798 // Define variables 799 $bbp_db = bbp_db(); 781 800 $statement = __( 'Removing trashed topics from user favorites… %s', 'bbpress' ); 782 801 $result = __( 'Failed!', 'bbpress' ); 783 $key = $wpdb->prefix . '_bbp_favorites'; 784 $users = $wpdb->get_results( "SELECT `user_id`, `meta_value` AS `favorites` FROM `{$wpdb->usermeta}` WHERE `meta_key` = '{$key}';" ); 802 803 $key = $bbp_db->prefix . '_bbp_favorites'; 804 $users = $bbp_db->get_results( "SELECT `user_id`, `meta_value` AS `favorites` FROM `{$bbp_db->usermeta}` WHERE `meta_key` = '{$key}';" ); 785 805 786 806 if ( is_wp_error( $users ) ) { … … 788 808 } 789 809 790 $topics = $ wpdb->get_col( "SELECT `ID` FROM `{$wpdb->posts}` WHERE `post_type` = '" . bbp_get_topic_post_type() . "' AND `post_status` = '" . bbp_get_public_status_id() . "';" );810 $topics = $bbp_db->get_col( "SELECT `ID` FROM `{$bbp_db->posts}` WHERE `post_type` = '" . bbp_get_topic_post_type() . "' AND `post_status` = '" . bbp_get_public_status_id() . "';" ); 791 811 792 812 if ( is_wp_error( $topics ) ) { … … 817 837 } 818 838 819 $sql_delete = "DELETE FROM `{$ wpdb->usermeta}` WHERE `meta_key` = '{$key}';";820 if ( is_wp_error( $ wpdb->query( $sql_delete ) ) ) {839 $sql_delete = "DELETE FROM `{$bbp_db->usermeta}` WHERE `meta_key` = '{$key}';"; 840 if ( is_wp_error( $bbp_db->query( $sql_delete ) ) ) { 821 841 return array( 4, sprintf( $statement, $result ) ); 822 842 } … … 824 844 foreach ( array_chunk( $values, 10000 ) as $chunk ) { 825 845 $chunk = "\n" . implode( ",\n", $chunk ); 826 $sql_insert = "INSERT INTO ` $wpdb->usermeta` (`user_id`, `meta_key`, `meta_value`) VALUES $chunk;";827 if ( is_wp_error( $ wpdb->query( $sql_insert ) ) ) {846 $sql_insert = "INSERT INTO `{$bbp_db->usermeta}` (`user_id`, `meta_key`, `meta_value`) VALUES {$chunk};"; 847 if ( is_wp_error( $bbp_db->query( $sql_insert ) ) ) { 828 848 return array( 5, sprintf( $statement, $result ) ); 829 849 } … … 845 865 */ 846 866 function bbp_admin_repair_user_topic_subscriptions() { 847 global $wpdb; 848 867 868 // Define variables 869 $bbp_db = bbp_db(); 849 870 $statement = __( 'Removing trashed topics from user subscriptions… %s', 'bbpress' ); 850 871 $result = __( 'Failed!', 'bbpress' ); 851 $key = $wpdb->prefix . '_bbp_subscriptions'; 852 $users = $wpdb->get_results( "SELECT `user_id`, `meta_value` AS `subscriptions` FROM `{$wpdb->usermeta}` WHERE `meta_key` = '{$key}';" ); 872 873 $key = $bbp_db->prefix . '_bbp_subscriptions'; 874 $users = $bbp_db->get_results( "SELECT `user_id`, `meta_value` AS `subscriptions` FROM `{$bbp_db->usermeta}` WHERE `meta_key` = '{$key}';" ); 853 875 854 876 if ( is_wp_error( $users ) ) { … … 856 878 } 857 879 858 $topics = $ wpdb->get_col( "SELECT `ID` FROM `{$wpdb->posts}` WHERE `post_type` = '" . bbp_get_topic_post_type() . "' AND `post_status` = '" . bbp_get_public_status_id() . "';" );880 $topics = $bbp_db->get_col( "SELECT `ID` FROM `{$bbp_db->posts}` WHERE `post_type` = '" . bbp_get_topic_post_type() . "' AND `post_status` = '" . bbp_get_public_status_id() . "';" ); 859 881 if ( is_wp_error( $topics ) ) { 860 882 return array( 2, sprintf( $statement, $result ) ); … … 884 906 } 885 907 886 $sql_delete = "DELETE FROM `{$ wpdb->usermeta}` WHERE `meta_key` = '{$key}';";887 if ( is_wp_error( $ wpdb->query( $sql_delete ) ) ) {908 $sql_delete = "DELETE FROM `{$bbp_db->usermeta}` WHERE `meta_key` = '{$key}';"; 909 if ( is_wp_error( $bbp_db->query( $sql_delete ) ) ) { 888 910 return array( 4, sprintf( $statement, $result ) ); 889 911 } … … 891 913 foreach ( array_chunk( $values, 10000 ) as $chunk ) { 892 914 $chunk = "\n" . implode( ",\n", $chunk ); 893 $sql_insert = "INSERT INTO `{$ wpdb->usermeta}` (`user_id`, `meta_key`, `meta_value`) VALUES $chunk;";894 if ( is_wp_error( $ wpdb->query( $sql_insert ) ) ) {915 $sql_insert = "INSERT INTO `{$bbp_db->usermeta}` (`user_id`, `meta_key`, `meta_value`) VALUES {$chunk};"; 916 if ( is_wp_error( $bbp_db->query( $sql_insert ) ) ) { 895 917 return array( 5, sprintf( $statement, $result ) ); 896 918 } … … 912 934 */ 913 935 function bbp_admin_repair_user_forum_subscriptions() { 914 global $wpdb; 915 936 937 // Define variables 938 $bbp_db = bbp_db(); 916 939 $statement = __( 'Removing trashed forums from user subscriptions… %s', 'bbpress' ); 917 940 $result = __( 'Failed!', 'bbpress' ); 918 $key = $wpdb->prefix . '_bbp_forum_subscriptions'; 919 $users = $wpdb->get_results( "SELECT `user_id`, `meta_value` AS `subscriptions` FROM `{$wpdb->usermeta}` WHERE `meta_key` = '{$key}';" ); 941 942 $key = $bbp_db->prefix . '_bbp_forum_subscriptions'; 943 $users = $bbp_db->get_results( "SELECT `user_id`, `meta_value` AS `subscriptions` FROM `{$bbp_db->usermeta}` WHERE `meta_key` = '{$key}';" ); 920 944 921 945 if ( is_wp_error( $users ) ) { … … 923 947 } 924 948 925 $forums = $ wpdb->get_col( "SELECT `ID` FROM `{$wpdb->posts}` WHERE `post_type` = '" . bbp_get_forum_post_type() . "' AND `post_status` = '" . bbp_get_public_status_id() . "';" );949 $forums = $bbp_db->get_col( "SELECT `ID` FROM `{$bbp_db->posts}` WHERE `post_type` = '" . bbp_get_forum_post_type() . "' AND `post_status` = '" . bbp_get_public_status_id() . "';" ); 926 950 if ( is_wp_error( $forums ) ) { 927 951 return array( 2, sprintf( $statement, $result ) ); … … 951 975 } 952 976 953 $sql_delete = "DELETE FROM `{$ wpdb->usermeta}` WHERE `meta_key` = '{$key}';";954 if ( is_wp_error( $ wpdb->query( $sql_delete ) ) ) {977 $sql_delete = "DELETE FROM `{$bbp_db->usermeta}` WHERE `meta_key` = '{$key}';"; 978 if ( is_wp_error( $bbp_db->query( $sql_delete ) ) ) { 955 979 return array( 4, sprintf( $statement, $result ) ); 956 980 } … … 958 982 foreach ( array_chunk( $values, 10000 ) as $chunk ) { 959 983 $chunk = "\n" . implode( ",\n", $chunk ); 960 $sql_insert = "INSERT INTO `{$ wpdb->usermeta}` (`user_id`, `meta_key`, `meta_value`) VALUES $chunk;";961 if ( is_wp_error( $ wpdb->query( $sql_insert ) ) ) {984 $sql_insert = "INSERT INTO `{$bbp_db->usermeta}` (`user_id`, `meta_key`, `meta_value`) VALUES {$chunk};"; 985 if ( is_wp_error( $bbp_db->query( $sql_insert ) ) ) { 962 986 return array( 5, sprintf( $statement, $result ) ); 963 987 } … … 999 1023 1000 1024 // If no role map exists, give the default forum role (bbp-participant) 1001 $new_role = isset( $role_map[ $role] ) ? $role_map[$role] : $default_role;1025 $new_role = isset( $role_map[ $role ] ) ? $role_map[ $role ] : $default_role; 1002 1026 1003 1027 // Get users of this site, limited to 1000 … … 1022 1046 1023 1047 $result = sprintf( __( 'Complete! %s users updated.', 'bbpress' ), bbp_number_format( $changed ) ); 1048 1024 1049 return array( 0, sprintf( $statement, $result ) ); 1025 1050 } … … 1041 1066 */ 1042 1067 function bbp_admin_repair_freshness() { 1043 global $wpdb; 1044 1068 1069 // Define variables 1070 $bbp_db = bbp_db(); 1045 1071 $statement = __( 'Recomputing latest post in every topic and forum… %s', 'bbpress' ); 1046 1072 $result = __( 'Failed!', 'bbpress' ); 1047 1073 1048 1074 // First, delete everything. 1049 if ( is_wp_error( $ wpdb->query( "DELETE FROM `$wpdb->postmeta` WHERE `meta_key` IN ( '_bbp_last_reply_id', '_bbp_last_topic_id', '_bbp_last_active_id', '_bbp_last_active_time' );" ) ) ) {1075 if ( is_wp_error( $bbp_db->query( "DELETE FROM `{$bbp_db->postmeta}` WHERE `meta_key` IN ( '_bbp_last_reply_id', '_bbp_last_topic_id', '_bbp_last_active_id', '_bbp_last_active_time' );" ) ) ) { 1050 1076 return array( 1, sprintf( $statement, $result ) ); 1051 1077 } … … 1058 1084 1059 1085 // Next, give all the topics with replies the ID their last reply. 1060 if ( is_wp_error( $ wpdb->query( "INSERT INTO `$wpdb->postmeta` (`post_id`, `meta_key`, `meta_value`)1086 if ( is_wp_error( $bbp_db->query( "INSERT INTO `{$bbp_db->postmeta}` (`post_id`, `meta_key`, `meta_value`) 1061 1087 ( SELECT `topic`.`ID`, '_bbp_last_reply_id', MAX( `reply`.`ID` ) 1062 FROM ` $wpdb->posts` AS `topic` INNER JOIN `$wpdb->posts` AS `reply` ON `topic`.`ID` = `reply`.`post_parent`1088 FROM `{$bbp_db->posts}` AS `topic` INNER JOIN `{$bbp_db->posts}` AS `reply` ON `topic`.`ID` = `reply`.`post_parent` 1063 1089 WHERE `reply`.`post_status` = '{$pps}' AND `topic`.`post_type` = '{$tpt}' AND `reply`.`post_type` = '{$rpt}' 1064 1090 GROUP BY `topic`.`ID` );" ) ) ) { … … 1067 1093 1068 1094 // For any remaining topics, give a reply ID of 0. 1069 if ( is_wp_error( $ wpdb->query( "INSERT INTO `$wpdb->postmeta` (`post_id`, `meta_key`, `meta_value`)1095 if ( is_wp_error( $bbp_db->query( "INSERT INTO `{$bbp_db->postmeta}` (`post_id`, `meta_key`, `meta_value`) 1070 1096 ( SELECT `ID`, '_bbp_last_reply_id', 0 1071 FROM ` $wpdb->posts` AS `topic` LEFT JOIN `$wpdb->postmeta` AS `reply`1097 FROM `{$bbp_db->posts}` AS `topic` LEFT JOIN `{$bbp_db->postmeta}` AS `reply` 1072 1098 ON `topic`.`ID` = `reply`.`post_id` AND `reply`.`meta_key` = '_bbp_last_reply_id' 1073 1099 WHERE `reply`.`meta_id` IS NULL AND `topic`.`post_type` = '{$tpt}' );" ) ) ) { … … 1076 1102 1077 1103 // Now we give all the forums with topics the ID their last topic. 1078 if ( is_wp_error( $ wpdb->query( "INSERT INTO `$wpdb->postmeta` (`post_id`, `meta_key`, `meta_value`)1104 if ( is_wp_error( $bbp_db->query( "INSERT INTO `{$bbp_db->postmeta}` (`post_id`, `meta_key`, `meta_value`) 1079 1105 ( SELECT `forum`.`ID`, '_bbp_last_topic_id', `topic`.`ID` 1080 FROM ` $wpdb->posts` AS `forum` INNER JOIN `$wpdb->posts` AS `topic` ON `forum`.`ID` = `topic`.`post_parent`1106 FROM `{$bbp_db->posts}` AS `forum` INNER JOIN `{$bbp_db->posts}` AS `topic` ON `forum`.`ID` = `topic`.`post_parent` 1081 1107 WHERE `topic`.`post_status` = '{$pps}' AND `forum`.`post_type` = '{$fpt}' AND `topic`.`post_type` = '{$tpt}' 1082 1108 GROUP BY `forum`.`ID` );" ) ) ) { … … 1085 1111 1086 1112 // For any remaining forums, give a topic ID of 0. 1087 if ( is_wp_error( $ wpdb->query( "INSERT INTO `$wpdb->postmeta` (`post_id`, `meta_key`, `meta_value`)1113 if ( is_wp_error( $bbp_db->query( "INSERT INTO `{$bbp_db->postmeta}` (`post_id`, `meta_key`, `meta_value`) 1088 1114 ( SELECT `ID`, '_bbp_last_topic_id', 0 1089 FROM ` $wpdb->posts` AS `forum` LEFT JOIN `$wpdb->postmeta` AS `topic`1115 FROM `{$bbp_db->posts}` AS `forum` LEFT JOIN `{$bbp_db->postmeta}` AS `topic` 1090 1116 ON `forum`.`ID` = `topic`.`post_id` AND `topic`.`meta_key` = '_bbp_last_topic_id' 1091 1117 WHERE `topic`.`meta_id` IS NULL AND `forum`.`post_type` = '{$fpt}' );" ) ) ) { … … 1094 1120 1095 1121 // After that, we give all the topics with replies the ID their last reply (again, this time for a different reason). 1096 if ( is_wp_error( $ wpdb->query( "INSERT INTO `$wpdb->postmeta` (`post_id`, `meta_key`, `meta_value`)1122 if ( is_wp_error( $bbp_db->query( "INSERT INTO `{$bbp_db->postmeta}` (`post_id`, `meta_key`, `meta_value`) 1097 1123 ( SELECT `topic`.`ID`, '_bbp_last_active_id', MAX( `reply`.`ID` ) 1098 FROM ` $wpdb->posts` AS `topic` INNER JOIN `$wpdb->posts` AS `reply` ON `topic`.`ID` = `reply`.`post_parent`1124 FROM `{$bbp_db->posts}` AS `topic` INNER JOIN `{$bbp_db->posts}` AS `reply` ON `topic`.`ID` = `reply`.`post_parent` 1099 1125 WHERE `reply`.`post_status` = '{$pps}' AND `topic`.`post_type` = '{$tpt}' AND `reply`.`post_type` = '{$rpt}' 1100 1126 GROUP BY `topic`.`ID` );" ) ) ) { … … 1103 1129 1104 1130 // For any remaining topics, give a reply ID of themself. 1105 if ( is_wp_error( $ wpdb->query( "INSERT INTO `$wpdb->postmeta` (`post_id`, `meta_key`, `meta_value`)1131 if ( is_wp_error( $bbp_db->query( "INSERT INTO `{$bbp_db->postmeta}` (`post_id`, `meta_key`, `meta_value`) 1106 1132 ( SELECT `ID`, '_bbp_last_active_id', `ID` 1107 FROM ` $wpdb->posts` AS `topic` LEFT JOIN `$wpdb->postmeta` AS `reply`1133 FROM `{$bbp_db->posts}` AS `topic` LEFT JOIN `{$bbp_db->postmeta}` AS `reply` 1108 1134 ON `topic`.`ID` = `reply`.`post_id` AND `reply`.`meta_key` = '_bbp_last_active_id' 1109 1135 WHERE `reply`.`meta_id` IS NULL AND `topic`.`post_type` = '{$tpt}' );" ) ) ) { … … 1112 1138 1113 1139 // Give topics with replies their last update time. 1114 if ( is_wp_error( $ wpdb->query( "INSERT INTO `$wpdb->postmeta` (`post_id`, `meta_key`, `meta_value`)1140 if ( is_wp_error( $bbp_db->query( "INSERT INTO `{$bbp_db->postmeta}` (`post_id`, `meta_key`, `meta_value`) 1115 1141 ( SELECT `topic`.`ID`, '_bbp_last_active_time', MAX( `reply`.`post_date` ) 1116 FROM ` $wpdb->posts` AS `topic` INNER JOIN `$wpdb->posts` AS `reply` ON `topic`.`ID` = `reply`.`post_parent`1142 FROM `{$bbp_db->posts}` AS `topic` INNER JOIN `{$bbp_db->posts}` AS `reply` ON `topic`.`ID` = `reply`.`post_parent` 1117 1143 WHERE `reply`.`post_status` = '{$pps}' AND `topic`.`post_type` = '{$tpt}' AND `reply`.`post_type` = '{$rpt}' 1118 1144 GROUP BY `topic`.`ID` );" ) ) ) { … … 1121 1147 1122 1148 // Give topics without replies their last update time. 1123 if ( is_wp_error( $ wpdb->query( "INSERT INTO `$wpdb->postmeta` (`post_id`, `meta_key`, `meta_value`)1149 if ( is_wp_error( $bbp_db->query( "INSERT INTO `{$bbp_db->postmeta}` (`post_id`, `meta_key`, `meta_value`) 1124 1150 ( SELECT `ID`, '_bbp_last_active_time', `post_date` 1125 FROM ` $wpdb->posts` AS `topic` LEFT JOIN `$wpdb->postmeta` AS `reply`1151 FROM `{$bbp_db->posts}` AS `topic` LEFT JOIN `{$bbp_db->postmeta}` AS `reply` 1126 1152 ON `topic`.`ID` = `reply`.`post_id` AND `reply`.`meta_key` = '_bbp_last_active_time' 1127 1153 WHERE `reply`.`meta_id` IS NULL AND `topic`.`post_type` = '{$tpt}' );" ) ) ) { … … 1130 1156 1131 1157 // Forums need to know what their last active item is as well. Now it gets a bit more complex to do in the database. 1132 $forums = $ wpdb->get_col( "SELECT `ID` FROM `$wpdb->posts` WHERE `post_type` = '{$fpt}' and `post_status` != 'auto-draft';" );1158 $forums = $bbp_db->get_col( "SELECT `ID` FROM `{$bbp_db->posts}` WHERE `post_type` = '{$fpt}' and `post_status` != 'auto-draft';" ); 1133 1159 if ( is_wp_error( $forums ) ) { 1134 1160 return array( 10, sprintf( $statement, $result ) ); … … 1168 1194 */ 1169 1195 function bbp_admin_repair_sticky() { 1170 global $wpdb; 1171 1196 1197 // Define variables 1198 $bbp_db = bbp_db(); 1172 1199 $statement = __( 'Repairing the sticky topic to the parent forum relationships… %s', 'bbpress' ); 1173 1200 $result = __( 'Failed!', 'bbpress' ); 1174 $forums = $wpdb->get_col( "SELECT ID FROM `{$wpdb->posts}` WHERE `post_type` = '" . bbp_get_forum_post_type() . "';" ); 1201 1202 $forums = $bbp_db->get_col( "SELECT ID FROM `{$bbp_db->posts}` WHERE `post_type` = '" . bbp_get_forum_post_type() . "';" ); 1175 1203 1176 1204 // Bail if no forums found … … 1181 1209 // Loop through forums and get their sticky topics 1182 1210 foreach ( $forums as $forum ) { 1183 $forum_stickies[ $forum] = get_post_meta( $forum, '_bbp_sticky_topics', true );1211 $forum_stickies[ $forum ] = get_post_meta( $forum, '_bbp_sticky_topics', true ); 1184 1212 } 1185 1213 … … 1201 1229 // match the topic's forum ID, unset the forum's sticky meta. 1202 1230 if ( ! bbp_is_topic_super_sticky( $topic_id ) && $forum_id !== bbp_get_topic_forum_id( $topic_id ) ) { 1203 unset( $forum_stickies[ $forum_id][$id] );1231 unset( $forum_stickies[ $forum_id ][ $id ] ); 1204 1232 } 1205 1233 } 1206 1234 1207 1235 // Get sticky topic ID's, or use empty string 1208 $stickers = empty( $forum_stickies[$forum_id] ) ? '' : array_values( $forum_stickies[ $forum_id] );1236 $stickers = empty( $forum_stickies[$forum_id] ) ? '' : array_values( $forum_stickies[ $forum_id ] ); 1209 1237 1210 1238 // Update the forum's sticky topics meta … … 1234 1262 */ 1235 1263 function bbp_admin_repair_closed_topics() { 1236 global $wpdb; 1237 1264 1265 // Define variables 1266 $bbp_db = bbp_db(); 1238 1267 $statement = __( 'Repairing closed topics… %s', 'bbpress' ); 1268 $result = __( 'No closed topics to repair.', 'bbpress' ); 1239 1269 $changed = 0; 1240 $result = __( 'No closed topics to repair.', 'bbpress' ); 1241 $closed_topics = $ wpdb->get_col( "SELECT ID FROM `{$wpdb->posts}` WHERE `post_type` = '" . bbp_get_topic_post_type() . "' AND `post_status` = 'closed';" );1270 1271 $closed_topics = $bbp_db->get_col( "SELECT ID FROM `{$bbp_db->posts}` WHERE `post_type` = '" . bbp_get_topic_post_type() . "' AND `post_status` = 'closed';" ); 1242 1272 1243 1273 // Bail if no closed topics found 1244 if ( empty( $closed_topics ) || is_wp_error( $closed_topics ) ) 1274 if ( empty( $closed_topics ) || is_wp_error( $closed_topics ) ) { 1245 1275 return array( 1, sprintf( $statement, $result ) ); 1276 } 1246 1277 1247 1278 // Loop through each closed topic … … 1262 1293 1263 1294 // Complete results 1264 $result = sprintf( _n( 'Complete! %d closed topic repaired.', 'Complete! %d closed topics repaired.', $changed, 'bbpress' ), $changed ); 1295 $result = sprintf( _n( 'Complete! %d closed topic repaired.', 'Complete! %d closed topics repaired.', $changed, 'bbpress' ), $changed ); 1296 1265 1297 return array( 0, sprintf( $statement, $result ) ); 1266 1298 } … … 1299 1331 */ 1300 1332 function bbp_admin_repair_forum_meta() { 1301 global $wpdb; 1302 1333 1334 // Define variables 1335 $bbp_db = bbp_db(); 1303 1336 $statement = __( 'Recalculating the forum for each post … %s', 'bbpress' ); 1304 1337 $result = __( 'Failed!', 'bbpress' ); 1305 1338 1306 1339 // First, delete everything. 1307 if ( is_wp_error( $ wpdb->query( "DELETE FROM `$wpdb->postmeta` WHERE `meta_key` = '_bbp_forum_id';" ) ) ) {1340 if ( is_wp_error( $bbp_db->query( "DELETE FROM `{$bbp_db->postmeta}` WHERE `meta_key` = '_bbp_forum_id';" ) ) ) { 1308 1341 return array( 1, sprintf( $statement, $result ) ); 1309 1342 } … … 1314 1347 1315 1348 // Next, give all the topics their parent forum id. 1316 if ( is_wp_error( $ wpdb->query( "INSERT INTO `$wpdb->postmeta` (`post_id`, `meta_key`, `meta_value`)1349 if ( is_wp_error( $bbp_db->query( "INSERT INTO `{$bbp_db->postmeta}` (`post_id`, `meta_key`, `meta_value`) 1317 1350 ( SELECT `topic`.`ID`, '_bbp_forum_id', `topic`.`post_parent` 1318 FROM `$ wpdb->posts`1351 FROM `$bbp_db->posts` 1319 1352 AS `topic` 1320 1353 WHERE `topic`.`post_type` = '{$tpt}' … … 1324 1357 1325 1358 // Next, give all the replies their parent forum id. 1326 if ( is_wp_error( $ wpdb->query( "INSERT INTO `$wpdb->postmeta` (`post_id`, `meta_key`, `meta_value`)1359 if ( is_wp_error( $bbp_db->query( "INSERT INTO `{$bbp_db->postmeta}` (`post_id`, `meta_key`, `meta_value`) 1327 1360 ( SELECT `reply`.`ID`, '_bbp_forum_id', `topic`.`post_parent` 1328 FROM `$ wpdb->posts`1361 FROM `$bbp_db->posts` 1329 1362 AS `reply` 1330 INNER JOIN `$ wpdb->posts`1363 INNER JOIN `$bbp_db->posts` 1331 1364 AS `topic` 1332 1365 ON `reply`.`post_parent` = `topic`.`ID` … … 1353 1386 */ 1354 1387 function bbp_admin_repair_topic_meta() { 1355 global $wpdb; 1356 1388 1389 // Define variables 1390 $bbp_db = bbp_db(); 1357 1391 $statement = __( 'Recalculating the topic for each post … %s', 'bbpress' ); 1358 1392 $result = __( 'Failed!', 'bbpress' ); 1359 1393 1360 1394 // First, delete everything. 1361 if ( is_wp_error( $ wpdb->query( "DELETE FROM `$wpdb->postmeta` WHERE `meta_key` = '_bbp_topic_id';" ) ) ) {1395 if ( is_wp_error( $bbp_db->query( "DELETE FROM `{$bbp_db->postmeta}` WHERE `meta_key` = '_bbp_topic_id';" ) ) ) { 1362 1396 return array( 1, sprintf( $statement, $result ) ); 1363 1397 } … … 1368 1402 1369 1403 // Next, give all the topics with replies the ID their last reply. 1370 if ( is_wp_error( $ wpdb->query( "INSERT INTO `$wpdb->postmeta` (`post_id`, `meta_key`, `meta_value`)1404 if ( is_wp_error( $bbp_db->query( "INSERT INTO `{$bbp_db->postmeta}` (`post_id`, `meta_key`, `meta_value`) 1371 1405 ( SELECT `topic`.`ID`, '_bbp_topic_id', `topic`.`ID` 1372 FROM `$ wpdb->posts`1406 FROM `$bbp_db->posts` 1373 1407 AS `topic` 1374 1408 WHERE `topic`.`post_type` = '{$tpt}' … … 1378 1412 1379 1413 // Next, give all the topics with replies the ID their last reply. 1380 if ( is_wp_error( $ wpdb->query( "INSERT INTO `$wpdb->postmeta` (`post_id`, `meta_key`, `meta_value`)1414 if ( is_wp_error( $bbp_db->query( "INSERT INTO `{$bbp_db->postmeta}` (`post_id`, `meta_key`, `meta_value`) 1381 1415 ( SELECT `reply`.`ID`, '_bbp_topic_id', `topic`.`ID` 1382 FROM `$ wpdb->posts`1416 FROM `$bbp_db->posts` 1383 1417 AS `reply` 1384 INNER JOIN `$ wpdb->posts`1418 INNER JOIN `$bbp_db->posts` 1385 1419 AS `topic` 1386 1420 ON `reply`.`post_parent` = `topic`.`ID` … … 1407 1441 */ 1408 1442 function bbp_admin_repair_reply_menu_order() { 1409 global $wpdb; 1410 1443 1444 // Define variables 1445 $bbp_db = bbp_db(); 1411 1446 $statement = __( 'Recalculating reply menu order … %s', 'bbpress' ); 1412 1447 $result = __( 'No reply positions to recalculate!', 'bbpress' ); 1413 1448 1414 1449 // Delete cases where `_bbp_reply_to` was accidentally set to itself 1415 if ( is_wp_error( $ wpdb->query( "DELETE FROM `{$wpdb->postmeta}` WHERE `meta_key` = '_bbp_reply_to' AND `post_id` = `meta_value`;" ) ) ) {1450 if ( is_wp_error( $bbp_db->query( "DELETE FROM `{$bbp_db->postmeta}` WHERE `meta_key` = '_bbp_reply_to' AND `post_id` = `meta_value`;" ) ) ) { 1416 1451 return array( 1, sprintf( $statement, $result ) ); 1417 1452 } … … 1421 1456 1422 1457 // Get an array of reply id's to update the menu oder for each reply 1423 $replies = $ wpdb->get_results( "SELECT `a`.`ID` FROM `{$wpdb->posts}` AS `a`1458 $replies = $bbp_db->get_results( "SELECT `a`.`ID` FROM `{$bbp_db->posts}` AS `a` 1424 1459 INNER JOIN ( 1425 1460 SELECT `menu_order`, `post_parent` 1426 FROM `{$ wpdb->posts}`1461 FROM `{$bbp_db->posts}` 1427 1462 GROUP BY `menu_order`, `post_parent` 1428 1463 HAVING COUNT( * ) >1 … … 1546 1581 check_admin_referer( 'bbpress-reset' ); 1547 1582 1548 global $wpdb;1549 1550 1583 // Stores messages 1551 1584 $messages = array(); … … 1563 1596 $rpt = bbp_get_reply_post_type(); 1564 1597 1598 // Define variables 1599 $bbp_db = bbp_db(); 1565 1600 $statement = __( 'Deleting Posts… %s', 'bbpress' ); 1566 $sql_posts = $wpdb->get_results( "SELECT `ID` FROM `{$wpdb->posts}` WHERE `post_type` IN ('{$fpt}', '{$tpt}', '{$rpt}')", OBJECT_K ); 1567 $sql_delete = "DELETE FROM `{$wpdb->posts}` WHERE `post_type` IN ('{$fpt}', '{$tpt}', '{$rpt}')"; 1568 $result = is_wp_error( $wpdb->query( $sql_delete ) ) ? $failed : $success; 1601 1602 $sql_posts = $bbp_db->get_results( "SELECT `ID` FROM `{$bbp_db->posts}` WHERE `post_type` IN ('{$fpt}', '{$tpt}', '{$rpt}')", OBJECT_K ); 1603 $sql_delete = "DELETE FROM `{$bbp_db->posts}` WHERE `post_type` IN ('{$fpt}', '{$tpt}', '{$rpt}')"; 1604 $result = is_wp_error( $bbp_db->query( $sql_delete ) ) ? $failed : $success; 1569 1605 $messages[] = sprintf( $statement, $result ); 1570 1606 … … 1578 1614 $statement = __( 'Deleting Post Meta… %s', 'bbpress' ); 1579 1615 $sql_meta = implode( "', '", $sql_meta ); 1580 $sql_delete = "DELETE FROM `{$ wpdb->postmeta}` WHERE `post_id` IN ('{$sql_meta}');";1581 $result = is_wp_error( $ wpdb->query( $sql_delete ) ) ? $failed : $success;1616 $sql_delete = "DELETE FROM `{$bbp_db->postmeta}` WHERE `post_id` IN ('{$sql_meta}');"; 1617 $result = is_wp_error( $bbp_db->query( $sql_delete ) ) ? $failed : $success; 1582 1618 $messages[] = sprintf( $statement, $result ); 1583 1619 } … … 1586 1622 1587 1623 $statement = __( 'Deleting Topic Tags… %s', 'bbpress' ); 1588 $sql_delete = "DELETE a,b,c FROM `{$ wpdb->terms}` AS a LEFT JOIN `{$wpdb->term_taxonomy}` AS c ON a.term_id = c.term_id LEFT JOIN `{$wpdb->term_relationships}` AS b ON b.term_taxonomy_id = c.term_taxonomy_id WHERE c.taxonomy = 'topic-tag';";1589 $result = is_wp_error( $ wpdb->query( $sql_delete ) ) ? $failed : $success;1624 $sql_delete = "DELETE a,b,c FROM `{$bbp_db->terms}` AS a LEFT JOIN `{$bbp_db->term_taxonomy}` AS c ON a.term_id = c.term_id LEFT JOIN `{$bbp_db->term_relationships}` AS b ON b.term_taxonomy_id = c.term_taxonomy_id WHERE c.taxonomy = 'topic-tag';"; 1625 $result = is_wp_error( $bbp_db->query( $sql_delete ) ) ? $failed : $success; 1590 1626 $messages[] = sprintf( $statement, $result ); 1591 1627 … … 1594 1630 // First, if we're deleting previously imported users, delete them now 1595 1631 if ( !empty( $_POST['bbpress-delete-imported-users'] ) ) { 1596 $sql_users = $ wpdb->get_results( "SELECT `user_id` FROM `{$wpdb->usermeta}` WHERE `meta_key` = '_bbp_user_id'", OBJECT_K );1632 $sql_users = $bbp_db->get_results( "SELECT `user_id` FROM `{$bbp_db->usermeta}` WHERE `meta_key` = '_bbp_user_id'", OBJECT_K ); 1597 1633 if ( !empty( $sql_users ) ) { 1598 1634 $sql_meta = array(); … … 1602 1638 $statement = __( 'Deleting User… %s', 'bbpress' ); 1603 1639 $sql_meta = implode( "', '", $sql_meta ); 1604 $sql_delete = "DELETE FROM `{$ wpdb->users}` WHERE `ID` IN ('{$sql_meta}');";1605 $result = is_wp_error( $ wpdb->query( $sql_delete ) ) ? $failed : $success;1640 $sql_delete = "DELETE FROM `{$bbp_db->users}` WHERE `ID` IN ('{$sql_meta}');"; 1641 $result = is_wp_error( $bbp_db->query( $sql_delete ) ) ? $failed : $success; 1606 1642 $messages[] = sprintf( $statement, $result ); 1607 1643 $statement = __( 'Deleting User Meta… %s', 'bbpress' ); 1608 $sql_delete = "DELETE FROM `{$ wpdb->usermeta}` WHERE `user_id` IN ('{$sql_meta}');";1609 $result = is_wp_error( $ wpdb->query( $sql_delete ) ) ? $failed : $success;1644 $sql_delete = "DELETE FROM `{$bbp_db->usermeta}` WHERE `user_id` IN ('{$sql_meta}');"; 1645 $result = is_wp_error( $bbp_db->query( $sql_delete ) ) ? $failed : $success; 1610 1646 $messages[] = sprintf( $statement, $result ); 1611 1647 } … … 1614 1650 // Next, if we still have users that were not imported delete that meta data 1615 1651 $statement = __( 'Deleting User Meta… %s', 'bbpress' ); 1616 $sql_delete = "DELETE FROM `{$ wpdb->usermeta}` WHERE `meta_key` LIKE '%%_bbp_%%';";1617 $result = is_wp_error( $ wpdb->query( $sql_delete ) ) ? $failed : $success;1652 $sql_delete = "DELETE FROM `{$bbp_db->usermeta}` WHERE `meta_key` LIKE '%%_bbp_%%';"; 1653 $result = is_wp_error( $bbp_db->query( $sql_delete ) ) ? $failed : $success; 1618 1654 $messages[] = sprintf( $statement, $result ); 1619 1655 … … 1621 1657 1622 1658 $statement = __( 'Deleting Conversion Table… %s', 'bbpress' ); 1623 $table_name = $ wpdb->prefix . 'bbp_converter_translator';1624 if ( $ wpdb->get_var( "SHOW TABLES LIKE '{$table_name}'" ) === $table_name ) {1625 $ wpdb->query( "DROP TABLE {$table_name}" );1659 $table_name = $bbp_db->prefix . 'bbp_converter_translator'; 1660 if ( $bbp_db->get_var( "SHOW TABLES LIKE '{$table_name}'" ) === $table_name ) { 1661 $bbp_db->query( "DROP TABLE {$table_name}" ); 1626 1662 $result = $success; 1627 1663 } else {
Note: See TracChangeset
for help on using the changeset viewer.