BBP_Akismet::update_post_meta( int $post_id, object $_post = false )
Update post meta after a spam check
Description
Parameters
- $post_id
-
(Required)
- $_post
-
(Optional)
Default value: false
Source
File: bp-forums/extend/akismet.php
public function update_post_meta( $post_id = 0, $_post = false ) {
// Define local variable(s)
$as_submitted = false;
// Setup some variables
$post_id = (int) $post_id;
// Ensure we have a post object
if ( empty( $_post ) )
$_post = get_post( $post_id );
// Set up Akismet last post data
if ( !empty( $this->last_post ) )
$as_submitted = $this->last_post['bbp_post_as_submitted'];
// wp_insert_post() might be called in other contexts. Ensure this is
// the same topic/reply as was checked by BBP_Akismet::check_post()
if ( is_object( $_post ) && !empty( $this->last_post ) && is_array( $as_submitted ) ) {
// Get user data
$userdata = get_userdata( $_post->post_author );
$anonymous_data = bbp_filter_anonymous_post_data();
// More checks
if ( intval( $as_submitted['comment_post_ID'] ) === intval( $_post->post_parent )
&& $as_submitted['comment_author'] === ( $anonymous_data ? $anonymous_data['bbp_anonymous_name'] : $userdata->display_name )
&& $as_submitted['comment_author_email'] === ( $anonymous_data ? $anonymous_data['bbp_anonymous_email'] : $userdata->user_email )
) {
// Normal result: true
if ( $this->last_post['bbp_akismet_result'] === 'true' ) {
// Leave a trail so other's know what we did
update_post_meta( $post_id, '_bbp_akismet_result', 'true' );
$this->update_post_history( $post_id, esc_html__( 'Akismet caught this post as spam', 'buddyboss' ), 'check-spam' );
// If post_status isn't the spam status, as expected, leave a note
if ( bbp_get_spam_status_id() !== $_post->post_status ) {
$this->update_post_history( $post_id, sprintf( esc_html__( 'Post status was changed to %s', 'buddyboss' ), $_post->post_status ), 'status-changed-' . $_post->post_status );
}
// Normal result: false
} elseif ( $this->last_post['bbp_akismet_result'] === 'false' ) {
// Leave a trail so other's know what we did
update_post_meta( $post_id, '_bbp_akismet_result', 'false' );
$this->update_post_history( $post_id, esc_html__( 'Akismet cleared this post as not spam', 'buddyboss' ), 'check-ham' );
// If post_status is the spam status, which isn't expected, leave a note
if ( bbp_get_spam_status_id() === $_post->post_status ) {
// @todo Use wp_blacklist_check()
$this->update_post_history( $post_id, sprintf( esc_html__( 'Post status was changed to %s', 'buddyboss' ), $_post->post_status ), 'status-changed-' . $_post->post_status );
}
// Abnormal result: error
} else {
// Leave a trail so other's know what we did
update_post_meta( $post_id, '_bbp_akismet_error', time() );
$this->update_post_history( $post_id, sprintf( esc_html__( 'Akismet was unable to check this post (response: %s), will automatically retry again later.', 'buddyboss' ), $this->last_post['bbp_akismet_result'] ), 'check-error' );
}
// Record the complete original data as submitted for checking
if ( isset( $this->last_post['bbp_post_as_submitted'] ) ) {
update_post_meta( $post_id, '_bbp_akismet_as_submitted', $this->last_post['bbp_post_as_submitted'] );
}
}
}
}
Changelog
| Version | Description |
|---|---|
| bbPress (r3308) | 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.