Skip to:
Content

bbPress.org


Ignore:
Timestamp:
07/14/2015 12:31:42 AM (11 years ago)
Author:
johnjamesjacoby
Message:

Abstraction: Use bbp_db(), bbp_rewrite() & friends, introduced in r5823 & r5826.

This commit improves the stability of bbPress in the WordPress environment by reducing global variable exposure. It also comes with minimal opcode improvements in some circumstances where $GLOBALS is preferred over defining via global statements.

Some additional surrounding cleanup directly related to functions & methods being altered is also being performed here.

Fixes #2786.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/includes/admin/tools.php

    r5783 r5827  
    241241 */
    242242function 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
    243248    if ( is_string( $message ) ) {
    244249        $message = '<p>' . $message . '</p>';
    245         $class = $class ? $class : 'updated';
     250        $class   = $class ? $class : 'updated';
     251
     252    // Messages as objects
    246253    } elseif ( is_wp_error( $message ) ) {
    247         $errors = $message->get_error_messages();
     254        $errors  = $message->get_error_messages();
    248255
    249256        switch ( count( $errors ) ) {
     
    260267        }
    261268
    262         $class = $class ? $class : 'error';
     269        $class = $class ? $class : 'is-error';
    263270    } else {
    264271        return false;
    265272    }
    266273
    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>';
    268276    $message = str_replace( "'", "\'", $message );
     277
     278    // Ugh
    269279    $lambda  = create_function( '', "echo '$message';" );
    270 
    271280    add_action( 'admin_notices', $lambda );
    272281
     
    323332 */
    324333function bbp_admin_repair_topic_reply_count() {
    325     global $wpdb;
    326 
     334
     335    // Define variables
     336    $bbp_db    = bbp_db();
    327337    $statement = __( 'Counting the number of replies in each topic&hellip; %s', 'bbpress' );
    328338    $result    = __( 'Failed!', 'bbpress' );
     
    335345
    336346    // 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`
    339349                        WHERE `posts`.`post_type` = '{$tpt}'
    340350                        AND `postmeta`.`meta_key` = '_bbp_reply_count'";
    341351
    342     if ( is_wp_error( $wpdb->query( $sql_delete ) ) ) {
     352    if ( is_wp_error( $bbp_db->query( $sql_delete ) ) ) {
    343353        return array( 1, sprintf( $statement, $result ) );
    344354    }
    345355
    346356    // 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`) (
    348358            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`
    351361                        ON  `replies`.`post_parent` = `topics`.`ID`
    352362                        AND `replies`.`post_status` = '{$pps}'
     
    356366                GROUP BY `topics`.`ID`);";
    357367
    358     if ( is_wp_error( $wpdb->query( $sql ) ) ) {
     368    if ( is_wp_error( $bbp_db->query( $sql ) ) ) {
    359369        return array( 2, sprintf( $statement, $result ) );
    360370    }
     
    377387 */
    378388function bbp_admin_repair_topic_voice_count() {
    379     global $wpdb;
    380 
     389
     390    // Define variables
     391    $bbp_db    = bbp_db();
    381392    $statement = __( 'Counting the number of voices in each topic&hellip; %s', 'bbpress' );
    382393    $result    = __( 'Failed!', 'bbpress' );
    383394
    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 ) ) ) {
    386397        return array( 1, sprintf( $statement, $result ) );
    387398    }
     
    393404    $cps = bbp_get_closed_status_id();
    394405
    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`) (
    396407            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`
    399410                    ON `posts`.`ID` = `postmeta`.`post_id`
    400411                    AND `postmeta`.`meta_key` = '_bbp_topic_id'
     
    404415                GROUP BY `postmeta`.`meta_value`);";
    405416
    406     if ( is_wp_error( $wpdb->query( $sql ) ) ) {
     417    if ( is_wp_error( $bbp_db->query( $sql ) ) ) {
    407418        return array( 2, sprintf( $statement, $result ) );
    408419    }
     
    424435 */
    425436function bbp_admin_repair_topic_hidden_reply_count() {
    426     global $wpdb;
    427 
     437
     438    // Define variables
     439    $bbp_db    = bbp_db();
    428440    $statement = __( 'Counting the number of spammed and trashed replies in each topic&hellip; %s', 'bbpress' );
    429441    $result    = __( 'Failed!', 'bbpress' );
    430442
    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 ) ) ) {
    433445        return array( 1, sprintf( $statement, $result ) );
    434446    }
     
    439451    $sps = bbp_get_spam_status_id();
    440452
    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 ) ) ) {
    443455        return array( 2, sprintf( $statement, $result ) );
    444456    }
     
    452464 * @since bbPress (r4395)
    453465 *
    454  * @global WPDB $wpdb
    455466 * @uses bbp_get_forum_post_type() To get the forum post type
    456467 * @return If a wp_error() occurs and no converted forums are found
    457468 */
    458469function bbp_admin_repair_group_forum_relationship() {
    459     global $wpdb;
    460 
     470
     471    // Define variables
     472    $bbp_db    = bbp_db();
    461473    $statement = __( 'Repairing BuddyPress group-forum relationships&hellip; %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;
    465477
    466478    // 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 );
    468480    $groups_table      = $prefix . 'bp_groups';
    469481    $groups_meta_table = $prefix . 'bp_groups_groupmeta';
    470482
    471483    // 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`
    475487                                        ON `forum`.`ID` = `forummeta`.`post_id`
    476488                                        AND `forummeta`.`meta_key` = '_bbp_old_forum_id'
     
    479491
    480492    // 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 ) ) {
    482494        return array( 2, sprintf( $statement, __( 'Failed!', 'bbpress' ) ) );
    483495    }
    484496
    485497    // Stash the last results
    486     $results = $wpdb->last_result;
     498    $results = $bbp_db->last_result;
    487499
    488500    // Update each group forum
     
    495507
    496508        // 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}';" );
    498510
    499511        // Bump the count
     
    503515
    504516        // 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}';" );
    506518        if ( !empty( $group_id ) ) {
    507519
     
    510522
    511523            // 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}';" );
    513525
    514526            // Sync up forum visibility based on group status
     
    597609 */
    598610function bbp_admin_repair_forum_topic_count() {
    599     global $wpdb;
    600 
     611
     612    // Define variables
     613    $bbp_db    = bbp_db();
    601614    $statement = __( 'Counting the number of topics in each forum&hellip; %s', 'bbpress' );
    602615    $result    = __( 'Failed!', 'bbpress' );
    603616
    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 ) ) ) {
    606619        return array( 1, sprintf( $statement, $result ) );
    607620    }
     
    633646 */
    634647function bbp_admin_repair_forum_reply_count() {
    635     global $wpdb;
    636 
     648
     649    // Define variables
     650    $bbp_db    = bbp_db();
    637651    $statement = __( 'Counting the number of replies in each forum&hellip; %s', 'bbpress' );
    638652    $result    = __( 'Failed!', 'bbpress' );
     
    642656
    643657    // 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`
    646660                        WHERE `posts`.`post_type` = '{$fpt}'
    647661                        AND `postmeta`.`meta_key` = '_bbp_reply_count'
    648662                        OR `postmeta`.`meta_key` = '_bbp_total_reply_count'";
    649663
    650     if ( is_wp_error( $wpdb->query( $sql_delete ) ) ) {
     664    if ( is_wp_error( $bbp_db->query( $sql_delete ) ) ) {
    651665        return array( 1, sprintf( $statement, $result ) );
    652666    }
     
    677691 */
    678692function bbp_admin_repair_user_topic_count() {
    679     global $wpdb;
    680 
     693
     694    // Define variables
     695    $bbp_db      = bbp_db();
    681696    $statement   = __( 'Counting the number of topics each user has created&hellip; %s', 'bbpress' );
    682697    $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 );
    685701
    686702    if ( is_wp_error( $insert_rows ) ) {
     
    688704    }
    689705
    690     $key           = $wpdb->prefix . '_bbp_topic_count';
     706    $key           = $bbp_db->prefix . '_bbp_topic_count';
    691707    $insert_values = array();
    692708    foreach ( $insert_rows as $insert_row ) {
     
    698714    }
    699715
    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 ) ) ) {
    702718        return array( 3, sprintf( $statement, $result ) );
    703719    }
     
    705721    foreach ( array_chunk( $insert_values, 10000 ) as $chunk ) {
    706722        $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 ) ) ) {
    710726            return array( 4, sprintf( $statement, $result ) );
    711727        }
     
    727743 */
    728744function bbp_admin_repair_user_reply_count() {
    729     global $wpdb;
    730 
     745
     746    // Define variables
     747    $bbp_db    = bbp_db();
    731748    $statement   = __( 'Counting the number of topics to which each user has replied&hellip; %s', 'bbpress' );
    732749    $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 );
    735753
    736754    if ( is_wp_error( $insert_rows ) ) {
     
    738756    }
    739757
    740     $key           = $wpdb->prefix . '_bbp_reply_count';
     758    $key           = $bbp_db->prefix . '_bbp_reply_count';
    741759    $insert_values = array();
    742760    foreach ( $insert_rows as $insert_row ) {
     
    748766    }
    749767
    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 ) ) ) {
    752770        return array( 3, sprintf( $statement, $result ) );
    753771    }
     
    755773    foreach ( array_chunk( $insert_values, 10000 ) as $chunk ) {
    756774        $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 ) ) ) {
    760778            return array( 4, sprintf( $statement, $result ) );
    761779        }
     
    777795 */
    778796function bbp_admin_repair_user_favorites() {
    779     global $wpdb;
    780 
     797
     798    // Define variables
     799    $bbp_db    = bbp_db();
    781800    $statement = __( 'Removing trashed topics from user favorites&hellip; %s', 'bbpress' );
    782801    $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}';" );
    785805
    786806    if ( is_wp_error( $users ) ) {
     
    788808    }
    789809
    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() . "';" );
    791811
    792812    if ( is_wp_error( $topics ) ) {
     
    817837    }
    818838
    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 ) ) ) {
    821841        return array( 4, sprintf( $statement, $result ) );
    822842    }
     
    824844    foreach ( array_chunk( $values, 10000 ) as $chunk ) {
    825845        $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 ) ) ) {
    828848            return array( 5, sprintf( $statement, $result ) );
    829849        }
     
    845865 */
    846866function bbp_admin_repair_user_topic_subscriptions() {
    847     global $wpdb;
    848 
     867
     868    // Define variables
     869    $bbp_db    = bbp_db();
    849870    $statement = __( 'Removing trashed topics from user subscriptions&hellip; %s', 'bbpress' );
    850871    $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}';" );
    853875
    854876    if ( is_wp_error( $users ) ) {
     
    856878    }
    857879
    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() . "';" );
    859881    if ( is_wp_error( $topics ) ) {
    860882        return array( 2, sprintf( $statement, $result ) );
     
    884906    }
    885907
    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 ) ) ) {
    888910        return array( 4, sprintf( $statement, $result ) );
    889911    }
     
    891913    foreach ( array_chunk( $values, 10000 ) as $chunk ) {
    892914        $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 ) ) ) {
    895917            return array( 5, sprintf( $statement, $result ) );
    896918        }
     
    912934 */
    913935function bbp_admin_repair_user_forum_subscriptions() {
    914     global $wpdb;
    915 
     936
     937    // Define variables
     938    $bbp_db    = bbp_db();
    916939    $statement = __( 'Removing trashed forums from user subscriptions&hellip; %s', 'bbpress' );
    917940    $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}';" );
    920944
    921945    if ( is_wp_error( $users ) ) {
     
    923947    }
    924948
    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() . "';" );
    926950    if ( is_wp_error( $forums ) ) {
    927951        return array( 2, sprintf( $statement, $result ) );
     
    951975    }
    952976
    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 ) ) ) {
    955979        return array( 4, sprintf( $statement, $result ) );
    956980    }
     
    958982    foreach ( array_chunk( $values, 10000 ) as $chunk ) {
    959983        $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 ) ) ) {
    962986            return array( 5, sprintf( $statement, $result ) );
    963987        }
     
    9991023
    10001024        // 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;
    10021026
    10031027        // Get users of this site, limited to 1000
     
    10221046
    10231047    $result = sprintf( __( 'Complete! %s users updated.', 'bbpress' ), bbp_number_format( $changed ) );
     1048
    10241049    return array( 0, sprintf( $statement, $result ) );
    10251050}
     
    10411066 */
    10421067function bbp_admin_repair_freshness() {
    1043     global $wpdb;
    1044 
     1068
     1069    // Define variables
     1070    $bbp_db    = bbp_db();
    10451071    $statement = __( 'Recomputing latest post in every topic and forum&hellip; %s', 'bbpress' );
    10461072    $result    = __( 'Failed!', 'bbpress' );
    10471073
    10481074    // 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' );" ) ) ) {
    10501076        return array( 1, sprintf( $statement, $result ) );
    10511077    }
     
    10581084
    10591085    // 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`)
    10611087            ( 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`
    10631089            WHERE `reply`.`post_status` = '{$pps}' AND `topic`.`post_type` = '{$tpt}' AND `reply`.`post_type` = '{$rpt}'
    10641090            GROUP BY `topic`.`ID` );" ) ) ) {
     
    10671093
    10681094    // 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`)
    10701096            ( 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`
    10721098            ON `topic`.`ID` = `reply`.`post_id` AND `reply`.`meta_key` = '_bbp_last_reply_id'
    10731099            WHERE `reply`.`meta_id` IS NULL AND `topic`.`post_type` = '{$tpt}' );" ) ) ) {
     
    10761102
    10771103    // 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`)
    10791105            ( 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`
    10811107            WHERE `topic`.`post_status` = '{$pps}' AND `forum`.`post_type` = '{$fpt}' AND `topic`.`post_type` = '{$tpt}'
    10821108            GROUP BY `forum`.`ID` );" ) ) ) {
     
    10851111
    10861112    // 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`)
    10881114            ( 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`
    10901116            ON `forum`.`ID` = `topic`.`post_id` AND `topic`.`meta_key` = '_bbp_last_topic_id'
    10911117            WHERE `topic`.`meta_id` IS NULL AND `forum`.`post_type` = '{$fpt}' );" ) ) ) {
     
    10941120
    10951121    // 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`)
    10971123            ( 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`
    10991125            WHERE `reply`.`post_status` = '{$pps}' AND `topic`.`post_type` = '{$tpt}' AND `reply`.`post_type` = '{$rpt}'
    11001126            GROUP BY `topic`.`ID` );" ) ) ) {
     
    11031129
    11041130    // 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`)
    11061132            ( 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`
    11081134            ON `topic`.`ID` = `reply`.`post_id` AND `reply`.`meta_key` = '_bbp_last_active_id'
    11091135            WHERE `reply`.`meta_id` IS NULL AND `topic`.`post_type` = '{$tpt}' );" ) ) ) {
     
    11121138
    11131139    // 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`)
    11151141            ( 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`
    11171143            WHERE `reply`.`post_status` = '{$pps}' AND `topic`.`post_type` = '{$tpt}' AND `reply`.`post_type` = '{$rpt}'
    11181144            GROUP BY `topic`.`ID` );" ) ) ) {
     
    11211147
    11221148    // 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`)
    11241150            ( 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`
    11261152            ON `topic`.`ID` = `reply`.`post_id` AND `reply`.`meta_key` = '_bbp_last_active_time'
    11271153            WHERE `reply`.`meta_id` IS NULL AND `topic`.`post_type` = '{$tpt}' );" ) ) ) {
     
    11301156
    11311157    // 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';" );
    11331159    if ( is_wp_error( $forums ) ) {
    11341160        return array( 10, sprintf( $statement, $result ) );
     
    11681194 */
    11691195function bbp_admin_repair_sticky() {
    1170     global $wpdb;
    1171 
     1196
     1197    // Define variables
     1198    $bbp_db    = bbp_db();
    11721199    $statement = __( 'Repairing the sticky topic to the parent forum relationships&hellip; %s', 'bbpress' );
    11731200    $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() . "';" );
    11751203
    11761204    // Bail if no forums found
     
    11811209    // Loop through forums and get their sticky topics
    11821210    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 );
    11841212    }
    11851213
     
    12011229            // match the topic's forum ID, unset the forum's sticky meta.
    12021230            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 ] );
    12041232            }
    12051233        }
    12061234
    12071235        // 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 ] );
    12091237
    12101238        // Update the forum's sticky topics meta
     
    12341262 */
    12351263function bbp_admin_repair_closed_topics() {
    1236     global $wpdb;
    1237 
     1264
     1265    // Define variables
     1266    $bbp_db        = bbp_db();
    12381267    $statement     = __( 'Repairing closed topics&hellip; %s', 'bbpress' );
     1268    $result        = __( 'No closed topics to repair.', 'bbpress' );
    12391269    $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';" );
    12421272
    12431273    // 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 ) ) {
    12451275        return array( 1, sprintf( $statement, $result ) );
     1276    }
    12461277
    12471278    // Loop through each closed topic
     
    12621293
    12631294    // 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
    12651297    return array( 0, sprintf( $statement, $result ) );
    12661298}
     
    12991331 */
    13001332function bbp_admin_repair_forum_meta() {
    1301     global $wpdb;
    1302 
     1333
     1334    // Define variables
     1335    $bbp_db    = bbp_db();
    13031336    $statement = __( 'Recalculating the forum for each post &hellip; %s', 'bbpress' );
    13041337    $result    = __( 'Failed!', 'bbpress' );
    13051338
    13061339    // 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';" ) ) ) {
    13081341        return array( 1, sprintf( $statement, $result ) );
    13091342    }
     
    13141347
    13151348    // 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`)
    13171350            ( SELECT `topic`.`ID`, '_bbp_forum_id', `topic`.`post_parent`
    1318             FROM `$wpdb->posts`
     1351            FROM `$bbp_db->posts`
    13191352                AS `topic`
    13201353            WHERE `topic`.`post_type` = '{$tpt}'
     
    13241357
    13251358    // 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`)
    13271360            ( SELECT `reply`.`ID`, '_bbp_forum_id', `topic`.`post_parent`
    1328             FROM `$wpdb->posts`
     1361            FROM `$bbp_db->posts`
    13291362                AS `reply`
    1330             INNER JOIN `$wpdb->posts`
     1363            INNER JOIN `$bbp_db->posts`
    13311364                AS `topic`
    13321365                ON `reply`.`post_parent` = `topic`.`ID`
     
    13531386 */
    13541387function bbp_admin_repair_topic_meta() {
    1355     global $wpdb;
    1356 
     1388
     1389    // Define variables
     1390    $bbp_db    = bbp_db();
    13571391    $statement = __( 'Recalculating the topic for each post &hellip; %s', 'bbpress' );
    13581392    $result    = __( 'Failed!', 'bbpress' );
    13591393
    13601394    // 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';" ) ) ) {
    13621396        return array( 1, sprintf( $statement, $result ) );
    13631397    }
     
    13681402
    13691403    // 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`)
    13711405            ( SELECT `topic`.`ID`, '_bbp_topic_id', `topic`.`ID`
    1372             FROM `$wpdb->posts`
     1406            FROM `$bbp_db->posts`
    13731407                AS `topic`
    13741408            WHERE `topic`.`post_type` = '{$tpt}'
     
    13781412
    13791413    // 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`)
    13811415            ( SELECT `reply`.`ID`, '_bbp_topic_id', `topic`.`ID`
    1382             FROM `$wpdb->posts`
     1416            FROM `$bbp_db->posts`
    13831417                AS `reply`
    1384             INNER JOIN `$wpdb->posts`
     1418            INNER JOIN `$bbp_db->posts`
    13851419                AS `topic`
    13861420                ON `reply`.`post_parent` = `topic`.`ID`
     
    14071441 */
    14081442function bbp_admin_repair_reply_menu_order() {
    1409     global $wpdb;
    1410 
     1443
     1444    // Define variables
     1445    $bbp_db    = bbp_db();
    14111446    $statement = __( 'Recalculating reply menu order &hellip; %s', 'bbpress' );
    14121447    $result    = __( 'No reply positions to recalculate!',         'bbpress' );
    14131448
    14141449    // 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`;" ) ) ) {
    14161451        return array( 1, sprintf( $statement, $result ) );
    14171452    }
     
    14211456
    14221457    // 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`
    14241459                                        INNER JOIN (
    14251460                                            SELECT `menu_order`, `post_parent`
    1426                                             FROM `{$wpdb->posts}`
     1461                                            FROM `{$bbp_db->posts}`
    14271462                                            GROUP BY `menu_order`, `post_parent`
    14281463                                            HAVING COUNT( * ) >1
     
    15461581    check_admin_referer( 'bbpress-reset' );
    15471582
    1548     global $wpdb;
    1549 
    15501583    // Stores messages
    15511584    $messages = array();
     
    15631596    $rpt = bbp_get_reply_post_type();
    15641597
     1598    // Define variables
     1599    $bbp_db    = bbp_db();
    15651600    $statement  = __( 'Deleting Posts&hellip; %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;
    15691605    $messages[] = sprintf( $statement, $result );
    15701606
     
    15781614        $statement  = __( 'Deleting Post Meta&hellip; %s', 'bbpress' );
    15791615        $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;
    15821618        $messages[] = sprintf( $statement, $result );
    15831619    }
     
    15861622
    15871623    $statement  = __( 'Deleting Topic Tags&hellip; %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;
    15901626    $messages[] = sprintf( $statement, $result );
    15911627
     
    15941630    // First, if we're deleting previously imported users, delete them now
    15951631    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 );
    15971633        if ( !empty( $sql_users ) ) {
    15981634            $sql_meta = array();
     
    16021638            $statement  = __( 'Deleting User&hellip; %s', 'bbpress' );
    16031639            $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;
    16061642            $messages[] = sprintf( $statement, $result );
    16071643            $statement  = __( 'Deleting User Meta&hellip; %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;
    16101646            $messages[] = sprintf( $statement, $result );
    16111647        }
     
    16141650    // Next, if we still have users that were not imported delete that meta data
    16151651    $statement  = __( 'Deleting User Meta&hellip; %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;
    16181654    $messages[] = sprintf( $statement, $result );
    16191655
     
    16211657
    16221658    $statement  = __( 'Deleting Conversion Table&hellip; %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}" );
    16261662        $result = $success;
    16271663    } else {
Note: See TracChangeset for help on using the changeset viewer.