Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
11/29/2011 08:45:28 PM (13 years ago)
Author:
djpaul
Message:

When marking a user as not a spammer, mark all their activity as not spam, too.
Also removes legacy behaviour of changing activities' hide_sitewide when marking a user as a spammer.
See #3660.

File:
1 edited

Legend:

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

    r5368 r5410  
    661661
    662662    // Do not delete user data unless a logged in user says so
    663     if ( empty( $user_id ) || !is_user_logged_in() )
     663    if ( empty( $user_id ) || ! is_user_logged_in() )
    664664        return false;
    665665
     
    699699}
    700700add_action( 'bp_make_spam_user', 'bp_activity_spam_all_user_data' );
     701
     702/**
     703 * Mark all of the user's activity as ham (not spam)
     704 *
     705 * @global object $wpdb
     706 * @global object $bp BuddyPress global settings
     707 * @param int $user_id
     708 * @since 1.6
     709 */
     710function bp_activity_ham_all_user_data( $user_id = 0 ) {
     711    global $bp, $wpdb;
     712
     713    // Do not delete user data unless a logged in user says so
     714    if ( empty( $user_id ) || ! is_user_logged_in() )
     715        return false;
     716
     717    // Get all the user's activities.
     718    $activities = bp_activity_get( array( 'display_comments' => 'stream', 'filter' => array( 'user_id' => $user_id ), 'show_hidden' => true, 'spam' => 'all', ) );
     719
     720    // Mark each as not spam
     721    foreach ( (array) $activities['activities'] as $activity ) {
     722
     723        // Create an activity object
     724        $activity_obj = new BP_Activity_Activity;
     725        foreach ( $activity as $k => $v )
     726            $activity_obj->$k = $v;
     727
     728        // Mark as not spam
     729        bp_activity_mark_as_ham( $activity_obj );
     730
     731        /*
     732         * If Akismet is present, update the activity history meta.
     733         *
     734         * This is usually taken care of when BP_Activity_Activity::save() happens, but
     735         * as we're going to be updating all the activity statuses directly, for efficency,
     736         * we need to update manually.
     737         */
     738        if ( ! empty( $bp->activity->akismet ) )
     739            $bp->activity->akismet->update_activity_ham_meta( $activity_obj );
     740
     741        // Tidy up
     742        unset( $activity_obj );
     743    }
     744
     745    // Mark all of this user's activities as spam
     746    $wpdb->query( $wpdb->prepare( "UPDATE {$bp->activity->table_name} SET is_spam = 0 WHERE user_id = %d", $user_id ) );
     747
     748    // Call an action for plugins to use
     749    do_action( 'bp_activity_ham_all_user_data', $user_id, $activities['activities'] );
     750}
     751add_action( 'bp_make_ham_user', 'bp_activity_ham_all_user_data' );
    701752
    702753/**
Note: See TracChangeset for help on using the changeset viewer.