just a quick question to save me time, if askismet sees it as spam, is the topic/reply still created, but marked as spam ie you can still see it in dashboard>topics/replies but as a spam?
They’re all in the dashboard under the spam section. So yes, the topic/reply is still created. My specific issue is not really with the spam topics though, as they don’t appear on the frontend and don’t affect user experience. My issue is with spam replies in legitimate topics, as these replies still modify the topic metadata and affect last_active_time. This places them on the top of the topics loop, and displays their last active date as the spam reply date, although there’s no new content in there for the user to see.
thanks, yes this happens in this forum too, but I have limited access to the backend here, as I just help out.
I was asking so I can find a hook to try and fix. your post was helpful, so let me see if I can do some code later today
Just playing with options. I don’t know how technical you are, but for an ‘askimet’ spammed reply, are there anything additional fields set in the reply metadata to say that askimet found it? If you don’t know, not a problem, but if there is or you know nothing is set, then that would be useful
Yes, there is a note saying something like “Akismet marked this post as spam” (I’m using a translated version, so I’m just translating into English off the top of my head). I’ll look under the hood a bit to give you more specifics on what triggers this
I’m in the code, and can work out where we might link to a hook, it is really if there is a metadata field I can use to do a check – the name would be useful
in case you are working on this, basically if we hook to
bbp_new_reply_pre_extras
we can then do a check if it has been spammed by askimet and the if so, just do a reply walker update
so something like (totally untested)
add_action ('bbp_new_reply_pre_extras' , 'rew_askimet_check', 100 , 1 ) ; //might need to be run at a high priority to make sure it is last - not tested
function rew_askimet_check ($reply_id) {
//only execute is this is akismet spam
if ( bbp_get_spam_status_id() == get_post_status($reply_id) && [some check that this has been marked by akismet])) {
//just run the reply update walker as this will do a full refresh of all ancestors to the topic if just the reply ID is sent
bbp_update_reply_walker($reply_id) ;
}
}
The akismet check would be something like
if (get_post_meta( $reply_id, 'some akismet metadata', true )
just had a quick look (i’m working on soemthing else at the moment, but found 5 minutes)
maybe
if ( bbp_get_spam_status_id() == get_post_status($reply_id) && !empty (get_post_meta( $reply_id, '_bbp_akismet_user_result', true ))) {
I apologise for the late response, I was distracted by another urgent issue. So if my understanding is correct, this basically just reruns the bbp_update_reply_walker if the reply is flagged by spam. But from what I’ve seen in the code, this wouldn’t solve the specific issue, since the walker only checks for the replie’s pending status
As in:
// Only update if reply is published
if ( ! bbp_is_reply_pending( $reply_id ) ) {
// Last reply and active ID's
bbp_update_topic_last_reply_id ( $ancestor, $reply_id );
bbp_update_topic_last_active_id( $ancestor, $active_id );
// Get the last active time if none was passed
$topic_last_active_time = $last_active_time;
if ( empty( $last_active_time ) ) {
$topic_last_active_time = get_post_field( 'post_date', bbp_get_topic_last_active_id( $ancestor ) );
}
bbp_update_topic_last_active_time( $ancestor, $topic_last_active_time );
}
But the specific reply, if it has been marked by Akismet would have the status ‘spam’ and not ‘pending’, so the walker would still update the value wrong. Is my understanding correct?
I don’t have any forums on my live sites (anymore), so don’t use akismet, so I’m relying on your better knowledge 🙂
so to save having to repeat bbpress code, the logic might be
add_action ('bbp_new_reply_pre_extras' , 'rew_askimet_check', 100 , 1 ) ; //might need to be run at a high priority to make sure it is last - not tested
function rew_askimet_check ($reply_id) {
//only execute is this is akismet spam
if ( bbp_get_spam_status_id() == get_post_status($reply_id) && !empty (get_post_meta( $reply_id, '_bbp_akismet_user_result', true ))) {
//unspam the reply (which takes it back to pending, and within that function runs the update_reply_walker)
bbp_unspam_reply( $reply_id) ;
//and then re-spam it
bbp_spam_reply( $reply_id) ;
}
}
which is actually what I do manually (I click unspam and then click spam on the front end admin) on this site when akismet does this.
Hi, allow me to join in. I am Martin’s collegue and we are dealing with this issue together.
I went into the code to see how this works. The problem is that after spam is checked using bbp_new_reply_pre_insert filter currently on line 379 in includes/replies/functions.php, the wp_insert_post runs, which is fine, but a few lines later the hook bb_new_reply hooks the function bbp_new_reply that takes care about all the extra metadata non related to the post but to various counts and date updates. However if we have spam, this function should probably not run.
I guess we should unset this action if spam is found. Do you think this can be done using the bbp_akismet_check_post filter?
Thanks for joining!
I am not a bbpress author, just someone who helps out.
Yes, I suspect that there are several places it could be done.
My code above should work (and if you can test it that would be great) , but if you fancy working up a better solution, please post back.
I will happily incorporate it into my bbp-style-pack plugin to save others needing to work out code and/or use child theme functions.
Thanks, for helping Robin. I believe your solution would work too, it’s just that we are trying to avoid or even reduce db overhead.
do you mean db or server?