BP_Akismet::send_akismet_request( array $activity_data, string $check = 'check', string $spam = 'spam' )
Contact Akismet to check if this is spam or ham.
Description
Props to WordPress core Akismet plugin for a lot of this.
Parameters
- $activity_data
-
(Required) Packet of information to submit to Akismet.
- $check
-
(Optional) "check" or "submit".
Default value: 'check'
- $spam
-
(Optional) "spam" or "ham".
Default value: 'spam'
Return
(array) $activity_data Activity data, with Akismet data added.
Source
File: bp-activity/classes/class-bp-akismet.php
public function send_akismet_request( $activity_data, $check = 'check', $spam = 'spam' ) { $query_string = $path = ''; $activity_data['blog'] = bp_get_option( 'home' ); $activity_data['blog_charset'] = bp_get_option( 'blog_charset' ); $activity_data['blog_lang'] = get_locale(); $activity_data['referrer'] = $_SERVER['HTTP_REFERER']; $activity_data['user_agent'] = bp_core_current_user_ua(); $activity_data['user_ip'] = bp_core_current_user_ip(); if ( Akismet::is_test_mode() ) $activity_data['is_test'] = 'true'; // Loop through _POST args and rekey strings. foreach ( $_POST as $key => $value ) if ( is_string( $value ) && 'cookie' != $key ) $activity_data['POST_' . $key] = $value; // Keys to ignore. $ignore = array( 'HTTP_COOKIE', 'HTTP_COOKIE2', 'PHP_AUTH_PW' ); // Loop through _SERVER args and remove whitelisted keys. foreach ( $_SERVER as $key => $value ) { // Key should not be ignored. if ( !in_array( $key, $ignore ) && is_string( $value ) ) { $activity_data[$key] = $value; // Key should be ignored. } else { $activity_data[$key] = ''; } } foreach ( $activity_data as $key => $data ) $query_string .= $key . '=' . urlencode( stripslashes( $data ) ) . '&'; if ( 'check' == $check ) $path = 'comment-check'; elseif ( 'submit' == $check ) $path = 'submit-' . $spam; // Send to Akismet. add_filter( 'akismet_ua', array( $this, 'buddypress_ua' ) ); $response = Akismet::http_post( $query_string, $path ); remove_filter( 'akismet_ua', array( $this, 'buddypress_ua' ) ); // Save response data. $activity_data['bp_as_result'] = $response[1]; if ( isset( $response[0]['x-akismet-pro-tip'] ) ) { $activity_data['akismet_pro_tip'] = $response[0]['x-akismet-pro-tip']; } // Perform a daily tidy up. if ( ! wp_next_scheduled( 'bp_activity_akismet_delete_old_metadata' ) ) wp_schedule_event( time(), 'daily', 'bp_activity_akismet_delete_old_metadata' ); return $activity_data; }
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.