bp_activity_mark_as_spam( BP_Activity_Activity $activity, string $source = 'by_a_person' )

Mark an activity item as spam.

Description

Parameters

$activity

(Required) The activity item to be spammed.

$source

(Optional) Default is "by_a_person" (ie, a person has manually marked the activity as spam). BP core also accepts 'by_akismet'.

Default value: 'by_a_person'

Source

File: bp-activity/bp-activity-functions.php

3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
function bp_activity_mark_as_spam( &$activity, $source = 'by_a_person' ) {
    $bp = buddypress();
 
    $activity->is_spam = 1;
 
    // Clear the activity feed first page cache.
    wp_cache_delete( 'bp_activity_sitewide_front', 'bp' );
 
    // Clear the activity comment cache for this activity item.
    wp_cache_delete( $activity->id, 'bp_activity_comments' );
 
    // If Akismet is active, and this was a manual spam/ham request, stop Akismet checking the activity.
    if ( 'by_a_person' == $source && !empty( $bp->activity->akismet ) ) {
        remove_action( 'bp_activity_before_save', array( $bp->activity->akismet, 'check_activity' ), 4 );
 
        // Build data package for Akismet.
        $activity_data = BP_Akismet::build_akismet_data_package( $activity );
 
        // Tell Akismet this is spam.
        $activity_data = $bp->activity->akismet->send_akismet_request( $activity_data, 'submit', 'spam' );
 
        // Update meta.
        add_action( 'bp_activity_after_save', array( $bp->activity->akismet, 'update_activity_spam_meta' ), 1, 1 );
    }
 
    /**
     * Fires at the end of the process to mark an activity item as spam.
     *
     * @since BuddyPress 1.6.0
     *
     * @param BP_Activity_Activity $activity Activity item being marked as spam.
     * @param string               $source   Source of determination of spam status. For example
     *                                       "by_a_person" or "by_akismet".
     */
    do_action( 'bp_activity_mark_as_spam', $activity, $source );
}

Changelog

Changelog
Version Description
BuddyPress 1.6.0 Introduced.

Questions?

We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.