Changeset 3856 for branches/plugin/bbp-includes/bbp-user-functions.php
- Timestamp:
- 04/28/2012 10:55:53 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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.