BBP_Akismet::check_post( string $post_data )
Converts topic/reply data into Akismet comment checking format
Description
Parameters
- $post_data
-
(Required)
Return
(array) Array of post data
Source
File: bp-forums/extend/akismet.php
public function check_post( $post_data ) { // Define local variables $user_data = array(); $post_permalink = ''; // Post is not published if ( bbp_get_public_status_id() !== $post_data['post_status'] ) return $post_data; // Cast the post_author to 0 if it's empty if ( empty( $post_data['post_author'] ) ) $post_data['post_author'] = 0; /** Author ************************************************************/ // Get user data $userdata = get_userdata( $post_data['post_author'] ); $anonymous_data = bbp_filter_anonymous_post_data(); // Author is anonymous if ( !empty( $anonymous_data ) ) { $user_data['name'] = $anonymous_data['bbp_anonymous_name']; $user_data['email'] = $anonymous_data['bbp_anonymous_email']; $user_data['website'] = $anonymous_data['bbp_anonymous_website']; // Author is logged in } elseif ( !empty( $userdata ) ) { $user_data['name'] = $userdata->display_name; $user_data['email'] = $userdata->user_email; $user_data['website'] = $userdata->user_url; // Missing author data, so set some empty strings } else { $user_data['name'] = ''; $user_data['email'] = ''; $user_data['website'] = ''; } /** Post **************************************************************/ // Use post parent for permalink if ( !empty( $post_data['post_parent'] ) ) $post_permalink = get_permalink( $post_data['post_parent'] ); // Put post_data back into usable array $_post = array( 'comment_author' => $user_data['name'], 'comment_author_email' => $user_data['email'], 'comment_author_url' => $user_data['website'], 'comment_content' => $post_data['post_content'], 'comment_post_ID' => $post_data['post_parent'], 'comment_type' => $post_data['post_type'], 'permalink' => $post_permalink, 'referrer' => $_SERVER['HTTP_REFERER'], 'user_agent' => $_SERVER['HTTP_USER_AGENT'], 'user_ID' => $post_data['post_author'], 'user_ip' => bbp_current_author_ip(), 'user_role' => $this->get_user_roles( $post_data['post_author'] ), ); // Check the post_data $_post = $this->maybe_spam( $_post ); // Get the result $post_data['bbp_akismet_result'] = $_post['bbp_akismet_result']; unset( $_post['bbp_akismet_result'] ); // Store the data as submitted $post_data['bbp_post_as_submitted'] = $_post; // Allow post_data to be manipulated do_action_ref_array( 'bbp_akismet_check_post', $post_data ); // Spam if ( 'true' === $post_data['bbp_akismet_result'] ) { // Let plugins do their thing do_action( 'bbp_akismet_spam_caught' ); // This is spam $post_data['post_status'] = bbp_get_spam_status_id(); // We don't want your spam tags here add_filter( 'bbp_new_reply_pre_set_terms', array( $this, 'filter_post_terms' ), 1, 3 ); // @todo Spam counter? } // @todo Topic/reply moderation? No true/false response - 'pending' or 'draft' // @todo Auto-delete old spam? // Log the last post $this->last_post = $post_data; // Pass the data back to the filter return $post_data; }
Changelog
Version | Description |
---|---|
bbPress (r3277) | 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.