Question

I have a plugin that I've written that is trying to call the gforms_after_submission hook. For some reason it isn't calling the function. I see in Gravity Forms documentation that it says I have to call gform_after_submission from the functions file - is there any reason I can't call it from the plugin? I've tested with the mail function, and the function admin_init is triggering.

<?php

class Infusionsoft_GformsPDF {
public function __construct() {
    add_action( 'admin_init', array( $this, 'admin_init' ) );
}

/**
 * Should call my function, but doesn't
 */
public function admin_init() {
    add_action('gform_after_submission', 'handle_file', 10, 2);
}

/**
 * Get the file URL and post it to Infusionsoft
 */

    public function handle_file($entry, $form){
        mail('myemail@email.com', 'Handle File was triggered', 'yippee');
    }
}
Was it helpful?

Solution

the problem here is that you've added the function call to the admin_init hook. The admin_init hook is only triggered when the user accesses the admin area, but you're submitting a form here, an action taking place on the front-end of your site outside of the admin area.

It's a simple fix :-) Just use the front-end initialization hook instead — init

Also check out this reference for the actions that are typically run when a page is loaded, on the front of your site and the admin area:

http://codex.wordpress.org/Plugin_API/Action_Reference

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top