Changeset 5827
- Timestamp:
- 07/14/2015 12:31:42 AM (9 years ago)
- Location:
- trunk/src/includes
- Files:
-
- 17 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/includes/admin/admin.php
r5809 r5827 693 693 */ 694 694 public function suggest_topic() { 695 global $wpdb;696 695 697 696 // Bail early if no request … … 710 709 // Try to get some topics 711 710 $topics = get_posts( array( 712 's' => $wpdb->esc_like( $_REQUEST['q'] ),711 's' => bbp_db()->esc_like( $_REQUEST['q'] ), 713 712 'post_type' => bbp_get_topic_post_type() 714 713 ) ); … … 729 728 */ 730 729 public function suggest_user() { 731 global $wpdb;732 730 733 731 // Bail early if no request … … 746 744 // Try to get some users 747 745 $users_query = new WP_User_Query( array( 748 'search' => '*' . $wpdb->esc_like( $_REQUEST['q'] ) . '*',746 'search' => '*' . bbp_db()->esc_like( $_REQUEST['q'] ) . '*', 749 747 'fields' => array( 'ID', 'user_nicename' ), 750 748 'search_columns' => array( 'ID', 'user_nicename', 'user_email' ), … … 948 946 * @since bbPress (r3689) 949 947 * 950 * @global WPDB $wpdb951 948 * @uses get_blog_option() 952 949 * @uses wp_remote_get() … … 995 992 * @since bbPress (r3689) 996 993 * 997 * @global WPDB $wpdb998 994 * @uses get_blog_option() 999 995 * @uses wp_remote_get() 1000 996 */ 1001 997 public static function network_update_screen() { 1002 global $wpdb;998 $bbp_db = bbp_db(); 1003 999 1004 1000 // Get action … … 1019 1015 1020 1016 // Get blogs 5 at a time 1021 $blogs = $ wpdb->get_results( "SELECT * FROM {$wpdb->blogs} WHERE site_id = '{$wpdb->siteid}' AND spam = '0' AND deleted = '0' AND archived = '0' ORDER BY registered DESC LIMIT {$n}, 5", ARRAY_A );1017 $blogs = $bbp_db->get_results( "SELECT * FROM {$bbp_db->blogs} WHERE site_id = '{$bbp_db->siteid}' AND spam = '0' AND deleted = '0' AND archived = '0' ORDER BY registered DESC LIMIT {$n}, 5", ARRAY_A ); 1022 1018 1023 1019 // No blogs so all done! -
trunk/src/includes/admin/converter.php
r5770 r5827 630 630 */ 631 631 public function sync_table( $drop = false ) { 632 global $wpdb; 633 634 $table_name = $ wpdb->prefix . 'bbp_converter_translator';635 if ( ! empty( $drop ) && $ wpdb->get_var( "SHOW TABLES LIKE '{$table_name}'" ) == $table_name ) {636 $ wpdb->query( "DROP TABLE {$table_name}" );632 633 $bbp_db = bbp_db(); 634 $table_name = $bbp_db->prefix . 'bbp_converter_translator'; 635 if ( ! empty( $drop ) && $bbp_db->get_var( "SHOW TABLES LIKE '{$table_name}'" ) == $table_name ) { 636 $bbp_db->query( "DROP TABLE {$table_name}" ); 637 637 } 638 638 639 639 require_once( ABSPATH . '/wp-admin/includes/upgrade.php' ); 640 640 641 if ( !empty( $ wpdb->charset ) ) {642 $charset_collate = "DEFAULT CHARACTER SET $ wpdb->charset";643 } 644 645 if ( !empty( $ wpdb->collate ) ) {646 $charset_collate .= " COLLATE $ wpdb->collate";641 if ( !empty( $bbp_db->charset ) ) { 642 $charset_collate = "DEFAULT CHARACTER SET $bbp_db->charset"; 643 } 644 645 if ( !empty( $bbp_db->collate ) ) { 646 $charset_collate .= " COLLATE $bbp_db->collate"; 647 647 } 648 648 … … 676 676 677 677 /** 678 * @var object This is the connection to the WordPress dat base.678 * @var object This is the connection to the WordPress database. 679 679 */ 680 680 protected $wpdb; … … 740 740 741 741 private function setup_globals() { 742 global $wpdb;743 742 744 743 /** Get database connections ******************************************/ 745 744 746 $this->wpdb = $wpdb;745 $this->wpdb = bbp_db(); 747 746 $this->max_rows = (int) $_POST['_bbp_converter_rows']; 748 747 $this->opdb = new wpdb( $_POST['_bbp_converter_db_user'], $_POST['_bbp_converter_db_pass'], $_POST['_bbp_converter_db_name'], $_POST['_bbp_converter_db_server'] ); -
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 463 $f_count 464 $s_count 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 { -
trunk/src/includes/common/functions.php
r5790 r5827 672 672 } 673 673 674 // Define global to use get_meta_sql() and get_var() methods675 global $wpdb;676 677 674 // Parse arguments against default values 678 675 $r = bbp_parse_args( $post_data, array( … … 685 682 ), 'check_for_duplicate' ); 686 683 684 // Get the DB 685 $bbp_db = bbp_db(); 686 687 687 // Check for anonymous post 688 688 if ( empty( $r['post_author'] ) && ( !empty( $r['anonymous_data'] ) && !empty( $r['anonymous_data']['bbp_anonymous_email'] ) ) ) { … … 690 690 'key' => '_bbp_anonymous_email', 691 691 'value' => $r['anonymous_data']['bbp_anonymous_email'] 692 ) ), 'post', $ wpdb->posts, 'ID' );692 ) ), 'post', $bbp_db->posts, 'ID' ); 693 693 694 694 $join = $clauses['join']; … … 698 698 } 699 699 700 // Unslash $r to pass through $wpdb->prepare()700 // Unslash $r to pass through DB->prepare() 701 701 // 702 702 // @see: https://bbpress.trac.wordpress.org/ticket/2185/ … … 705 705 706 706 // Prepare duplicate check query 707 $query = $ wpdb->prepare( "SELECT ID FROM {$wpdb->posts} {$join} WHERE post_type = %s AND post_status != %s AND post_author = %d AND post_content = %s {$where}", $r['post_type'], $r['post_status'], $r['post_author'], $r['post_content'] );708 $query .= !empty( $r['post_parent'] ) ? $ wpdb->prepare( " AND post_parent = %d", $r['post_parent'] ) : '';707 $query = $bbp_db->prepare( "SELECT ID FROM {$bbp_db->posts} {$join} WHERE post_type = %s AND post_status != %s AND post_author = %d AND post_content = %s {$where}", $r['post_type'], $r['post_status'], $r['post_author'], $r['post_content'] ); 708 $query .= !empty( $r['post_parent'] ) ? $bbp_db->prepare( " AND post_parent = %d", $r['post_parent'] ) : ''; 709 709 $query .= " LIMIT 1"; 710 710 $dupe = apply_filters( 'bbp_check_for_duplicate_query', $query, $r ); 711 711 712 if ( $ wpdb->get_var( $dupe ) ) {712 if ( $bbp_db->get_var( $dupe ) ) { 713 713 do_action( 'bbp_check_for_duplicate_trigger', $post_data ); 714 714 return false; … … 1451 1451 * 1452 1452 * @since bbPress (r2996) 1453 * 1454 * @global DB $wpdb1453 * @deprecated bbPress (r5814) 1454 * 1455 1455 * @global WP $wp 1456 1456 * @param string $where … … 1459 1459 */ 1460 1460 function bbp_query_post_parent__in( $where, $object = '' ) { 1461 global $wp db, $wp;1461 global $wp; 1462 1462 1463 1463 // Noop if WP core supports this already … … 1476 1476 } 1477 1477 1478 // Get the DB 1479 $bbp_db = bbp_db(); 1480 1478 1481 // Including specific post_parent's 1479 1482 if ( ! empty( $object->query_vars['post_parent__in'] ) ) { 1480 1483 $ids = implode( ',', wp_parse_id_list( $object->query_vars['post_parent__in'] ) ); 1481 $where .= " AND {$ wpdb->posts}.post_parent IN ($ids)";1484 $where .= " AND {$bbp_db->posts}.post_parent IN ($ids)"; 1482 1485 1483 1486 // Excluding specific post_parent's 1484 1487 } elseif ( ! empty( $object->query_vars['post_parent__not_in'] ) ) { 1485 1488 $ids = implode( ',', wp_parse_id_list( $object->query_vars['post_parent__not_in'] ) ); 1486 $where .= " AND {$ wpdb->posts}.post_parent NOT IN ($ids)";1489 $where .= " AND {$bbp_db->posts}.post_parent NOT IN ($ids)"; 1487 1490 } 1488 1491 … … 1506 1509 */ 1507 1510 function bbp_get_public_child_last_id( $parent_id = 0, $post_type = 'post' ) { 1508 global $wpdb;1509 1511 1510 1512 // Bail if nothing passed … … 1528 1530 // Join post statuses together 1529 1531 $post_status = "'" . implode( "', '", $post_status ) . "'"; 1530 1531 $child_id = (int) $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM {$wpdb->posts} WHERE post_parent = %d AND post_status IN ( {$post_status} ) AND post_type = '%s' ORDER BY ID DESC LIMIT 1;", $parent_id, $post_type ) ); 1532 $bbp_db = bbp_db(); 1533 $query = $bbp_db->prepare( "SELECT ID FROM {$bbp_db->posts} WHERE post_parent = %d AND post_status IN ( {$post_status} ) AND post_type = '%s' ORDER BY ID DESC LIMIT 1;", $parent_id, $post_type ); 1534 $child_id = (int) $bbp_db->get_var( $query ); 1532 1535 1533 1536 wp_cache_set( $cache_id, $child_id, 'bbpress_posts' ); … … 1557 1560 */ 1558 1561 function bbp_get_public_child_count( $parent_id = 0, $post_type = 'post' ) { 1559 global $wpdb;1560 1562 1561 1563 // Bail if nothing passed … … 1579 1581 // Join post statuses together 1580 1582 $post_status = "'" . implode( "', '", $post_status ) . "'"; 1581 1582 $child_count = (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(ID) FROM {$wpdb->posts} WHERE post_parent = %d AND post_status IN ( {$post_status} ) AND post_type = '%s';", $parent_id, $post_type ) ); 1583 $bbp_db = bbp_db(); 1584 $query = $bbp_db->prepare( "SELECT COUNT(ID) FROM {$bbp_db->posts} WHERE post_parent = %d AND post_status IN ( {$post_status} ) AND post_type = '%s';", $parent_id, $post_type ); 1585 $child_count = (int) $bbp_db->get_var( $query ); 1583 1586 1584 1587 wp_cache_set( $cache_id, $child_count, 'bbpress_posts' ); … … 1610 1613 */ 1611 1614 function bbp_get_public_child_ids( $parent_id = 0, $post_type = 'post' ) { 1612 global $wpdb;1613 1615 1614 1616 // Bail if nothing passed … … 1632 1634 // Join post statuses together 1633 1635 $post_status = "'" . implode( "', '", $post_status ) . "'"; 1634 1635 $child_ids = (array) $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM {$wpdb->posts} WHERE post_parent = %d AND post_status IN ( {$post_status} ) AND post_type = '%s' ORDER BY ID DESC;", $parent_id, $post_type ) ); 1636 $bbp_db = bbp_db(); 1637 $query = $bbp_db->prepare( "SELECT ID FROM {$bbp_db->posts} WHERE post_parent = %d AND post_status IN ( {$post_status} ) AND post_type = '%s' ORDER BY ID DESC;", $parent_id, $post_type ); 1638 $child_ids = (array) $bbp_db->get_col( $query ); 1636 1639 1637 1640 wp_cache_set( $cache_id, $child_ids, 'bbpress_posts' ); … … 1670 1673 */ 1671 1674 function bbp_get_all_child_ids( $parent_id = 0, $post_type = 'post' ) { 1672 global $wpdb;1673 1675 1674 1676 // Bail if nothing passed … … 1712 1714 // Join post statuses together 1713 1715 $post_status = "'" . implode( "', '", $post_status ) . "'"; 1714 1715 $child_ids = (array) $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM {$wpdb->posts} WHERE post_parent = %d AND post_status IN ( {$post_status} ) AND post_type = '%s' ORDER BY ID DESC;", $parent_id, $post_type ) ); 1716 $bbp_db = bbp_db(); 1717 $query = $bbp_db->prepare( "SELECT ID FROM {$bbp_db->posts} WHERE post_parent = %d AND post_status IN ( {$post_status} ) AND post_type = '%s' ORDER BY ID DESC;", $parent_id, $post_type ); 1718 $child_ids = (array) $bbp_db->get_col( $query ); 1716 1719 1717 1720 wp_cache_set( $cache_id, $child_ids, 'bbpress_posts' ); -
trunk/src/includes/common/template.php
r5770 r5827 2058 2058 */ 2059 2059 function bbp_get_view_url( $view = false ) { 2060 global $wp_rewrite;2061 2060 2062 2061 $view = bbp_get_view_id( $view ); … … 2066 2065 2067 2066 // Pretty permalinks 2068 if ( $wp_rewrite->using_permalinks() ) { 2069 $url = $wp_rewrite->root . bbp_get_view_slug() . '/' . $view; 2070 $url = home_url( user_trailingslashit( $url ) ); 2067 if ( bbp_use_pretty_urls() ) { 2068 $url = trailingslashit( bbp_get_root_url() . bbp_get_view_slug() ) . $view; 2069 $url = user_trailingslashit( $url ); 2070 $url = home_url( $url ); 2071 2071 2072 2072 // Unpretty permalinks 2073 2073 } else { 2074 $url = add_query_arg( array( bbp_get_view_rewrite_id() => $view ), home_url( '/' ) ); 2074 $url = add_query_arg( array( 2075 bbp_get_view_rewrite_id() => $view 2076 ), home_url( '/' ) ); 2075 2077 } 2076 2078 -
trunk/src/includes/core/capabilities.php
r5770 r5827 244 244 245 245 /** 246 * Get the $wp_rolesglobal without needing to declare it everywhere246 * Get the `$wp_roles` global without needing to declare it everywhere 247 247 * 248 248 * @since bbPress (r4293) 249 249 * 250 * @global WP_Roles $wp_roles251 250 * @return WP_Roles 252 251 */ 253 252 function bbp_get_wp_roles() { 254 global $wp_roles; 255 256 // Load roles if not set 257 if ( ! isset( $wp_roles ) ) { 258 $wp_roles = new WP_Roles(); 259 } 260 261 return $wp_roles; 253 254 // Try to get `$wp_roles` 255 $retval = bbp_get_global_object( 'wp_roles', 'WP_Roles' ); 256 257 // Set roles if not loaded 258 if ( is_null( $retval ) ) { 259 $retval = $GLOBALS['wp_roles'] = new WP_Roles(); 260 } 261 262 return $retval; 262 263 } 263 264 … … 273 274 274 275 // Get WordPress's roles (returns $wp_roles global) 275 $wp_roles 276 $wp_roles = bbp_get_wp_roles(); 276 277 277 278 // Apply the WordPress 'editable_roles' filter to let plugins ride along. … … 302 303 303 304 foreach ( bbp_get_dynamic_roles() as $role_id => $details ) { 304 $wp_roles->roles[ $role_id] = $details;305 $wp_roles->role_objects[ $role_id] = new WP_Role( $role_id, $details['capabilities'] );306 $wp_roles->role_names[ $role_id] = $details['name'];305 $wp_roles->roles[ $role_id ] = $details; 306 $wp_roles->role_objects[ $role_id ] = new WP_Role( $role_id, $details['capabilities'] ); 307 $wp_roles->role_names[ $role_id ] = $details['name']; 307 308 } 308 309 … … 316 317 * 317 318 * @see _bbp_reinit_dynamic_roles() 318 *319 * @global WPDB $wpdb Used to get the database prefix320 319 */ 321 320 function bbp_filter_user_roles_option() { 322 global $wpdb; 323 324 $role_key = $wpdb->prefix . 'user_roles'; 321 $role_key = bbp_db()->prefix . 'user_roles'; 325 322 326 323 add_filter( 'option_' . $role_key, '_bbp_reinit_dynamic_roles' ); … … 419 416 function bbp_get_dynamic_role_name( $role_id = '' ) { 420 417 $roles = bbp_get_dynamic_roles(); 421 $role = isset( $roles[ $role_id] ) ? $roles[$role_id]['name'] : '';418 $role = isset( $roles[ $role_id ] ) ? $roles[ $role_id ]['name'] : ''; 422 419 423 420 return apply_filters( 'bbp_get_dynamic_role_name', $role, $role_id, $roles ); … … 445 442 // If keys match, unset 446 443 if ( $wp_role === $bbp_role ) { 447 unset( $all_roles[ $wp_role] );444 unset( $all_roles[ $wp_role ] ); 448 445 } 449 446 } -
trunk/src/includes/core/theme-compat.php
r5770 r5827 804 804 * 805 805 * @since bbPress (r2628) 806 * 806 807 * @param string $redirect_url Redirect url 807 * @uses WP_Rewrite::using_permalinks() To check if the blog is using permalinks808 * @uses bbp_use_pretty_urls() To check if the blog is using permalinks 808 809 * @uses bbp_get_paged() To get the current page number 809 810 * @uses bbp_is_single_topic() To check if it's a topic page 810 811 * @uses bbp_is_single_forum() To check if it's a forum page 812 * 811 813 * @return bool|string False if it's a topic/forum and their first page, 812 814 * otherwise the redirect url 813 815 */ 814 816 function bbp_redirect_canonical( $redirect_url ) { 815 global $wp_rewrite;816 817 817 818 // Canonical is for the beautiful 818 if ( $wp_rewrite->using_permalinks() ) {819 if ( bbp_use_pretty_urls() ) { 819 820 820 821 // If viewing beyond page 1 of several -
trunk/src/includes/forums/functions.php
r5775 r5827 822 822 // Only run queries if visibility is changing 823 823 if ( bbp_get_public_status_id() !== $current_visibility ) { 824 825 // Update forums visibility setting 826 global $wpdb; 827 $wpdb->update( $wpdb->posts, array( 'post_status' => bbp_get_public_status_id() ), array( 'ID' => $forum_id ) ); 824 $bbp_db = bbp_db(); 825 $bbp_db->update( $bbp_db->posts, array( 'post_status' => bbp_get_public_status_id() ), array( 'ID' => $forum_id ) ); 828 826 wp_transition_post_status( bbp_get_public_status_id(), $current_visibility, get_post( $forum_id ) ); 829 827 bbp_clean_post_cache( $forum_id ); … … 874 872 875 873 // Update forums visibility setting 876 global $wpdb;877 $ wpdb->update( $wpdb->posts, array( 'post_status' => bbp_get_private_status_id() ), array( 'ID' => $forum_id ) );874 $bbp_db = bbp_db(); 875 $bbp_db->update( $bbp_db->posts, array( 'post_status' => bbp_get_private_status_id() ), array( 'ID' => $forum_id ) ); 878 876 wp_transition_post_status( bbp_get_private_status_id(), $current_visibility, get_post( $forum_id ) ); 879 877 bbp_clean_post_cache( $forum_id ); … … 924 922 925 923 // Update forums visibility setting 926 global $wpdb;927 $ wpdb->update( $wpdb->posts, array( 'post_status' => bbp_get_hidden_status_id() ), array( 'ID' => $forum_id ) );924 $bbp_db = bbp_db(); 925 $bbp_db->update( $bbp_db->posts, array( 'post_status' => bbp_get_hidden_status_id() ), array( 'ID' => $forum_id ) ); 928 926 wp_transition_post_status( bbp_get_hidden_status_id(), $current_visibility, get_post( $forum_id ) ); 929 927 bbp_clean_post_cache( $forum_id ); … … 1511 1509 */ 1512 1510 function bbp_update_forum_topic_count_hidden( $forum_id = 0, $topic_count = 0 ) { 1513 global $wpdb;1514 1511 1515 1512 // If topic_id was passed as $forum_id, then get its forum … … 1528 1525 // Get topics of forum 1529 1526 if ( empty( $topic_count ) ) { 1527 $bbp_db = bbp_db(); 1530 1528 $post_status = "'" . implode( "','", array( bbp_get_trash_status_id(), bbp_get_spam_status_id(), bbp_get_pending_status_id() ) ) . "'"; 1531 $topic_count = $ wpdb->get_var( $wpdb->prepare( "SELECT COUNT(ID) FROM {$wpdb->posts} WHERE post_parent = %d AND post_status IN ( {$post_status} ) AND post_type = '%s';", $forum_id, bbp_get_topic_post_type() ) );1529 $topic_count = $bbp_db->get_var( $bbp_db->prepare( "SELECT COUNT(ID) FROM {$bbp_db->posts} WHERE post_parent = %d AND post_status IN ( {$post_status} ) AND post_type = '%s';", $forum_id, bbp_get_topic_post_type() ) ); 1532 1530 } 1533 1531 … … 1563 1561 */ 1564 1562 function bbp_update_forum_reply_count( $forum_id = 0 ) { 1565 global $wpdb;1566 1563 1567 1564 $forum_id = bbp_get_forum_id( $forum_id ); … … 1580 1577 $topic_ids = bbp_forum_query_topic_ids( $forum_id ); 1581 1578 if ( ! empty( $topic_ids ) ) { 1579 $bbp_db = bbp_db(); 1582 1580 $topic_ids = implode( ',', wp_parse_id_list( $topic_ids ) ); 1583 $reply_count = (int) $ wpdb->get_var( $wpdb->prepare( "SELECT COUNT(ID) FROM {$wpdb->posts} WHERE post_parent IN ( {$topic_ids} ) AND post_status = '%s' AND post_type = '%s';", bbp_get_public_status_id(), bbp_get_reply_post_type() ) );1581 $reply_count = (int) $bbp_db->get_var( $bbp_db->prepare( "SELECT COUNT(ID) FROM {$bbp_db->posts} WHERE post_parent IN ( {$topic_ids} ) AND post_status = '%s' AND post_type = '%s';", bbp_get_public_status_id(), bbp_get_reply_post_type() ) ); 1584 1582 } 1585 1583 … … 2004 2002 */ 2005 2003 function bbp_forum_query_last_reply_id( $forum_id, $topic_ids = 0 ) { 2006 global $wpdb;2007 2004 2008 2005 $cache_id = 'bbp_get_forum_' . $forum_id . '_reply_id'; … … 2016 2013 2017 2014 if ( !empty( $topic_ids ) ) { 2015 $bbp_db = bbp_db(); 2018 2016 $topic_ids = implode( ',', wp_parse_id_list( $topic_ids ) ); 2019 $reply_id = (int) $ wpdb->get_var( $wpdb->prepare( "SELECT ID FROM {$wpdb->posts} WHERE post_parent IN ( {$topic_ids} ) AND post_status = '%s' AND post_type = '%s' ORDER BY ID DESC LIMIT 1;", bbp_get_public_status_id(), bbp_get_reply_post_type() ) );2017 $reply_id = (int) $bbp_db->get_var( $bbp_db->prepare( "SELECT ID FROM {$bbp_db->posts} WHERE post_parent IN ( {$topic_ids} ) AND post_status = '%s' AND post_type = '%s' ORDER BY ID DESC LIMIT 1;", bbp_get_public_status_id(), bbp_get_reply_post_type() ) ); 2020 2018 } else { 2021 2019 $reply_id = 0; -
trunk/src/includes/replies/functions.php
r5825 r5827 1249 1249 * and destination topic ids 1250 1250 * @uses bbp_get_reply_post_type() To get the reply post type 1251 * @uses wpdb::prepare() To prepare our sql query1252 * @uses wpdb::get_results() To execute the sql query and get results1253 1251 * @uses wp_update_post() To update the replies 1254 1252 * @uses bbp_update_reply_topic_id() To update the reply topic id … … 2112 2110 /** Proceed ***************************************************************/ 2113 2111 2114 global $wpdb;2115 2116 2112 // Table name for posts 2117 $table_name = $wpdb->prefix . 'posts';2113 $table_name = bbp_db()->prefix . 'posts'; 2118 2114 2119 2115 // Get the topic ID from the post_parent, set in bbp_has_replies() -
trunk/src/includes/replies/template.php
r5770 r5827 109 109 * others' replies 110 110 * @uses WP_Query To make query and get the replies 111 * @uses WP_Rewrite::using_permalinks() To check if the blog is using permalinks111 * @uses bbp_use_pretty_urls() To check if the site is using pretty URLs 112 112 * @uses get_permalink() To get the permalink 113 113 * @uses add_query_arg() To add custom args to the url … … 120 120 */ 121 121 function bbp_has_replies( $args = array() ) { 122 global $wp_rewrite;123 122 124 123 /** Defaults **************************************************************/ … … 226 225 227 226 // If pretty permalinks are enabled, make our pagination pretty 228 if ( $wp_rewrite->using_permalinks() ) {227 if ( bbp_use_pretty_urls() ) { 229 228 230 229 // User's replies … … 245 244 } 246 245 247 $base = trailingslashit( $base ) . user_trailingslashit( $wp_rewrite->pagination_base. '/%#%/' );246 $base = trailingslashit( $base ) . user_trailingslashit( bbp_get_paged_slug() . '/%#%/' ); 248 247 249 248 // Unpretty permalinks … … 272 271 273 272 // Remove first page from pagination 274 if ( $wp_rewrite->using_permalinks() ) {275 $bbp->reply_query->pagination_links = str_replace( $wp_rewrite->pagination_base. '/1/', '', $bbp->reply_query->pagination_links );273 if ( bbp_use_pretty_urls() ) { 274 $bbp->reply_query->pagination_links = str_replace( bbp_get_paged_slug() . '/1/', '', $bbp->reply_query->pagination_links ); 276 275 } else { 277 276 $bbp->reply_query->pagination_links = str_replace( '&paged=1', '', $bbp->reply_query->pagination_links ); … … 474 473 * @uses bbp_get_reply_position() To get the reply position 475 474 * @uses get_option() To get the replies per page option 476 * @uses WP_Rewrite::using_permalinks() To check if the blog uses 477 * permalinks 475 * @uses bbp_use_pretty_urls() To check if the site uses pretty URLs 478 476 * @uses add_query_arg() To add custom args to the url 479 477 * @uses apply_filters() Calls 'bbp_get_reply_url' with the reply url, … … 506 504 // Include pagination 507 505 } else { 508 global $wp_rewrite;509 506 510 507 // Pretty permalinks 511 if ( $wp_rewrite->using_permalinks() ) {512 $url = trailingslashit( $topic_url ) . trailingslashit( $wp_rewrite->pagination_base) . trailingslashit( $reply_page ) . $reply_hash;508 if ( bbp_use_pretty_urls() ) { 509 $url = trailingslashit( $topic_url ) . trailingslashit( bbp_get_paged_slug() ) . trailingslashit( $reply_page ) . $reply_hash; 513 510 514 511 // Yucky links … … 2022 2019 */ 2023 2020 function bbp_get_reply_edit_url( $reply_id = 0 ) { 2024 global $wp_rewrite;2025 2021 2026 2022 $reply = bbp_get_reply( $reply_id ); … … 2032 2028 2033 2029 // Pretty permalinks 2034 if ( $wp_rewrite->using_permalinks() ) {2030 if ( bbp_use_pretty_urls() ) { 2035 2031 $url = trailingslashit( $reply_link ) . bbp_get_edit_rewrite_id(); 2036 $url = trailingslashit( $url );2032 $url = user_trailingslashit( $url ); 2037 2033 2038 2034 // Unpretty permalinks 2039 2035 } else { 2040 $url = add_query_arg( array( bbp_get_reply_post_type() => $reply->post_name, bbp_get_edit_rewrite_id() => '1' ), $reply_link ); 2036 $url = add_query_arg( array( 2037 bbp_get_reply_post_type() => $reply->post_name, 2038 bbp_get_edit_rewrite_id() => '1' 2039 ), $reply_link ); 2041 2040 } 2042 2041 -
trunk/src/includes/search/functions.php
r5770 r5827 16 16 * Run the search query 17 17 * 18 * @since bbPress (r4579) 18 * @since bbPress (r4579) 19 19 * 20 20 * @param mixed $new_args New arguments … … 26 26 function bbp_search_query( $new_args = array() ) { 27 27 28 // Existing arguments 28 // Existing arguments 29 29 $query_args = bbp_get_search_query_args(); 30 30 … … 59 59 * 60 60 * @since bbPress (r4928) 61 * 61 62 * @return If a redirect is not needed 62 63 */ 63 64 function bbp_search_results_redirect() { 64 global $wp_rewrite; 65 65 66 66 // Bail if not a search request action 67 67 if ( empty( $_GET['action'] ) || ( 'bbp-search-request' !== $_GET['action'] ) ) { … … 70 70 71 71 // Bail if not using pretty permalinks 72 if ( ! $wp_rewrite->using_permalinks() ) {72 if ( ! bbp_use_pretty_urls() ) { 73 73 return; 74 74 } -
trunk/src/includes/search/template.php
r5770 r5827 31 31 * @uses bbp_get_search_terms() To get the search terms 32 32 * @uses WP_Query To make query and get the search results 33 * @uses WP_Rewrite::using_permalinks() To check if the blog is using permalinks33 * @uses bbp_use_pretty_urls() To check if the site is using pretty URLs 34 34 * @uses bbp_get_search_url() To get the forum search url 35 35 * @uses paginate_links() To paginate search results … … 40 40 */ 41 41 function bbp_has_search_results( $args = array() ) { 42 global $wp_rewrite;43 42 44 43 /** Defaults **************************************************************/ … … 115 114 116 115 // If pretty permalinks are enabled, make our pagination pretty 117 if ( $wp_rewrite->using_permalinks() ) {116 if ( bbp_use_pretty_urls() ) { 118 117 119 118 // Shortcode territory … … 127 126 128 127 // Add pagination base 129 $base = $base . user_trailingslashit( $wp_rewrite->pagination_base. '/%#%/' );128 $base = $base . user_trailingslashit( bbp_get_paged_slug() . '/%#%/' ); 130 129 131 130 // Unpretty permalinks … … 154 153 155 154 // Remove first page from pagination 156 if ( $wp_rewrite->using_permalinks() ) {157 $bbp->search_query->pagination_links = str_replace( $wp_rewrite->pagination_base. '/1/', '', $bbp->search_query->pagination_links );155 if ( bbp_use_pretty_urls() ) { 156 $bbp->search_query->pagination_links = str_replace( bbp_get_paged_slug() . '/1/', '', $bbp->search_query->pagination_links ); 158 157 } else { 159 158 $bbp->search_query->pagination_links = str_replace( '&paged=1', '', $bbp->search_query->pagination_links ); … … 264 263 */ 265 264 function bbp_get_search_url() { 266 global $wp_rewrite;267 265 268 266 // Pretty permalinks 269 if ( $wp_rewrite->using_permalinks() ) { 270 $url = $wp_rewrite->root . bbp_get_search_slug(); 271 $url = home_url( user_trailingslashit( $url ) ); 267 if ( bbp_use_pretty_urls() ) { 268 $url = bbp_get_root_url() . bbp_get_search_slug(); 269 $url = user_trailingslashit( $url ); 270 $url = home_url( $url ); 272 271 273 272 // Unpretty permalinks 274 273 } else { 275 $url = add_query_arg( array( bbp_get_search_rewrite_id() => '' ), home_url( '/' ) ); 274 $url = add_query_arg( array( 275 bbp_get_search_rewrite_id() => '' 276 ), home_url( '/' ) ); 276 277 } 277 278 … … 302 303 */ 303 304 function bbp_get_search_results_url() { 304 global $wp_rewrite;305 305 306 306 // Get the search terms … … 308 308 309 309 // Pretty permalinks 310 if ( $wp_rewrite->using_permalinks() ) {310 if ( bbp_use_pretty_urls() ) { 311 311 312 312 // Root search URL 313 $url = $wp_rewrite->root. bbp_get_search_slug();313 $url = bbp_get_root_url() . bbp_get_search_slug(); 314 314 315 315 // Append search terms 316 316 if ( ! empty( $search_terms ) ) { 317 $url = trailingslashit( $url ) . u ser_trailingslashit( urlencode( $search_terms ));317 $url = trailingslashit( $url ) . urlencode( $search_terms ); 318 318 } 319 319 320 320 // Run through home_url() 321 $url = home_url( user_trailingslashit( $url ) ); 321 $url = user_trailingslashit( $url ); 322 $url = home_url( $url ); 322 323 323 324 // Unpretty permalinks 324 325 } else { 325 $url = add_query_arg( array( bbp_get_search_rewrite_id() => urlencode( $search_terms ) ), home_url( '/' ) ); 326 $url = add_query_arg( array( 327 bbp_get_search_rewrite_id() => urlencode( $search_terms ) 328 ), home_url( '/' ) ); 326 329 } 327 330 -
trunk/src/includes/topics/functions.php
r5778 r5827 1472 1472 } 1473 1473 1474 global $wpdb;1475 1476 1474 // Prevent debug notices 1477 1475 $from_reply_id = $destination_topic_id = 0; … … 1678 1676 // get_posts() is not used because it doesn't allow us to use '>=' 1679 1677 // comparision without a filter. 1680 $replies = (array) $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->posts} WHERE {$wpdb->posts}.post_date >= %s AND {$wpdb->posts}.post_parent = %d AND {$wpdb->posts}.post_type = %s ORDER BY {$wpdb->posts}.post_date ASC", $from_reply->post_date, $source_topic->ID, bbp_get_reply_post_type() ) ); 1678 $bbp_db = bbp_db(); 1679 $query = $bbp_db->prepare( "SELECT * FROM {$bbp_db->posts} WHERE {$bbp_db->posts}.post_date >= %s AND {$bbp_db->posts}.post_parent = %d AND {$bbp_db->posts}.post_type = %s ORDER BY {$bbp_db->posts}.post_date ASC", $from_reply->post_date, $source_topic->ID, bbp_get_reply_post_type() ); 1680 $replies = (array) $bbp_db->get_results( $query ); 1681 1681 1682 1682 // Make sure there are replies to loop through … … 2509 2509 */ 2510 2510 function bbp_update_topic_reply_count_hidden( $topic_id = 0, $reply_count = 0 ) { 2511 global $wpdb;2512 2511 2513 2512 // If it's a reply, then get the parent (topic id) … … 2520 2519 // Get replies of topic 2521 2520 if ( empty( $reply_count ) ) { 2521 $bbp_db = bbp_db(); 2522 2522 $post_status = "'" . implode( "','", array( bbp_get_trash_status_id(), bbp_get_spam_status_id(), bbp_get_pending_status_id() ) ) . "'"; 2523 $reply_count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(ID) FROM {$wpdb->posts} WHERE post_parent = %d AND post_status IN ( {$post_status} ) AND post_type = '%s';", $topic_id, bbp_get_reply_post_type() ) ); 2523 $query = $bbp_db->prepare( "SELECT COUNT(ID) FROM {$bbp_db->posts} WHERE post_parent = %d AND post_status IN ( {$post_status} ) AND post_type = '%s';", $topic_id, bbp_get_reply_post_type() ); 2524 $reply_count = $bbp_db->get_var( $query ); 2524 2525 } 2525 2526 … … 2673 2674 * @uses bbp_get_topic_post_type() To get the topic post type 2674 2675 * @uses wpdb::prepare() To prepare our sql query 2675 * @uses wpdb::get_ col() To execute our query and get the column back2676 * @uses wpdb::get_var() To execute our query and get the column back 2676 2677 * @uses update_post_meta() To update the topic voice count meta 2677 2678 * @uses apply_filters() Calls 'bbp_update_topic_voice_count' with the voice … … 2680 2681 */ 2681 2682 function bbp_update_topic_voice_count( $topic_id = 0 ) { 2682 global $wpdb;2683 2683 2684 2684 // If it's a reply, then get the parent (topic id) … … 2692 2692 2693 2693 // Query the DB to get voices in this topic 2694 $voices = (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT( DISTINCT post_author ) FROM {$wpdb->posts} WHERE ( post_parent = %d AND post_status = '%s' AND post_type = '%s' ) OR ( ID = %d AND post_type = '%s' );", $topic_id, bbp_get_public_status_id(), bbp_get_reply_post_type(), $topic_id, bbp_get_topic_post_type() ) ); 2694 $bbp_db = bbp_db(); 2695 $query = $bbp_db->prepare( "SELECT COUNT( DISTINCT post_author ) FROM {$bbp_db->posts} WHERE ( post_parent = %d AND post_status = '%s' AND post_type = '%s' ) OR ( ID = %d AND post_type = '%s' );", $topic_id, bbp_get_public_status_id(), bbp_get_reply_post_type(), $topic_id, bbp_get_topic_post_type() ); 2696 $voices = (int) $bbp_db->get_var( $query ); 2695 2697 2696 2698 // Update the voice count for this topic id … … 2713 2715 * @uses bbp_get_topic_post_type() To get the topic post type 2714 2716 * @uses wpdb::prepare() To prepare our sql query 2715 * @uses wpdb::get_ col() To execute our query and get the column back2717 * @uses wpdb::get_var() To execute our query and get the column back 2716 2718 * @uses update_post_meta() To update the topic anonymous reply count meta 2717 2719 * @uses apply_filters() Calls 'bbp_update_topic_anonymous_reply_count' with the … … 2720 2722 */ 2721 2723 function bbp_update_topic_anonymous_reply_count( $topic_id = 0 ) { 2722 global $wpdb;2723 2724 2724 2725 // If it's a reply, then get the parent (topic id) … … 2731 2732 } 2732 2733 2733 $anonymous_replies = (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT( ID ) FROM {$wpdb->posts} WHERE ( post_parent = %d AND post_status = '%s' AND post_type = '%s' AND post_author = 0 ) OR ( ID = %d AND post_type = '%s' AND post_author = 0 );", $topic_id, bbp_get_public_status_id(), bbp_get_reply_post_type(), $topic_id, bbp_get_topic_post_type() ) ); 2734 2735 update_post_meta( $topic_id, '_bbp_anonymous_reply_count', $anonymous_replies ); 2736 2737 return (int) apply_filters( 'bbp_update_topic_anonymous_reply_count', $anonymous_replies, $topic_id ); 2734 // Query the DB to get anonymous replies in this topic 2735 $bbp_db = bbp_db(); 2736 $query = $bbp_db->prepare( "SELECT COUNT( ID ) FROM {$bbp_db->posts} WHERE ( post_parent = %d AND post_status = '%s' AND post_type = '%s' AND post_author = 0 ) OR ( ID = %d AND post_type = '%s' AND post_author = 0 );", $topic_id, bbp_get_public_status_id(), bbp_get_reply_post_type(), $topic_id, bbp_get_topic_post_type() ); 2737 $replies = (int) $bbp_db->get_var( $query ); 2738 2739 update_post_meta( $topic_id, '_bbp_anonymous_reply_count', $replies ); 2740 2741 return (int) apply_filters( 'bbp_update_topic_anonymous_reply_count', $replies, $topic_id ); 2738 2742 } 2739 2743 -
trunk/src/includes/topics/template.php
r5811 r5827 128 128 * @uses bbp_get_super_stickies() To get the super stickies 129 129 * @uses bbp_get_stickies() To get the forum stickies 130 * @uses wpdb::get_results() To execute our query and get the results 131 * @uses WP_Rewrite::using_permalinks() To check if the blog is using permalinks 130 * @uses bbp_use_pretty_urls() To check if the site is using pretty URLs 132 131 * @uses get_permalink() To get the permalink 133 132 * @uses add_query_arg() To add custom args to the url … … 140 139 */ 141 140 function bbp_has_topics( $args = array() ) { 142 global $wp_rewrite;143 141 144 142 /** Defaults **************************************************************/ … … 354 352 355 353 // If pretty permalinks are enabled, make our pagination pretty 356 if ( $wp_rewrite->using_permalinks() ) {354 if ( bbp_use_pretty_urls() ) { 357 355 358 356 // User's topics … … 398 396 399 397 // Use pagination base 400 $base = trailingslashit( $base ) . user_trailingslashit( $wp_rewrite->pagination_base. '/%#%/' );398 $base = trailingslashit( $base ) . user_trailingslashit( bbp_get_paged_slug() . '/%#%/' ); 401 399 402 400 // Unpretty pagination … … 420 418 421 419 // Remove first page from pagination 422 $bbp->topic_query->pagination_links = str_replace( $wp_rewrite->pagination_base. "/1/'", "'", $bbp->topic_query->pagination_links );420 $bbp->topic_query->pagination_links = str_replace( bbp_get_paged_slug() . "/1/'", "'", $bbp->topic_query->pagination_links ); 423 421 } 424 422 … … 851 849 * - after: After the links 852 850 * @uses bbp_get_topic_id() To get the topic id 853 * @uses WP_Rewrite::using_permalinks() To check if the blog is using 854 * permalinks 851 * @uses bbp_use_pretty_urls() To check if the site is using pretty URLs 855 852 * @uses user_trailingslashit() To add a trailing slash 856 853 * @uses trailingslashit() To add a trailing slash … … 866 863 */ 867 864 function bbp_get_topic_pagination( $args = array() ) { 868 global $wp_rewrite;869 865 870 866 // Bail if threading replies … … 881 877 882 878 // If pretty permalinks are enabled, make our pagination pretty 883 if ( $wp_rewrite->using_permalinks() ) {884 $base = trailingslashit( get_permalink( $r['topic_id'] ) ) . user_trailingslashit( $wp_rewrite->pagination_base. '/%#%/' );879 if ( bbp_use_pretty_urls() ) { 880 $base = trailingslashit( get_permalink( $r['topic_id'] ) ) . user_trailingslashit( bbp_get_paged_slug() . '/%#%/' ); 885 881 } else { 886 882 $base = add_query_arg( 'paged', '%#%', get_permalink( $r['topic_id'] ) ); … … 910 906 911 907 // Remove first page from pagination 912 if ( $wp_rewrite->using_permalinks() ) {913 $pagination_links = str_replace( $wp_rewrite->pagination_base. '/1/', '', $pagination_links );908 if ( bbp_use_pretty_urls() ) { 909 $pagination_links = str_replace( bbp_get_paged_slug() . '/1/', '', $pagination_links ); 914 910 } else { 915 911 $pagination_links = str_replace( '&paged=1', '', $pagination_links ); … … 2640 2636 */ 2641 2637 function bbp_get_topic_edit_url( $topic_id = 0 ) { 2642 global $wp_rewrite;2643 2638 2644 2639 $topic = bbp_get_topic( $topic_id ); … … 2651 2646 2652 2647 // Pretty permalinks 2653 if ( $wp_rewrite->using_permalinks() ) {2648 if ( bbp_use_pretty_urls() ) { 2654 2649 $url = trailingslashit( $topic_link ) . bbp_get_edit_rewrite_id(); 2655 $url = trailingslashit( $url );2650 $url = user_trailingslashit( $url ); 2656 2651 2657 2652 // Unpretty permalinks 2658 2653 } else { 2659 $url = add_query_arg( array( bbp_get_topic_post_type() => $topic->post_name, bbp_get_edit_rewrite_id() => '1' ), $topic_link ); 2654 $url = add_query_arg( array( 2655 bbp_get_topic_post_type() => $topic->post_name, 2656 bbp_get_edit_rewrite_id() => '1' 2657 ), $topic_link ); 2660 2658 } 2661 2659 … … 3767 3765 */ 3768 3766 function bbp_get_topic_tag_edit_link( $tag = '' ) { 3769 global $wp_rewrite;3770 3767 3771 3768 // Get the term … … 3781 3778 3782 3779 // Pretty 3783 if ( $wp_rewrite->using_permalinks() ) {3780 if ( bbp_use_pretty_urls() ) { 3784 3781 $retval = user_trailingslashit( trailingslashit( bbp_get_topic_tag_link() ) . bbp_get_edit_rewrite_id() ); 3785 3782 -
trunk/src/includes/users/capabilities.php
r5770 r5827 383 383 * @since bbPress (r3405) 384 384 * 385 * @global WPDB $wpdb386 385 * @param int $user_id Optional. User ID to spam. Defaults to displayed user. 387 386 … … 420 419 421 420 // Arm the torpedos 422 global $wpdb;421 $bbp_db = bbp_db(); 423 422 424 423 // Get the blog IDs of the user to mark as spam … … 427 426 // If user has no blogs, they are a guest on this site 428 427 if ( empty( $blogs ) ) { 429 $blogs[ $ wpdb->blogid ] = array();428 $blogs[ $bbp_db->blogid ] = array(); 430 429 } 431 430 … … 441 440 442 441 // Get topics and replies 443 $posts = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM {$wpdb->posts} WHERE post_author = %d AND post_status = '%s' AND post_type IN ( {$post_types} )", $user_id, bbp_get_public_status_id() ) ); 442 $query = $bbp_db->prepare( "SELECT ID FROM {$bbp_db->posts} WHERE post_author = %d AND post_status = '%s' AND post_type IN ( {$post_types} )", $user_id, bbp_get_public_status_id() ); 443 $posts = $bbp_db->get_col( $query ); 444 444 445 445 // Loop through posts and spam them … … 475 475 * @since bbPress (r3405) 476 476 * 477 * @global WPDB $wpdb478 477 * @param int $user_id Optional. User ID to unspam. Defaults to displayed user. 479 478 * … … 511 510 512 511 // Arm the torpedos 513 global $wpdb;512 $bbp_db = bbp_db(); 514 513 515 514 // Get the blog IDs of the user to mark as spam … … 518 517 // If user has no blogs, they are a guest on this site 519 518 if ( empty( $blogs ) ) { 520 $blogs[ $ wpdb->blogid ] = array();519 $blogs[ $bbp_db->blogid ] = array(); 521 520 } 522 521 … … 532 531 533 532 // Get topics and replies 534 $posts = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM {$wpdb->posts} WHERE post_author = %d AND post_status = '%s' AND post_type IN ( {$post_types} )", $user_id, bbp_get_spam_status_id() ) ); 533 $query = $bbp_db->prepare( "SELECT ID FROM {$bbp_db->posts} WHERE post_author = %d AND post_status = '%s' AND post_type IN ( {$post_types} )", $user_id, bbp_get_spam_status_id() ); 534 $posts = $bbp_db->get_col( $query ); 535 535 536 536 // Loop through posts and spam them -
trunk/src/includes/users/functions.php
r5805 r5827 188 188 } 189 189 190 global $wpdb; 191 192 $key = $wpdb->prefix . '_bbp_favorites'; 193 $users = wp_cache_get( 'bbp_get_topic_favoriters_' . $topic_id, 'bbpress_users' ); 190 $bbp_db = bbp_db(); 191 $key = $bbp_db->prefix . '_bbp_favorites'; 192 $users = wp_cache_get( 'bbp_get_topic_favoriters_' . $topic_id, 'bbpress_users' ); 194 193 if ( false === $users ) { 195 $users = $ wpdb->get_col( "SELECT user_id FROM {$wpdb->usermeta} WHERE meta_key = '{$key}' and FIND_IN_SET('{$topic_id}', meta_value) > 0" );194 $users = $bbp_db->get_col( "SELECT user_id FROM {$bbp_db->usermeta} WHERE meta_key = '{$key}' and FIND_IN_SET('{$topic_id}', meta_value) > 0" ); 196 195 wp_cache_set( 'bbp_get_topic_favoriters_' . $topic_id, $users, 'bbpress_users' ); 197 196 } … … 499 498 } 500 499 501 global $wpdb; 502 503 $key = $wpdb->prefix . '_bbp_forum_subscriptions'; 504 $users = wp_cache_get( 'bbp_get_forum_subscribers_' . $forum_id, 'bbpress_users' ); 500 $bbp_db = bbp_db(); 501 $key = $bbp_db->prefix . '_bbp_forum_subscriptions'; 502 $users = wp_cache_get( 'bbp_get_forum_subscribers_' . $forum_id, 'bbpress_users' ); 505 503 if ( false === $users ) { 506 $users = $ wpdb->get_col( "SELECT user_id FROM {$wpdb->usermeta} WHERE meta_key = '{$key}' and FIND_IN_SET('{$forum_id}', meta_value) > 0" );504 $users = $bbp_db->get_col( "SELECT user_id FROM {$bbp_db->usermeta} WHERE meta_key = '{$key}' and FIND_IN_SET('{$forum_id}', meta_value) > 0" ); 507 505 wp_cache_set( 'bbp_get_forum_subscribers_' . $forum_id, $users, 'bbpress_users' ); 508 506 } … … 527 525 } 528 526 529 global $wpdb; 530 531 $key = $wpdb->prefix . '_bbp_subscriptions'; 532 $users = wp_cache_get( 'bbp_get_topic_subscribers_' . $topic_id, 'bbpress_users' ); 527 $bbp_db = bbp_db(); 528 $key = $bbp_db->prefix . '_bbp_subscriptions'; 529 $users = wp_cache_get( 'bbp_get_topic_subscribers_' . $topic_id, 'bbpress_users' ); 533 530 if ( false === $users ) { 534 $users = $ wpdb->get_col( "SELECT user_id FROM {$wpdb->usermeta} WHERE meta_key = '{$key}' and FIND_IN_SET('{$topic_id}', meta_value) > 0" );531 $users = $bbp_db->get_col( "SELECT user_id FROM {$bbp_db->usermeta} WHERE meta_key = '{$key}' and FIND_IN_SET('{$topic_id}', meta_value) > 0" ); 535 532 wp_cache_set( 'bbp_get_topic_subscribers_' . $topic_id, $users, 'bbpress_users' ); 536 533 } … … 1316 1313 * is the one of the logged in user) 1317 1314 * @uses get_option() To get the displayed user's new email id option 1318 * @uses wpdb::prepare() To sanitize our sql query1319 * @uses wpdb::get_var() To execute our query and get back the variable1320 * @uses wpdb::query() To execute our query1321 1315 * @uses wp_update_user() To update the user 1322 1316 * @uses delete_option() To delete the displayed user's email id option … … 1331 1325 * @uses get_userdata() To get the user data 1332 1326 * @uses is_email() To check if the string is an email id or not 1333 * @uses wpdb::get_blog_prefix() To get the blog prefix1334 1327 * @uses is_network_admin() To check if the user is the network admin 1335 1328 * @uses revoke_super_admin() To revoke super admin priviledges … … 1449 1442 * @since bbPress (r5660) 1450 1443 * 1451 * @global object $wpdb 1452 * @param string $action 1444 * @param string $action 1453 1445 * 1454 1446 * @uses bbp_is_user_home_edit() To check if on the current users profile edit page … … 1531 1523 // Update signups table, if signups table & entry exists 1532 1524 // For Multisite & BuddyPress compatibility 1533 global $wpdb;1534 if ( ! empty( $ wpdb->signups ) && $wpdb->get_var( $wpdb->prepare( "SELECT user_login FROM {$wpdb->signups} WHERE user_login = %s", bbp_get_displayed_user_field( 'user_login', 'raw' ) ) ) ) {1535 $ wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->signups} SET user_email = %s WHERE user_login = %s", $user->user_email, bbp_get_displayed_user_field( 'user_login', 'raw' ) ) );1525 $bbp_db = bbp_db(); 1526 if ( ! empty( $bbp_db->signups ) && $bbp_db->get_var( $bbp_db->prepare( "SELECT user_login FROM {$bbp_db->signups} WHERE user_login = %s", bbp_get_displayed_user_field( 'user_login', 'raw' ) ) ) ) { 1527 $bbp_db->query( $bbp_db->prepare( "UPDATE {$bbp_db->signups} SET user_email = %s WHERE user_login = %s", $user->user_email, bbp_get_displayed_user_field( 'user_login', 'raw' ) ) ); 1536 1528 } 1537 1529 … … 1727 1719 * 1728 1720 * @since bbPress (r3633) 1721 * 1729 1722 * @param int $user_id User ID to get count for 1730 * @global WPDB $wpdb1723 * 1731 1724 * @uses bbp_get_user_id() 1732 1725 * @uses get_posts_by_author_sql() 1733 1726 * @uses bbp_get_topic_post_type() 1734 1727 * @uses apply_filters() 1728 * 1735 1729 * @return int Raw DB count of topics 1736 1730 */ … … 1741 1735 } 1742 1736 1743 global $wpdb; 1744 1745 $where = get_posts_by_author_sql( bbp_get_topic_post_type(), true, $user_id ); 1746 $count = (int) $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->posts} {$where}" ); 1737 $bbp_db = bbp_db(); 1738 $where = get_posts_by_author_sql( bbp_get_topic_post_type(), true, $user_id ); 1739 $count = (int) $bbp_db->get_var( "SELECT COUNT(*) FROM {$bbp_db->posts} {$where}" ); 1747 1740 1748 1741 return (int) apply_filters( 'bbp_get_user_topic_count_raw', $count, $user_id ); … … 1753 1746 * 1754 1747 * @since bbPress (r3633) 1748 * 1755 1749 * @param int $user_id User ID to get count for 1756 * @global WPDB $wpdb1750 * 1757 1751 * @uses bbp_get_user_id() 1758 1752 * @uses get_posts_by_author_sql() 1759 1753 * @uses bbp_get_reply_post_type() 1760 1754 * @uses apply_filters() 1755 * 1761 1756 * @return int Raw DB count of replies 1762 1757 */ … … 1767 1762 } 1768 1763 1769 global $wpdb; 1770 1771 $where = get_posts_by_author_sql( bbp_get_reply_post_type(), true, $user_id ); 1772 $count = (int) $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->posts} {$where}" ); 1764 $bbp_db = bbp_db(); 1765 $where = get_posts_by_author_sql( bbp_get_reply_post_type(), true, $user_id ); 1766 $count = (int) $bbp_db->get_var( "SELECT COUNT(*) FROM {$bbp_db->posts} {$where}" ); 1773 1767 1774 1768 return (int) apply_filters( 'bbp_get_user_reply_count_raw', $count, $user_id ); … … 1846 1840 1847 1841 // Add them up and filter them 1848 $new_count = apply_filters( 'bbp_bump_user_reply_count', ( (int) $count + (int) $difference ), $user_id, $difference, $count );1842 $new_count = apply_filters( 'bbp_bump_user_reply_count', $user_reply_count, $user_id, $difference, $count ); 1849 1843 1850 1844 return bbp_update_user_reply_count( $user_id, $new_count ); … … 2069 2063 * 2070 2064 * @since bbPress (r3813) 2071 * @global WPDB $wpdb2072 2065 */ 2073 2066 function bbp_user_maybe_convert_pass() { … … 2083 2076 } 2084 2077 2085 global $wpdb;2086 2087 2078 // Bail if no user password to convert 2088 $row = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->users} INNER JOIN {$wpdb->usermeta} ON user_id = ID WHERE meta_key = '_bbp_class' AND user_login = '%s' LIMIT 1", $username ) ); 2079 $bbp_db = bbp_db(); 2080 $query = $bbp_db->prepare( "SELECT * FROM {$bbp_db->users} INNER JOIN {$bbp_db->usermeta} ON user_id = ID WHERE meta_key = '_bbp_class' AND user_login = '%s' LIMIT 1", $username ); 2081 $row = $bbp_db->get_row( $query ); 2089 2082 if ( empty( $row ) || is_wp_error( $row ) ) { 2090 2083 return; -
trunk/src/includes/users/template.php
r5815 r5827 336 336 * @param string $user_nicename Optional. User nicename 337 337 * @uses bbp_get_user_id() To get user id 338 * @uses WP_Rewrite::using_permalinks() To check if the blog is using 339 * permalinks 338 * @uses bbp_use_pretty_urls() To check if the site is using pretty URLs 340 339 * @uses add_query_arg() To add custom args to the url 341 340 * @uses home_url() To get blog home url … … 345 344 */ 346 345 function bbp_get_user_profile_url( $user_id = 0, $user_nicename = '' ) { 347 global $wp_rewrite;348 346 349 347 // Use displayed user ID if there is one, and one isn't requested … … 360 358 361 359 // Pretty permalinks 362 if ( $wp_rewrite->using_permalinks() ) {360 if ( bbp_use_pretty_urls() ) { 363 361 364 362 // Get username if not passed … … 367 365 } 368 366 369 $url = trailingslashit( $wp_rewrite->root. bbp_get_user_slug() ) . $user_nicename;367 $url = trailingslashit( bbp_get_root_url() . bbp_get_user_slug() ) . $user_nicename; 370 368 $url = user_trailingslashit( $url ); 371 369 $url = home_url( $url ); … … 439 437 * @uses bbp_get_user_id() To get user id 440 438 * @uses bbp_get_user_profile_url() To get the user profile url 441 * @uses WP_Rewrite::using_permalinks() To check if the blog is using 442 * permalinks 439 * @uses bbp_use_pretty_urls() To check if the site is using pretty URLs 443 440 * @uses add_query_arg() To add custom args to the url 444 441 * @uses home_url() To get blog home url … … 448 445 */ 449 446 function bbp_get_user_profile_edit_url( $user_id = 0, $user_nicename = '' ) { 450 global $wp_rewrite;451 447 452 448 $user_id = bbp_get_user_id( $user_id ); … … 465 461 466 462 // Pretty permalinks 467 if ( $wp_rewrite->using_permalinks() ) {463 if ( bbp_use_pretty_urls() ) { 468 464 $url = trailingslashit( $profile_url ) . 'edit'; 469 465 $url = user_trailingslashit( $url ); … … 820 816 */ 821 817 function bbp_get_favorites_permalink( $user_id = 0 ) { 822 global $wp_rewrite;823 818 824 819 // Use displayed user ID if there is one, and one isn't requested … … 838 833 839 834 // Pretty permalinks 840 if ( $wp_rewrite->using_permalinks() ) {835 if ( bbp_use_pretty_urls() ) { 841 836 $url = trailingslashit( $profile_url ) . bbp_get_user_favorites_rewrite_id(); 842 837 $url = user_trailingslashit( $url ); … … 980 975 */ 981 976 function bbp_get_subscriptions_permalink( $user_id = 0 ) { 982 global $wp_rewrite;983 977 984 978 // Use displayed user ID if there is one, and one isn't requested … … 998 992 999 993 // Pretty permalinks 1000 if ( $wp_rewrite->using_permalinks() ) {994 if ( bbp_use_pretty_urls() ) { 1001 995 $url = trailingslashit( $profile_url ) . bbp_get_user_subscriptions_slug(); 1002 996 $url = user_trailingslashit( $url ); … … 1421 1415 */ 1422 1416 function bbp_get_user_topics_created_url( $user_id = 0 ) { 1423 global $wp_rewrite;1424 1417 1425 1418 // Use displayed user ID if there is one, and one isn't requested … … 1439 1432 1440 1433 // Pretty permalinks 1441 if ( $wp_rewrite->using_permalinks() ) {1434 if ( bbp_use_pretty_urls() ) { 1442 1435 $url = trailingslashit( $profile_url ) . bbp_get_topic_archive_slug(); 1443 1436 $url = user_trailingslashit( $url ); … … 1479 1472 */ 1480 1473 function bbp_get_user_replies_created_url( $user_id = 0 ) { 1481 global $wp_rewrite;1482 1474 1483 1475 // Use displayed user ID if there is one, and one isn't requested … … 1497 1489 1498 1490 // Pretty permalinks 1499 if ( $wp_rewrite->using_permalinks() ) {1491 if ( bbp_use_pretty_urls() ) { 1500 1492 $url = trailingslashit( $profile_url ) . bbp_get_reply_archive_slug(); 1501 1493 $url = user_trailingslashit( $url );
Note: See TracChangeset
for help on using the changeset viewer.