Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
02/17/2012 05:30:04 PM (12 years ago)
Author:
boonebgorges
Message:

Splits mark-as-spam/ham functions into action function and business function.
Introduces new functions to hook to WP core make_spam_user/make_ham_user hooks, so that BP spamming events are triggered from the Network Dashboard.
Fixes #3787

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-members/bp-members-actions.php

    r5751 r5803  
    2525 */
    2626function bp_core_action_set_spammer_status( $user_id = 0 ) {
    27     global $wpdb;
    28 
    29     // Only super admins can currently spam users
    30     if ( !bp_current_user_can( 'bp_moderate' ) || bp_is_my_profile() )
    31         return;
    3227
    3328    // Use displayed user if it's not yourself
    34     if ( empty( $user_id ) && bp_is_user() )
     29    if ( empty( $user_id ) )
    3530        $user_id = bp_displayed_user_id();
    36 
    37     // Bail if no user ID
    38     if ( empty( $user_id ) )
    39         return;
    40 
    41     // Bail if user ID is super admin
    42     if ( is_super_admin( $user_id ) )
    43         return;
    4431
    4532    if ( bp_is_current_component( 'admin' ) && ( in_array( bp_current_action(), array( 'mark-spammer', 'unmark-spammer' ) ) ) ) {
     
    4835        check_admin_referer( 'mark-unmark-spammer' );
    4936
    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';
    5439
    55         // To spam or not to spam
    56         $is_spam = bp_is_current_action( 'mark-spammer' ) ? 1 : 0;
     40        // The heavy lifting
     41        bp_core_process_spammer_status( $user_id, $status );
    5742
    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 ) {
    8245            bp_core_add_message( __( 'User marked as spammer. Spam users are visible only to site admins.', 'buddypress' ) );
    8346        } else {
     
    8548        }
    8649
    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;
    9852        do_action( 'bp_core_action_set_spammer_status', bp_displayed_user_id(), $is_spam );
    9953
Note: See TracChangeset for help on using the changeset viewer.