I’m having trouble figuring out where I should be registering my function in such a way that I can access the Gravity Forms API (GFAPI). At first glance, this may appear to be native to Gravity Forms, but I think I’m just missing some basic understanding of how WordPress uses hooks and registers functions.
The error I’m trying to resolve is that class_exists(“GFForms”) returns false (i.e. my code can’t access the API) in a context where I want it to return true.
I’m trying to take an XML, parse it, and use some of the data to generate a gravity forms entry.
My starting point was the Gravity Forms Simple AddOn (https://github.com/gravityforms/simpleaddon) as, to my knowledge, this is the direction I probably need to head since I’m wanting to access the GFAPI (correct me if I’m wrong there).
1) To start, I create a bootstrap file responsible for making GravityForms aware of the AddOn (abcd_import.php):
2) The following class (in class-abcd.php) contains the function that creates a shortcode, which creates a form, which calls ‘process_xml.php’. Before I had it set up so that both the ‘add_abcd_import_fields’ and ‘add_shortcode’ functions were outside the class. When they were outside the class, I could add the shortcode which successfully added the form (but no API access).
3) The HTML form created from the shortcode calls ‘process_xml.php’ through it’s action attribute. At the end of this file I attempt to a call a function ‘generate_A’ which fails because GFForms is unavailable. Regardless of what I do (read: where I move my functions around, the filters I add, etc.), I can’t seem to get at the GFAPI. My only conclusion is that I’m just doing something dumb.
Gratitude to anyone that can point me in the right direction on this. Thanks so much!