Skip to:
Content

BuddyPress.org

Changeset 5368


Ignore:
Timestamp:
11/24/2011 07:33:49 PM (10 years ago)
Author:
djpaul
Message:

When marking a user as a spammer, flag all of their activity items as spam instead of deleting them. See #3660

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-activity/bp-activity-functions.php

    r5351 r5368  
    648648add_action( 'wpmu_delete_user',  'bp_activity_remove_all_user_data' );
    649649add_action( 'delete_user',       'bp_activity_remove_all_user_data' );
    650 add_action( 'bp_make_spam_user', 'bp_activity_remove_all_user_data' );
     650
     651/**
     652 * Mark all of the user's activity as spam
     653 *
     654 * @global object $wpdb
     655 * @global object $bp BuddyPress global settings
     656 * @param int $user_id
     657 * @since 1.6
     658 */
     659function bp_activity_spam_all_user_data( $user_id = 0 ) {
     660    global $bp, $wpdb;
     661
     662    // Do not delete user data unless a logged in user says so
     663    if ( empty( $user_id ) || !is_user_logged_in() )
     664        return false;
     665
     666    // Get all the user's activities.
     667    $activities = bp_activity_get( array( 'display_comments' => 'stream', 'filter' => array( 'user_id' => $user_id ), 'show_hidden' => true, ) );
     668
     669    // Mark each as spam
     670    foreach ( (array) $activities['activities'] as $activity ) {
     671
     672        // Create an activity object
     673        $activity_obj = new BP_Activity_Activity;
     674        foreach ( $activity as $k => $v )
     675            $activity_obj->$k = $v;
     676
     677        // Mark as spam
     678        bp_activity_mark_as_spam( $activity_obj );
     679
     680        /*
     681         * If Akismet is present, update the activity history meta.
     682         *
     683         * This is usually taken care of when BP_Activity_Activity::save() happens, but
     684         * as we're going to be updating all the activity statuses directly, for efficency,
     685         * we need to update manually.
     686         */
     687        if ( ! empty( $bp->activity->akismet ) )
     688            $bp->activity->akismet->update_activity_spam_meta( $activity_obj );
     689
     690        // Tidy up
     691        unset( $activity_obj );
     692    }
     693
     694    // Mark all of this user's activities as spam
     695    $wpdb->query( $wpdb->prepare( "UPDATE {$bp->activity->table_name} SET is_spam = 1 WHERE user_id = %d", $user_id ) );
     696
     697    // Call an action for plugins to use
     698    do_action( 'bp_activity_spam_all_user_data', $user_id, $activities['activities'] );
     699}
     700add_action( 'bp_make_spam_user', 'bp_activity_spam_all_user_data' );
    651701
    652702/**
Note: See TracChangeset for help on using the changeset viewer.