For our WordPress site (which uses Contact Form 7), we wrote some custom php that runs a background process when a specific CF7 is submitted. We did this within our child theme's functions.php, with reference files placed in a sub folder within the child theme.
Code from functions.php:
add_action( 'wpcf7_before_send_mail', 'vul_submit' );
function vul_submit( $contact_form ) {
$title = $contact_form->title;
$submission = WPCF7_Submission::get_instance();
if ( $submission ) {
$posted_data = $submission->get_posted_data();
}
if ( 'SVT' == $title ) {
require dirname(__FILE__) . "/ST/index.php";
}
}
The index.php
contains or calls on the rest of the code. This currently works great--the intended functions run when a CF7 form with the name "SVT" is submitted.
However, when I try to move this out of the child theme, and instead into a site-specific SVTplugin.php
, it no longer works. I followed instructions here http://www.wpbeginner.com/beginners-guide/what-why-and-how-tos-of-creating-a-site-specific-wordpress-plugin/, and moved the above quoted code out of functions.php into its own plugin file (as well as all the supporting files).
I can confirm that the plugin is activated, and that the conflicting function in the original functions.php has been commented out. The form still submits--except nothing happens in the background anymore.
By adding some "debugging" file_put_contents
, it appears that SVTplugin.php
isn't being called upon form submission. Not sure what the right terminology is, but I suspect the add_action
isn't activated here? Do I need a separate do_action
or something?
I'm guessing there may be a very simple thing that I'm missing here--any guidance would be appreciated. Thanks!
file_put_contents
into the SVTplugin.php function before it goes onto calling the other files, and the text write doesn't actually activate for some reason.