Please can you add an extra filter
-
Hi Guido,
Can you please add an extra filter.
I can give you specific code, or if you have a github repository even a pull request.
I want to handle some extra spam checks for a keen user of yours.
Alan
- This topic was modified 2 years ago by Alan Fuller.
-
Hi Alan,
Not using GitHub, develop local only.
I thought my plugin does quite wel regarding spam, but I’m always willing to add more checks.
Can you share here?
Guido
You plugin does do well against spam but there area few gaps that only a machine learning spam detection can handle.
I would like a filter before the save submission post and a couple of if statements before the add post and send and one around the send ( with an extra filter fixes an issues one of your reviewers had to save but not send )
The easiest way to share is via a gist of my version on vscf-submission.php
https://gist.github.com/alanef/e20f4cf6d39cbff7606fddc76722987b
I hope you find those filters / conditions acceptable
Alan
Hi Alan,
Thanks for this.
File vscf-submission.php starts withif ( $error == false ) {
and IMO the validation and all spam checks should be done before this point. That’s why I didn’t add much validation/checks there.About:
$post_status = apply_filters( 'vscf_pre_database_save', 'pending', $form_data );
My knowledge about
apply_filters()
is limited, the$form_data
doesn’t contain the post status, so not understand what this does.Guido
Hi, first – there is are typos in my gist I’m just going to test fully and then I’ll explain the logic / reasoning
- This reply was modified 2 years ago by Alan Fuller.
OK the gist should be good.
Initially I thought that the
if ( $error == false ) {
would be the place to put the check, but there is an issue with non bot spam in terms of false negatives, in that case you want the spam to be logged in the submissions post, marked as spam, but not send an email.
So the filters and conditions have to be further down.
In terms of how filters work, filter change a variable, the first in the list, but also pass down other data as variables ( as many as you want ) so the filter can make logic choices.
so
$post_status = apply_filters( 'vscf_pre_database_save', 'pending', $form_data );
if there is nothing adding the filter the first argument is returned, so in that case $post_status is
pending
exactly as your original code intends.However a filter can receive multiple arguments and so will receive form data, and hence an anti-spam filter can analyse the $form_data and return a post status of
pending
orspam
if it THINKs it is spam but not 100% sure ( e.g. spam probability > 70% orfalse
if it is certain i.e. bot detected.So an add filter would look like
add_filter('vscf_pre_database_save', function($post_status, $form_data) { if ( spam_analysis($form_data) == 100 ) { $post_status = false; } else if ( spam_analysis($form_data) > 70 ) { $post_status = 'spam'; } return $post_status; }, 10, 2 );
( there is something else needed so the ‘spam’ post_type items show as a link in the list table of submissions, but that is trivial )
The second if / filter just before email sending simply needs to check if the post_type was pending – as that means – send the email, as your original code would. ( I just placed the filter there to make your code more customisable as I noticed the last line of this review https://www.ads-software.com/support/topic/its-great-but-some-things-are-missing/ and that filter would enable turning off email sending )
I hope that explains why the filter and if’s need to be lower down the code.
Hi Alan,
Thanks for your reply and explanation. The code base of my plugins is very easy to understand. I don’t have deep PHP knowledge, using all kinds of resources to build what I want. Of course with usability and security in mind. That’s why sometimes I have trouble understanding the more complex stuff (such as the WP filters) ??
By the way, did you take over the plugins of Graham? Many years ago I had contact with him on a regular basis, while testing his “Quick” plugins for him.
Guido
Hi Guido,
Yes I know Graham well, he lives fairly close to me, and I took over Quick Event Manager, Quick Contact Form and Quick PayPal Payments from him when he wanted to focus on other things.
Alan
Hi Alan,
Have thought about your request a bit longer. SPAM often contains multiple links to shady websites, but my plugin already has an option to disallow or only allow 1 link in the post content. In case more links are added, validation fails. This means no submission is send and saved. So can you explain to me why you think I need those extra filters?
Guido
My request came from a user of my anti spam plugin that wanted to use with your VS Contact form plugin as they already use your plugin rather than migrating to a different forms plugin that is integrateable.
Most major contact form plugins have filter hooks where additional logic pre sending can be plugged in.
I appreciate it is your plugin and you can do with it what you feel fit.
If you don’t want to do it that is fine with me.
- The topic ‘Please can you add an extra filter’ is closed to new replies.