Changeset 5803
- Timestamp:
- 02/17/2012 05:30:04 PM (13 years ago)
- Location:
- trunk/bp-members
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/bp-members/bp-members-actions.php
r5751 r5803 25 25 */ 26 26 function bp_core_action_set_spammer_status( $user_id = 0 ) { 27 global $wpdb;28 29 // Only super admins can currently spam users30 if ( !bp_current_user_can( 'bp_moderate' ) || bp_is_my_profile() )31 return;32 27 33 28 // Use displayed user if it's not yourself 34 if ( empty( $user_id ) && bp_is_user())29 if ( empty( $user_id ) ) 35 30 $user_id = bp_displayed_user_id(); 36 37 // Bail if no user ID38 if ( empty( $user_id ) )39 return;40 41 // Bail if user ID is super admin42 if ( is_super_admin( $user_id ) )43 return;44 31 45 32 if ( bp_is_current_component( 'admin' ) && ( in_array( bp_current_action(), array( 'mark-spammer', 'unmark-spammer' ) ) ) ) { … … 48 35 check_admin_referer( 'mark-unmark-spammer' ); 49 36 50 // Get the functions file 51 if ( is_multisite() ) { 52 require( ABSPATH . 'wp-admin/includes/ms.php' ); 53 } 37 // To spam or not to spam 38 $status = bp_is_current_action( 'mark-spammer' ) ? 'spam' : 'ham'; 54 39 55 // T o spam or not to spam56 $is_spam = bp_is_current_action( 'mark-spammer' ) ? 1 : 0;40 // The heavy lifting 41 bp_core_process_spammer_status( $user_id, $status ); 57 42 58 // Get the blogs for the user 59 $blogs = get_blogs_of_user( $user_id, true ); 60 61 foreach ( (array) $blogs as $key => $details ) { 62 63 // Do not mark the main or current root blog as spam 64 if ( 1 == $details->userblog_id || bp_get_root_blog_id() == $details->userblog_id ) { 65 continue; 66 } 67 68 // Update the blog status 69 update_blog_status( $details->userblog_id, 'spam', $is_spam ); 70 } 71 72 // Finally, mark this user as a spammer 73 if ( is_multisite() ) { 74 update_user_status( $user_id, 'spam', $is_spam ); 75 } 76 77 // Always set single site status 78 $wpdb->update( $wpdb->users, array( 'user_status' => $is_spam ), array( 'ID' => $user_id ) ); 79 80 // Add feedback message 81 if ( $is_spam ) { 43 // Add feedback message. @todo - Error reporting 44 if ( 'spam' == $status ) { 82 45 bp_core_add_message( __( 'User marked as spammer. Spam users are visible only to site admins.', 'buddypress' ) ); 83 46 } else { … … 85 48 } 86 49 87 // We need a special hook for is_spam so that components can delete data at spam time 88 $bp_action = $is_spam ? 'bp_make_spam_user' : 'bp_make_ham_user'; 89 do_action( $bp_action, bp_displayed_user_id() ); 90 91 // Call multisite actions in single site mode for good measure 92 if ( !is_multisite() ) { 93 $wp_action = $is_spam ? 'make_spam_user' : 'make_ham_user'; 94 do_action( $wp_action, bp_displayed_user_id() ); 95 } 96 97 // Allow plugins to do neat things 50 // Deprecated. Use bp_core_process_spammer_status. 51 $is_spam = 'spam' == $status; 98 52 do_action( 'bp_core_action_set_spammer_status', bp_displayed_user_id(), $is_spam ); 99 53 -
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.