How to use add_action("wpcf7_before_send_mail" outside wp loop?

I am trying to trigger an add_action hook (add_action("wpcf7_before_send_mail", "add_data_to_custom_table");) from outside the wordpress loop. The add_action hook is defined in theme's functions-custom.php.

in domain.com/test.php i have

define('WP_USE_THEMES', false);
define('WP_CUSTOM_TABLE', 'test_table');

/** Loads the WordPress Environment and Template */
require( '../wp/wp-blog-header.php' );

   include('../wp/wp-content/themes/customtheme/incs/functions-custom.php');

?php echo do_shortcode('[contact-form-7 id="417" title="Test Contact Form"]'); ?

In this setup the add_action hook is not working. If however i move the add_action hook definition to the theme's functions.php it does work.

My question: how can i include a functions-custom.php file outside the wordpress loop with working add_actions without including it from the theme's functions.php???

Topic plugin-contact-form-7 outside-wordpress loop Wordpress

Category Web


Just simply put your add_action hook in a simple plugin. Activate the plugin and watch it run with the rest of the plugins.

If you insist on putting the add_action in the theme's functions.php then simply define a constant in your point of entry script, like this: define('SCRIPTONOMY', true);

Finally run a conditional in the functions.php testing for the constant.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.