Changeset 5803 for trunk/bp-members/bp-members-functions.php
- Timestamp:
- 02/17/2012 05:30:04 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/bp-members/bp-members-functions.php
r5796 r5803 485 485 return apply_filters( 'bp_core_get_total_member_count', $count ); 486 486 } 487 488 /** 489 * Processes a spammed or unspammed user 490 * 491 * This function is called in two ways: 492 * - in bp_core_action_set_spammer_status() (when spamming from the front-end) 493 * - by bp_core_mark_user_spam_admin() or bp_core_mark_user_ham_admin() (when spamming from the 494 * Dashboard) 495 * 496 * @since 1.6 497 * 498 * @param int $user_id The user being spammed/hammed 499 * @param string $status 'spam' if being marked as spam, 'ham' otherwise 500 */ 501 function bp_core_process_spammer_status( $user_id, $status ) { 502 global $wpdb; 503 504 // Only super admins can currently spam users 505 if ( !is_super_admin() || bp_is_my_profile() ) 506 return; 507 508 // Bail if no user ID 509 if ( empty( $user_id ) ) 510 return; 511 512 // Bail if user ID is super admin 513 if ( is_super_admin( $user_id ) ) 514 return; 515 516 // Get the functions file 517 if ( is_multisite() ) { 518 require_once( ABSPATH . 'wp-admin/includes/ms.php' ); 519 } 520 521 $is_spam = 'spam' == $status; 522 523 // Only you can prevent infinite loops 524 remove_action( 'make_spam_user', 'bp_core_mark_user_spam_admin' ); 525 remove_action( 'make_ham_user', 'bp_core_mark_user_ham_admin' ); 526 527 // When marking as spam in the Dashboard, these actions are handled by WordPress 528 if ( !is_admin() ) { 529 // Get the blogs for the user 530 $blogs = get_blogs_of_user( $user_id, true ); 531 532 foreach ( (array) $blogs as $key => $details ) { 533 534 // Do not mark the main or current root blog as spam 535 if ( 1 == $details->userblog_id || bp_get_root_blog_id() == $details->userblog_id ) { 536 continue; 537 } 538 539 // Update the blog status 540 update_blog_status( $details->userblog_id, 'spam', $is_spam ); 541 } 542 543 // Finally, mark this user as a spammer 544 if ( is_multisite() ) { 545 update_user_status( $user_id, 'spam', $is_spam ); 546 } 547 548 // Always set single site status 549 $wpdb->update( $wpdb->users, array( 'user_status' => $is_spam ), array( 'ID' => $user_id ) ); 550 551 // Call multisite actions in single site mode for good measure 552 if ( !is_multisite() ) { 553 $wp_action = $is_spam ? 'make_spam_user' : 'make_ham_user'; 554 do_action( $wp_action, bp_displayed_user_id() ); 555 } 556 } 557 558 // Hide this user's activity 559 if ( $is_spam && bp_is_active( 'activity' ) ) { 560 bp_activity_hide_user_activity( $user_id ); 561 } 562 563 // We need a special hook for is_spam so that components can delete data at spam time 564 $bp_action = $is_spam ? 'bp_make_spam_user' : 'bp_make_ham_user'; 565 do_action( $bp_action, $user_id ); 566 567 // Allow plugins to do neat things 568 do_action( 'bp_core_process_spammer_status', $user_id, $is_spam ); 569 570 return true; 571 } 572 573 /** 574 * Hook to WP's make_spam_user and run our custom BP spam functions 575 * 576 * @since 1.6 577 * 578 * @param int $user_id The user id passed from the make_spam_user hook 579 */ 580 function bp_core_mark_user_spam_admin( $user_id ) { 581 bp_core_process_spammer_status( $user_id, 'spam' ); 582 } 583 add_action( 'make_spam_user', 'bp_core_mark_user_spam_admin' ); 584 585 /** 586 * Hook to WP's make_ham_user and run our custom BP spam functions 587 * 588 * @since 1.6 589 * 590 * @param int $user_id The user id passed from the make_ham_user hook 591 */ 592 function bp_core_mark_user_ham_admin( $user_id ) { 593 bp_core_process_spammer_status( $user_id, 'ham' ); 594 } 595 add_action( 'make_ham_user', 'bp_core_mark_user_ham_admin' ); 487 596 488 597 /**
Note: See TracChangeset
for help on using the changeset viewer.