Changeset 3856
- Timestamp:
- 04/28/2012 10:55:53 PM (13 years ago)
- Location:
- branches/plugin
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/plugin/bbp-admin/bbp-tools.php
r3811 r3856 723 723 $statement = __( 'Removing trashed topics from user favorites… %s', 'bbpress' ); 724 724 $result = __( 'Failed!', 'bbpress' ); 725 726 $users = $wpdb->get_results( "SELECT `user_id`, `meta_value` AS `favorites` FROM `$wpdb->usermeta` WHERE `meta_key` = '_bbp_favorites';" ); 725 $key = bbp_get_favorites_key(); 726 $users = $wpdb->get_results( "SELECT `user_id`, `meta_value` AS `favorites` FROM `{$wpdb->usermeta}` WHERE `meta_key` = '{$key}';" ); 727 727 728 if ( is_wp_error( $users ) ) 728 729 return array( 1, sprintf( $statement, $result ) ); 729 730 730 $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() . "';" );731 $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() . "';" ); 731 732 732 733 if ( is_wp_error( $topics ) ) … … 743 744 744 745 $favorites = join( ',', $favorites ); 745 $values[] = "(' $user->user_id', '_bbp_favorites', '$favorites')";746 $values[] = "('{$user->user_id}', '{$key}, '{$favorites}')"; 746 747 } 747 748 … … 751 752 } 752 753 753 $sql_delete = "DELETE FROM ` $wpdb->usermeta` WHERE `meta_key` = '_bbp_favorites';";754 $sql_delete = "DELETE FROM `{$wpdb->usermeta}` WHERE `meta_key` = '{$key}';"; 754 755 if ( is_wp_error( $wpdb->query( $sql_delete ) ) ) 755 756 return array( 4, sprintf( $statement, $result ) ); … … 782 783 $statement = __( 'Removing trashed topics from user subscriptions… %s', 'bbpress' ); 783 784 $result = __( 'Failed!', 'bbpress' ); 784 785 $users = $wpdb->get_results( "SELECT `user_id`, `meta_value` AS `subscriptions` FROM `$wpdb->usermeta` WHERE `meta_key` = '_bbp_subscriptions';" ); 785 $key = bbp_get_subscriptions_key(); 786 $users = $wpdb->get_results( "SELECT `user_id`, `meta_value` AS `subscriptions` FROM `{$wpdb->usermeta}` WHERE `meta_key` = '{$key}';" ); 787 786 788 if ( is_wp_error( $users ) ) 787 789 return array( 1, sprintf( $statement, $result ) ); 788 790 789 $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() . "';" );791 $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() . "';" ); 790 792 if ( is_wp_error( $topics ) ) 791 793 return array( 2, sprintf( $statement, $result ) ); … … 801 803 802 804 $subscriptions = join( ',', $subscriptions ); 803 $values[] = "(' $user->user_id', '_bbp_subscriptions', '$subscriptions')";805 $values[] = "('{$user->user_id}', '{$key}', '{$subscriptions}')"; 804 806 } 805 807 … … 809 811 } 810 812 811 $sql_delete = "DELETE FROM ` $wpdb->usermeta` WHERE `meta_key` = '_bbp_subscriptions';";813 $sql_delete = "DELETE FROM `{$wpdb->usermeta}` WHERE `meta_key` = '{$key}';"; 812 814 if ( is_wp_error( $wpdb->query( $sql_delete ) ) ) 813 815 return array( 4, sprintf( $statement, $result ) ); … … 816 818 foreach ( $values as $chunk ) { 817 819 $chunk = "\n" . join( ",\n", $chunk ); 818 $sql_insert = "INSERT INTO ` $wpdb->usermeta` (`user_id`, `meta_key`, `meta_value`) VALUES $chunk;";820 $sql_insert = "INSERT INTO `{$wpdb->usermeta}` (`user_id`, `meta_key`, `meta_value`) VALUES $chunk;"; 819 821 if ( is_wp_error( $wpdb->query( $sql_insert ) ) ) 820 822 return array( 5, sprintf( $statement, $result ) ); -
branches/plugin/bbp-includes/bbp-user-functions.php
r3809 r3856 216 216 217 217 /** 218 * Get the meta key for favorites, based on blog prefix 219 * 220 * @since bbPress (r3856) 221 * @param int $blog_id Optional blog id to switch to 222 * @global WPDB $wpdb 223 * @return string 224 */ 225 function bbp_get_favorites_key( $blog_id = 0 ) { 226 global $wpdb; 227 228 // If blog ID is passed, switch to that blog 229 if ( !empty( $blog_id ) ) { 230 switch_to_blog( $blog_id ); 231 $prefix = $wpdb->prefix; 232 restore_current_blog(); 233 234 // Use current blog 235 } else { 236 $prefix = $wpdb->prefix; 237 } 238 239 return apply_filters( 'bbp_get_favorites_key', '_bbp_' . $prefix . 'favorites', $blog_id, $prefix ); 240 } 241 242 /** 218 243 * Get the users who have made the topic favorite 219 244 * … … 233 258 234 259 // Get the users who have favorited the topic 235 $users = $wpdb->get_col( "SELECT user_id FROM {$wpdb->usermeta} WHERE meta_key = '_bbp_favorites' and FIND_IN_SET('{$topic_id}', meta_value) > 0" ); 260 $key = bbp_get_favorites_key(); 261 $users = $wpdb->get_col( "SELECT user_id FROM {$wpdb->usermeta} WHERE meta_key = '{$key}' and FIND_IN_SET('{$topic_id}', meta_value) > 0" ); 236 262 $users = apply_filters( 'bbp_get_topic_favoriters', $users, $topic_id ); 237 263 … … 289 315 return false; 290 316 291 $favorites = (string) get_user_meta( $user_id, '_bbp_favorites', true );317 $favorites = (string) get_user_meta( $user_id, bbp_get_favorites_key(), true ); 292 318 $favorites = (array) explode( ',', $favorites ); 293 319 $favorites = array_filter( $favorites ); … … 370 396 $favorites = array_filter( $favorites ); 371 397 $favorites = (string) implode( ',', $favorites ); 372 update_user_meta( $user_id, '_bbp_favorites', $favorites );398 update_user_meta( $user_id, bbp_get_favorites_key(), $favorites ); 373 399 } 374 400 … … 407 433 if ( !empty( $favorites ) ) { 408 434 $favorites = implode( ',', $favorites ); 409 update_user_meta( $user_id, '_bbp_favorites', $favorites );435 update_user_meta( $user_id, bbp_get_favorites_key(), $favorites ); 410 436 } else { 411 delete_user_meta( $user_id, '_bbp_favorites');437 delete_user_meta( $user_id, bbp_get_favorites_key() ); 412 438 } 413 439 } … … 520 546 521 547 /** 548 * Get the meta key for subscriptions, based on blog prefix 549 * 550 * @since bbPress (r3856) 551 * @global WPDB $wpdb 552 * @return string 553 */ 554 function bbp_get_subscriptions_key( $blog_id = 0 ) { 555 global $wpdb; 556 557 // If blog ID is passed, switch to that blog 558 if ( !empty( $blog_id ) ) { 559 switch_to_blog( $blog_id ); 560 $prefix = $wpdb->prefix; 561 restore_current_blog(); 562 563 // Use current blog 564 } else { 565 $prefix = $wpdb->prefix; 566 } 567 568 return apply_filters( 'bbp_get_subscriptions_key', '_bbp_' . $prefix . 'subscriptions', $blog_id, $prefix ); 569 } 570 571 /** 522 572 * Get the users who have subscribed to the topic 523 573 * … … 534 584 global $wpdb; 535 585 586 $key = bbp_get_subscriptions_key(); 536 587 $users = wp_cache_get( 'bbp_get_topic_subscribers_' . $topic_id, 'bbpress' ); 537 588 if ( empty( $users ) ) { 538 $users = $wpdb->get_col( "SELECT user_id FROM {$wpdb->usermeta} WHERE meta_key = ' _bbp_subscriptions' and FIND_IN_SET('{$topic_id}', meta_value) > 0" );589 $users = $wpdb->get_col( "SELECT user_id FROM {$wpdb->usermeta} WHERE meta_key = '{$key}' and FIND_IN_SET('{$topic_id}', meta_value) > 0" ); 539 590 wp_cache_set( 'bbp_get_topic_subscribers_' . $topic_id, $users, 'bbpress' ); 540 591 } … … 594 645 return false; 595 646 596 $subscriptions = (string) get_user_meta( $user_id, '_bbp_subscriptions', true );647 $subscriptions = (string) get_user_meta( $user_id, bbp_get_subscriptions_key(), true ); 597 648 $subscriptions = (array) explode( ',', $subscriptions ); 598 649 $subscriptions = array_filter( $subscriptions ); … … 678 729 $subscriptions = array_filter( $subscriptions ); 679 730 $subscriptions = (string) implode( ',', $subscriptions ); 680 update_user_meta( $user_id, '_bbp_subscriptions', $subscriptions );731 update_user_meta( $user_id, bbp_get_subscriptions_key(), $subscriptions ); 681 732 682 733 wp_cache_delete( 'bbp_get_topic_subscribers_' . $topic_id, 'bbpress' ); … … 719 770 if ( !empty( $subscriptions ) ) { 720 771 $subscriptions = implode( ',', $subscriptions ); 721 update_user_meta( $user_id, '_bbp_subscriptions', $subscriptions );772 update_user_meta( $user_id, bbp_get_subscriptions_key(), $subscriptions ); 722 773 } else { 723 delete_user_meta( $user_id, '_bbp_subscriptions');774 delete_user_meta( $user_id, bbp_get_subscriptions_key() ); 724 775 } 725 776
Note: See TracChangeset
for help on using the changeset viewer.