BP_Akismet::check_activity( BP_Activity_Activity $activity )

Check if the activity item is spam or ham.

Description

See also

Parameters

$activity

(Required) The activity item to check.

Source

File: bp-activity/classes/class-bp-akismet.php

390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
public function check_activity( $activity ) {
    // By default, only handle activity updates and activity comments.
    if ( !in_array( $activity->type, BP_Akismet::get_activity_types() ) )
        return;
 
    // Make sure last_activity is clear to avoid any confusion.
    $this->last_activity = null;
 
    // Build data package for Akismet.
    $activity_data = BP_Akismet::build_akismet_data_package( $activity );
 
    // Check with Akismet to see if this is spam.
    $activity_data = $this->send_akismet_request( $activity_data, 'check', 'spam' );
 
    // Record this item.
    $this->last_activity = $activity;
 
    // Store a copy of the data that was submitted to Akismet.
    $this->last_activity->akismet_submission = $activity_data;
 
    // Spam.
    if ( 'true' == $activity_data['bp_as_result'] ) {
        /**
         * Fires after an activity item has been proven to be spam, but before officially being marked as spam.
         *
         * @since BuddyPress 1.6.0
         *
         * @param BP_Activity_Activity $activity      The activity item proven to be spam.
         * @param array                $activity_data Array of activity data for item including
         *                                            Akismet check results data.
         */
        do_action_ref_array( 'bp_activity_akismet_spam_caught', array( &$activity, $activity_data ) );
 
        // Mark as spam.
        bp_activity_mark_as_spam( $activity, 'by_akismet' );
 
        if (
            Akismet::allow_discard() &&
            ! empty( $activity_data['akismet_pro_tip'] ) &&
            'discard' === $activity_data['akismet_pro_tip']
        ) {
            // If this is so spammy it's not worth your time, let's just delete it.
            if ( $activity->type === 'activity_comment' ) {
                bp_activity_delete_comment( $activity->item_id, $activity->id );
            } else {
                bp_activity_delete( array( 'id' => $activity->id ) );
            }
        }
    }
 
    // Update activity meta after a spam check.
    add_action( 'bp_activity_after_save', array( $this, 'update_activity_akismet_meta' ), 1, 1 );
}

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.