WordPress - Contact Form7 - Modify php code of analyze to inject own spam-check

86
December 08, 2019, at 05:50 AM

I have Breaked my lance searching over english and russian manuals

Info: I`m running site on the Wordpress platform. Its contact form is WordpressContactForm7.

The Issue: spam is beeing REPEATEDLY sent 5-7 times a day through the contact form to my callcenter`s email.

My work: I made simple spam filter in php that block common phrases and emails, that beeing found in body of message - makes its spam-rating hotter and hotter.

Everything after spam-level 90% is blocked. Everything after 60% must block user to 1-email-a-day- mode

The Problem : I could not find any proper place in WPCF7 phpcode to inject my own.

I am new to wordpress and could find only two entry-points: 1) virtual address of data-processor sitename.com/wp-json/contact-form-7/v1/contact-forms/46550/feedback that is virtual and tells me nothing about the place where wpcf7 have server-processing and sending to my mail.

2) installation ZIP of contact-form-7 plugin Also it has lots of everything - And I watched through carefully - but I found I cannot make a full image of it in my mind /

So I decided to ask for the help the experienced coder to show off the different ways to deal with that.

P.S. (Note1 I am a little affraid of WP, and prefer to rely on my own raw php skills and build-from-zero code constructions. Im much better dealing the code done by me rather than somebody outers.)

(Note2 I ve heard that json api is vuln...)

(Note3 I`m afraid of updating any components - the cause is that WP is controlled and carried by superirors - so any my fault can be the last one^)

Please Kindly consult me on the topic, If possible <3 Thank You

Answer 1

CF7 have a lot of hooks and filters actually, like wpcf7_skip_mail,wpcf7_mail_sent,wpcf7_before_send_mail and others..

e,g:

 add_action( 'wpcf7_before_send_mail', 'wpcf7_my_before_send_mail' );
   function wpcf7_my_before_send_mail( $wpcf7 ) {
       // put your logic  code here
   }

the following is special for skipping mail

 add_filter( 'wpcf7_skip_mail', function( $skip_mail, $contact_form ) {
       if( /* your logic */ )
           $skip_mail = true;
       return $skip_mail;
   }, 10, 2 );

combining this logic, you can also do something like

add_action("wpcf7_before_send_mail", "wpcf7_do_something");  
function wpcf7_do_something($cf7) {
    // this is the contact form object
    $wpcf = WPCF7_ContactForm::get_current();
    // exam0ple : ID of Form $wpcf->id
    if (/*your logic here*/) {
        // If you want to skip mailing... 
        $wpcf->skip_mail = true;    
    }
    return $wpcf;
}

you should also look at the CF7 Docs, you could find some other ways of fighting spam like ip_blacklist and other tips

READ ALSO
Having problem with a multilevel-array in Twig

Having problem with a multilevel-array in Twig

I trying everything but I don't know how to get a day that is associated with a vacation objectIn a multi-dimensional array in a Twig template I put a year, the year has 12 months, and every month has days, every day has a name("Monday,

87
How to remove array sign from json encoded data

How to remove array sign from json encoded data

I was modifying existing api and after watching documentation, i realized that the output is not appropriate as documentation describesSo i tried couple of methods but didn't get to the output

87
I am having an issue with the twig template system

I am having an issue with the twig template system

I have opencart 3 installed on my dev box and have suddenly started getting the following error:

93