PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

Import form on plugin activation

  1. I have a small plugin for my multisite that essentially registers a custom post type and on activation I would like it to import a gravity form that I had previous created and exported.

    Is there any documentation or help that I can get that might point me in the right direction for importing a gravity form upon plugin activation?

    TIA

    Posted 11 years ago on Tuesday April 2, 2013 | Permalink
  2. This will work upon site creation in multisite:
    http://www.gravityhelp.com/documentation/page/Advanced_Configuration_Options#GF_IMPORT_FILE

    This will work when a theme is activated:
    http://www.gravityhelp.com/documentation/page/Advanced_Configuration_Options#GF_THEME_IMPORT_FILE

    I think you could copy the code that is used for the GF_THEME_IMPORT functionality and adapt it to your plugin application.

    Posted 11 years ago on Tuesday April 2, 2013 | Permalink
  3. Thanks for the quick response Chris. This solution seems like it's only applicable to when a new site is created on a multisite network. Is there a way to use the GF_IMPORT_FILE on plugin activation?

    I tried adding define("GF_IMPORT_FILE", "http://mydomain.com/plugin-direcory/get-a-free-estimate.xml"); to my plugin file and on activation, the form was not imported.

    Thanks for your help!

    Posted 11 years ago on Tuesday April 2, 2013 | Permalink
  4. It won't work on plugin activation. I was hoping your could look at how the code works on theme activation, and you could modify that to work in your plugin, so that when the plugin is activated, you can run the same type of code to import your XML file containing the form.

    This functionality: http://www.gravityhelp.com/documentation/page/Advanced_Configuration_Options#GF_THEME_IMPORT_FILE

    Posted 11 years ago on Tuesday April 2, 2013 | Permalink
  5. My apologies, I responded before you added more details to your initial response. I'll look into the GF_THEME_IMPORT functionality.

    Posted 11 years ago on Tuesday April 2, 2013 | Permalink
  6. Looks like this is what happens when a theme is activated and that constant is defined:

    [php]
    GFExport::import_file(get_stylesheet_directory() . "/" . GF_THEME_IMPORT_FILE);

    You could call the same function when your plugin is activated, with a different constant, and a different location.

    Posted 11 years ago on Tuesday April 2, 2013 | Permalink
  7. I got it working using the following:

    define("GF_IMPORT_FILE", "http://mydomain.com/plugin-directory/get-a-free-estimate.xml");
    function nwtd_lpfs_import_form() {
    	if(defined("GF_IMPORT_FILE") && !get_option("gf_imported_file")){
            GFExport::import_file(GF_IMPORT_FILE);
            update_option("gf_imported_file", true);
        }
    }
    add_action('init', 'nwtd_lpfs_import_form' );

    Using just GFExport::import_file(get_stylesheet_directory() . "/" . GF_THEME_IMPORT_FILE); added two of the forms upon plugin activation and another upon plugin deactivation.

    Thanks for your help Chris!

    Posted 11 years ago on Tuesday April 2, 2013 | Permalink
  8. Chris, my issue is resolved but I'm not sure how to close this thread.

    Posted 11 years ago on Wednesday April 3, 2013 | Permalink

This topic has been resolved and has been closed to new replies.