Changeset 5805
- Timestamp:
- 02/17/2012 09:53:04 PM (13 years ago)
- Location:
- branches/1.5/bp-members
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/1.5/bp-members/bp-members-actions.php
r4961 r5805 12 12 13 13 /** 14 * Listens to the $bp component and action variables to determine if the user is viewing the members15 * directory page. If they are, it will set up the directory and load the members directory template.16 *17 * @package BuddyPress Core18 * @global object $bp Global BuddyPress settings object19 * @uses wp_enqueue_script() Loads a JS script into the header of the page.20 * @uses bp_core_load_template() Loads a specific template file.21 */22 /**23 14 * When a site admin selects "Mark as Spammer/Not Spammer" from the admin menu 24 15 * this action will fire and mark or unmark the user and their blogs as spam. … … 30 21 */ 31 22 function bp_core_action_set_spammer_status( $user_id = 0 ) { 32 global $wpdb;33 34 // Only super admins can currently spam users35 if ( !is_super_admin() || bp_is_my_profile() )36 return;37 23 38 24 // Use displayed user if it's not yourself 39 if ( empty( $user_id ) && bp_is_user())25 if ( empty( $user_id ) ) 40 26 $user_id = bp_displayed_user_id(); 41 42 // Bail if no user ID43 if ( empty( $user_id ) )44 return;45 46 // Bail if user ID is super admin47 if ( is_super_admin( $user_id ) )48 return;49 27 50 28 if ( bp_is_current_component( 'admin' ) && ( in_array( bp_current_action(), array( 'mark-spammer', 'unmark-spammer' ) ) ) ) { … … 53 31 check_admin_referer( 'mark-unmark-spammer' ); 54 32 55 // Get the functions file 56 if ( is_multisite() ) { 57 require( ABSPATH . 'wp-admin/includes/ms.php' ); 58 } 33 // To spam or not to spam 34 $status = bp_is_current_action( 'mark-spammer' ) ? 'spam' : 'ham'; 59 35 60 // T o spam or not to spam61 $is_spam = bp_is_current_action( 'mark-spammer' ) ? 1 : 0;36 // The heavy lifting 37 bp_core_process_spammer_status( $user_id, $status ); 62 38 63 // Get the blogs for the user 64 $blogs = get_blogs_of_user( $user_id, true ); 65 66 foreach ( (array) $blogs as $key => $details ) { 67 68 // Do not mark the main or current root blog as spam 69 if ( 1 == $details->userblog_id || bp_get_root_blog_id() == $details->userblog_id ) { 70 continue; 71 } 72 73 // Update the blog status 74 update_blog_status( $details->userblog_id, 'spam', $is_spam ); 75 } 76 77 // Finally, mark this user as a spammer 78 if ( is_multisite() ) { 79 update_user_status( $user_id, 'spam', $is_spam ); 80 } 81 82 // Always set single site status 83 $wpdb->update( $wpdb->users, array( 'user_status' => $is_spam ), array( 'ID' => $user_id ) ); 84 85 // Add feedback message 86 if ( $is_spam ) { 39 // Add feedback message. @todo - Error reporting 40 if ( 'spam' == $status ) { 87 41 bp_core_add_message( __( 'User marked as spammer. Spam users are visible only to site admins.', 'buddypress' ) ); 88 42 } else { … … 90 44 } 91 45 92 // Hide this user's activity 93 if ( $is_spam && bp_is_active( 'activity' ) ) { 94 bp_activity_hide_user_activity( $user_id ); 95 } 96 97 // We need a special hook for is_spam so that components can delete data at spam time 98 $bp_action = $is_spam ? 'bp_make_spam_user' : 'bp_make_ham_user'; 99 do_action( $bp_action, bp_displayed_user_id() ); 100 101 // Call multisite actions in single site mode for good measure 102 if ( !is_multisite() ) { 103 $wp_action = $is_spam ? 'make_spam_user' : 'make_ham_user'; 104 do_action( $wp_action, bp_displayed_user_id() ); 105 } 106 107 // Allow plugins to do neat things 46 // Deprecated. Use bp_core_process_spammer_status. 47 $is_spam = 'spam' == $status; 108 48 do_action( 'bp_core_action_set_spammer_status', bp_displayed_user_id(), $is_spam ); 109 49 -
branches/1.5/bp-members/bp-members-functions.php
r5778 r5805 488 488 489 489 /** 490 * Processes a spammed or unspammed user 491 * 492 * This function is called in two ways: 493 * - in bp_core_action_set_spammer_status() (when spamming from the front-end) 494 * - by bp_core_mark_user_spam_admin() or bp_core_mark_user_ham_admin() (when spamming from the 495 * Dashboard) 496 * 497 * @since 1.5.5 498 * 499 * @param int $user_id The user being spammed/hammed 500 * @param string $status 'spam' if being marked as spam, 'ham' otherwise 501 */ 502 function bp_core_process_spammer_status( $user_id, $status ) { 503 global $wpdb; 504 505 // Only super admins can currently spam users 506 if ( !is_super_admin() || bp_is_my_profile() ) 507 return; 508 509 // Bail if no user ID 510 if ( empty( $user_id ) ) 511 return; 512 513 // Bail if user ID is super admin 514 if ( is_super_admin( $user_id ) ) 515 return; 516 517 // Get the functions file 518 if ( is_multisite() ) { 519 require_once( ABSPATH . 'wp-admin/includes/ms.php' ); 520 } 521 522 $is_spam = 'spam' == $status; 523 524 // Only you can prevent infinite loops 525 remove_action( 'make_spam_user', 'bp_core_mark_user_spam_admin' ); 526 remove_action( 'make_ham_user', 'bp_core_mark_user_ham_admin' ); 527 528 // When marking as spam in the Dashboard, these actions are handled by WordPress 529 if ( !is_admin() ) { 530 // Get the blogs for the user 531 $blogs = get_blogs_of_user( $user_id, true ); 532 533 foreach ( (array) $blogs as $key => $details ) { 534 535 // Do not mark the main or current root blog as spam 536 if ( 1 == $details->userblog_id || bp_get_root_blog_id() == $details->userblog_id ) { 537 continue; 538 } 539 540 // Update the blog status 541 update_blog_status( $details->userblog_id, 'spam', $is_spam ); 542 } 543 544 // Finally, mark this user as a spammer 545 if ( is_multisite() ) { 546 update_user_status( $user_id, 'spam', $is_spam ); 547 } 548 549 // Always set single site status 550 $wpdb->update( $wpdb->users, array( 'user_status' => $is_spam ), array( 'ID' => $user_id ) ); 551 552 // Call multisite actions in single site mode for good measure 553 if ( !is_multisite() ) { 554 $wp_action = $is_spam ? 'make_spam_user' : 'make_ham_user'; 555 do_action( $wp_action, bp_displayed_user_id() ); 556 } 557 } 558 559 // Hide this user's activity 560 if ( $is_spam && bp_is_active( 'activity' ) ) { 561 bp_activity_hide_user_activity( $user_id ); 562 } 563 564 // We need a special hook for is_spam so that components can delete data at spam time 565 $bp_action = $is_spam ? 'bp_make_spam_user' : 'bp_make_ham_user'; 566 do_action( $bp_action, $user_id ); 567 568 // Allow plugins to do neat things 569 do_action( 'bp_core_process_spammer_status', $user_id, $is_spam ); 570 571 return true; 572 } 573 574 /** 575 * Hook to WP's make_spam_user and run our custom BP spam functions 576 * 577 * @since 1.5.5 578 * 579 * @param int $user_id The user id passed from the make_spam_user hook 580 */ 581 function bp_core_mark_user_spam_admin( $user_id ) { 582 bp_core_process_spammer_status( $user_id, 'spam' ); 583 } 584 add_action( 'make_spam_user', 'bp_core_mark_user_spam_admin' ); 585 586 /** 587 * Hook to WP's make_ham_user and run our custom BP spam functions 588 * 589 * @since 1.5.5 590 * 591 * @param int $user_id The user id passed from the make_ham_user hook 592 */ 593 function bp_core_mark_user_ham_admin( $user_id ) { 594 bp_core_process_spammer_status( $user_id, 'ham' ); 595 } 596 add_action( 'make_ham_user', 'bp_core_mark_user_ham_admin' ); 597 598 /** 490 599 * Checks if the user has been marked as a spammer. 491 600 *
Note: See TracChangeset
for help on using the changeset viewer.