Okay, let me get it out there, I love Akismet. It has saved me so much time on the account I simply don’t have any reason to check spam. It’s truly something that you can set and forget, and really you should pay for it.
Another great plugin you should pay for is Gravity Forms, it is well coded, extensible, with lots of extensions, and some great built in features. One such in built feature which is switched on automatically is spam checking messages with Akismet. It’s something you should leave switched on.
However, there may be the odd occasion where you have to switch it off.
Say, for example, you have a Gravity Form which allows logged in users to submit posts. Logged in users are provisionally spam checked, so you don’t need to check for spam again. Furthermore, Gravity Forms’ spam filter after the form contents is saved, but before it is saved as a standard post. So if the message is flagged as spam, the user will not see his post go live, and it won’t be present in the Posts section of the WordPress dashboard. Intstead it is hidden in the “Spam” section of the entries field.
In situations like this, it makes sense to disable Gravity Forms’ spam filters. Although there isn’t a tickbox or a setting on a form or sitewide, you can do this with a few lines of code.
There is a filter – gform_akismet_enabled – that allows you to disable Akismet on individual forms or on all forms (which I wouldn’t recommend). To disable it, get your form ID (which you can find on the Forms page), and add it to the end of the hook. So for this example, we’ll use ID of 1.
So, to disable Akismet on this form, simply do the following:-
1 2 3 4 5 6 7 8 9 10 11 | /** * Disable akismet on a Gravity form * * @link https://www.winwar.co.uk/2015/01/disable-gravity-forms-spam-filter-2/?utm_source=codesnippet * * @return false */ function winwar_disable_akismet() { return false; } add_filter("gform_akismet_enabled_1", "winwar_disable_akismet"); |
It’s generally a good idea to have this in a function, as should you need to add to more than one form, you can call it, plus it maintains backwards compatibility:-
1 2 3 4 5 6 7 8 9 10 11 12 | /** * Disable akismet on a Gravity form * * @link https://www.winwar.co.uk/2015/01/disable-gravity-forms-spam-filter-2/?utm_source=codesnippet * * @return false */ function winwar_disable_akismet() { return false; } add_filter("gform_akismet_enabled_1", "winwar_disable_akismet"); add_filter("gform_akismet_enabled_3", "winwar_disable_akismet"); |
Anyway, that’s how you disable the Gravity Forms spam filter. 99% of the time you should leave it on. However on the rare occasions you need to switch it off, that’s how to do it.
Hi Rhys,
Great post, I’m sure it will help a lot of users. It’s worth noting there is a sitewide setting for disabling the Akismet integration on the Forms > Settings page.
Also in Gravity Forms 1.8.17 we introduced the gform_entry_is_spam hook which allows developers or users to perform their own spam check and return true or false. There’s also a form specific version.
add_filter( 'gform_entry_is_spam', 'it_is_all_spam', 10, 3 );
function it_is_all_spam( $is_spam, $form, $entry ) {
// perform custom check
return true;
}
I believe there are some third-party plugins and add-ons already making use of this hook.
January 14, 2015 at 12:19 pmThanks for the comment Richard, do appreciate it :)
Wasn’t aware of the sitewide switch off, should be more useful than relying on the code, and good to hear about the custom checker. Thanks for your great comment!
January 14, 2015 at 12:28 pmEither I’m being dense or there *isn’t* actually a setting for Akismet on Forms > Settings…
January 14, 2015 at 1:36 pmThe Akismet Integration setting appears between the No-Conflict Mode and Currency settings, it is only present when Akismet is installed and active.
January 14, 2015 at 1:40 pmIgnore me, looks like the client has removed Akismet. That would explain why I can’t see it… ;)
January 14, 2015 at 3:11 pmHi Rhys,
When I first read the title, I couldn’t think of a scenario where this might be useful, but it looks like there is one :)
You could make your functions even simpler with using the
__return_false()
function WordPress already provides, which simply returns false.
January 14, 2015 at 3:23 pmadd_filter("gform_akismet_enabled_1", "__return_false");
Hi Pascal,
Thanks for that. I wasn’t sure of how to structure something like what you suggested, hence going the more traditional route :).
Rhys
January 14, 2015 at 4:33 pm