BBP_Akismet::submit_post( int $post_id )
Submit a post for spamming or hamming
Description
Parameters
- $post_id
-
(Required)
Return
(array) Array of existing topic terms
Source
File: bp-forums/extend/akismet.php
public function submit_post( $post_id = 0 ) {
global $current_user, $current_site;
// Innocent until proven guilty
$request_type = 'ham';
$current_filter = current_filter();
// Check this filter and adjust the $request_type accordingly
switch ( $current_filter ) {
// Mysterious, and straight from the can
case 'bbp_spammed_topic' :
case 'bbp_spammed_reply' :
$request_type = 'spam';
break;
// Honey-glazed, a straight off the bone
case 'bbp_unspammed_topic' :
case 'bbp_unspammed_reply' :
$request_type = 'ham';
break;
// Possibly poison...
default :
return;
}
// Setup some variables
$post_id = (int) $post_id;
// Make sure we have a post
$_post = get_post( $post_id );
// Bail if get_post() fails
if ( empty( $_post ) )
return;
// Bail if we're spamming, but the post_status isn't spam
if ( ( 'spam' === $request_type ) && ( bbp_get_spam_status_id() !== $_post->post_status ) )
return;
// Set some default post_data
$post_data = array(
'comment_approved' => $_post->post_status,
'comment_author' => $_post->post_author ? get_the_author_meta( 'display_name', $_post->post_author ) : get_post_meta( $post_id, '_bbp_anonymous_name', true ),
'comment_author_email' => $_post->post_author ? get_the_author_meta( 'email', $_post->post_author ) : get_post_meta( $post_id, '_bbp_anonymous_email', true ),
'comment_author_url' => $_post->post_author ? bbp_get_user_profile_url( $_post->post_author ) : get_post_meta( $post_id, '_bbp_anonymous_website', true ),
'comment_content' => $_post->post_content,
'comment_date' => $_post->post_date,
'comment_ID' => $post_id,
'comment_post_ID' => $_post->post_parent,
'comment_type' => $_post->post_type,
'permalink' => get_permalink( $post_id ),
'user_ID' => $_post->post_author,
'user_ip' => get_post_meta( $post_id, '_bbp_author_ip', true ),
'user_role' => $this->get_user_roles( $_post->post_author ),
);
// Use the original version stored in post_meta if available
$as_submitted = get_post_meta( $post_id, '_bbp_akismet_as_submitted', true );
if ( $as_submitted && is_array( $as_submitted ) && isset( $as_submitted['comment_content'] ) )
$post_data = array_merge( $post_data, $as_submitted );
// Add the reporter IP address
$post_data['reporter_ip'] = bbp_current_author_ip();
// Add some reporter info
if ( is_object( $current_user ) )
$post_data['reporter'] = $current_user->user_login;
// Add the current site domain
if ( is_object( $current_site ) )
$post_data['site_domain'] = $current_site->domain;
// Place your slide beneath the microscope
$post_data = $this->maybe_spam( $post_data, 'submit', $request_type );
// Manual user action
if ( isset( $post_data['reporter'] ) ) {
// What kind of action
switch ( $request_type ) {
// Spammy
case 'spam' :
$this->update_post_history( $post_id, sprintf( esc_html__( '%1$s reported this %2$s as spam', 'buddyboss' ), $post_data['reporter'], $post_data['comment_type'] ), 'report-spam' );
update_post_meta( $post_id, '_bbp_akismet_user_result', 'true' );
update_post_meta( $post_id, '_bbp_akismet_user', $post_data['reporter'] );
break;
// Hammy
case 'ham' :
$this->update_post_history( $post_id, sprintf( esc_html__( '%1$s reported this %2$s as not spam', 'buddyboss' ), $post_data['reporter'], $post_data['comment_type'] ), 'report-ham' );
update_post_meta( $post_id, '_bbp_akismet_user_result', 'false' );
update_post_meta( $post_id, '_bbp_akismet_user', $post_data['reporter'] );
// @todo Topic term revision history
break;
// Possible other actions
default :
break;
}
}
do_action( 'bbp_akismet_submit_' . $request_type . '_post', $post_id, $post_data['bbp_akismet_result'] );
}
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.