BP_Akismet::check_activity( BP_Activity_Activity $activity )

Check if the activity item is spam or ham.


Description Description

See also See also


Top ↑

Parameters Parameters

$activity

(Required) The activity item to check.


Top ↑

Source Source

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

	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 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 );
	}

Top ↑

Changelog Changelog

Changelog
Version Description
1.6.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.