• Resolved Beda

    (@bedas)


    On a particular project we need to completely bypass Akismet for certain users.

    So I was hoping that using pre_comment_approved filter and returning one for those users who we want to “whitelist”, would do it, but clearly Akismet still scans these users’s comments and flags them as spam (but we trust these users and do NOT want Akismet to scan these particular users’ comments.

    This was the code used:

     function prefix_auto_approve_comments_by_role( $approved, $commentdata ) { $user = wp_get_current_user(); $allowed_roles = array( 'role_1', 'role_2' ); if ( array_intersect( $allowed_roles, $user->roles ) ) { return 1; } // Otherwise, return the original approval status. return $approved; } add_filter( 'pre_comment_approved' , 'prefix_auto_approve_comments_by_role' , '99', 2 );

    Thus my question to the support community here as I cannot find any other appropriate filter in Akismet itself, or any related documentation:
    How to completely bypass Akismet scanning for certain users?

    The filter name, if any, is enough for me to proceed.

    Thanks

    • This topic was modified 1 year, 6 months ago by Beda .
Viewing 6 replies - 1 through 6 (of 6 total)
  • Hi @bedas .

    There are multiple ways you can achieve this. Let me discuss a few of them with the team, and we’ll get back to you soon with some suggestions. 🙂

    I was going to suggest that maybe the Auto Approve Comments plugin could be of help, but I checked their code, and they actually don’t approve a comment if Akismet thought it’s spam .

    On the other hand, maybe the approach they’re taking could be something you could replicate for your needs: they hook on wp_insert_comment , set $comment['comment_approved'] to 1, and update the comment .

    That wouldn’t bypass Akismet per se, though. It would just negate it flagging something as spam.

    To completely bypass Akismet, you can also leverage the fact that it won’t do anything in the way of checking for spam if the API key isn’t configured.

    So, in an mu-plugin (or your preferred way to auto-run code), you could:

     if ( ! is_admin() ) { add_filter( 'akismet_get_api_key', '__return_null' ); }

    … for the users you want. That way, every time our plugin tries to use Akismet::get_api_key() , it won’t get one, and won’t check the API, etc.

    The is_admin() test is there so that those users still get access to Akismet’s functionalities in wp-admin (like in comment moderation, etc).

    Thread Starter Beda

    (@bedas)

    Hi there @stephdau – thanks for the reply.

    Wouldn’t it be a good idea to include a “dedicated” filter for this?
    I can work with the return null for API key, it’s a good way, but also kind of feels a bit “hacky”. Nothing wrong with it, just that a “akismet_bypass_scan” or something like that, would feel “better” 🙂

    Also the is_admin will not work if the comments are submitted by ajax. Which makes it a bit more tricky to use that option with the API Key.

    Anyway, I think I can work around with the provided options.

    • This reply was modified 1 year, 6 months ago by Beda .

    Hi @bedas .

    We’ll look into a new hook to achieve that in a future release indeed.

    Hi Steph!

    FWIW I also need this for my acceptance testing with Codeception. All in all I’d like to keep Akismet enabled, but don’t want it affecting my comments testing. A dedicated filter I could rely on would be a huge help.

    (ideally, it would be a filter that could be added on init , rather than requiring an mu-plugin or whatever. The filter you gave needs to be run super early which is a big inconvenience)

    • This reply was modified 1 year, 3 months ago by Jer Clarke .

    Hey @jerclarke ! It’s been a minute since we’ve talked WP. 😀
    Sorry for the delay, mis-sorted notif.

    Noted, but in the context of testing , something you might want to explore leveraging is the AKISMET_TEST_MODE constant and related Akismet::is_test_mode() . That’ll set the is_test param when querying the API, so your tests don’t affect training, etc.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Completely bypass Akismet’ is closed to new replies.