Documentation

Add-on Framework

  1. Introduction
  2. How it works
  3. A Simple Add-On
  4. Function Descriptions


Introduction

The Add-On Framework provides basic functionality for developers when creating new add-ons for Gravity Forms. It facilitates the following:

  • Initialization
  • Enforcing Gravity Forms minimum version requirement
  • Creating settings pages (add-on and form settings)
  • Permissions and integration with the Members plugin
  • Conditional script enqueuing including no-conflict mode integration
  • Adding custom meta fields to the entry object
  • Creating form feeds
  • Creating a results page
  • Integration with the Gravity Forms Locking API
  • Standardization of UI elements and styles
  • Automatic clean uninstall


How it works

To create a new add-on, simply extend one of the following classes:

  • GFAddOn
    Extend the GFAddOn class to create add-ons that are either very simple or that don't fit into the more specialized case below (GFFeedsAddOn). This class will help to make sure all the scripts are enqueued on the right page, it'll speed up the development of settings pages and it eliminates the need to write some of the housekeeping tasks like clean uninstall.

  • GFFeedAddOn
    Extend the GFFeedAddOn class to create add-ons that give users the ability to create form feeds. A feed is a user-configurable action that gets processed after a form is submitted. With this class you get all of the features of the GFAddOn class plus some additional functionality to facilitate the development of the feed settings UI and conditional processing. For examples of add-ons that use feeds, check out the MailChimp Add-On and the Coupons Add-On.

    Note: Gravity Forms' Add-Ons which are utilizing the Add-On Framework have two key files used for the Add-On. The separation into two files came about because Add-Ons could be attempted to be loaded before Gravity Forms has loaded. Because the Add-Ons require Gravity Forms, errors would be thrown. The file loaded by WordPress, named with the slug, contains no dependency on Gravity Forms and no errors are thrown if Gravity Forms has not yet loaded. This file will include a second file which will only be run once the filter "gform_loaded" fires by Gravity Forms and initializes the Add-Ons.

    Below is an example of what the root file loaded by WordPress would look like. This is the root file for the PayPal Standard Add-On.
    paypal.php (minus header information)

define( 'GF_PAYPAL_VERSION', '2.3.7' );</p>

<p>add_action( 'gform_loaded', array( 'GF_PayPal_Bootstrap', 'load' ), 5 );</p>

<p>class GF_PayPal_Bootstrap {</p>

<pre><code>public static function load(){

    if ( ! method_exists( 'GFForms', 'include_payment_addon_framework' ) ) {
        return;
    }

    require_once( 'class-gf-paypal.php' );

    GFAddOn::register( 'GFPayPal' );
}
</code></pre>

<p>}</p>

<p>function gf_paypal(){
    return GFPayPal::get_instance();
}

In the above example, you will notice that the secondary file loaded is named "class-gf-paypal.php". This occurs when the "gform_loaded" filter is applied.


A Simple Add-On

The following code demonstrates the following:

  • basic configuration of the add-on
  • including the Add-On Framework in a plugin
  • extending the GFAddOn class
  • enforcing the requirement for the minimum version of Gravity Forms
  • adding a top level page to the Forms menu
  • adding a form settings tab and add one checkbox
  • adding an add-on settings tab to the Gravity Forms settings page with one textbox
<?php
if (class_exists("GFForms")) {
    GFForms::include_addon_framework();

    class GFSimpleAddOn extends GFAddOn {

        protected $_version = "1.0";
        protected $_min_gravityforms_version = "1.7.9999";
        protected $_slug = "simpleaddon";
        protected $_path = "simpleaddon/simpleaddon.php";
        protected $_full_path = __FILE__;
        protected $_url = "http://www.gravityforms.com";
        protected $_title = "Gravity Forms Simple Add-On";
        protected $_short_title = "Simple Add-On";

        public function plugin_page() {
            ?>
            This page appears in the Forms menu
            &lt;?php
        }</p>

<pre><code>    public function form_settings_fields() {
        return array(
            array(
                "title"  =&gt; "Simple Form Settings",
                "fields" =&gt; array(
                    array(
                        "label"   =&gt; "My checkbox",
                        "type"    =&gt; "checkbox",
                        "name"    =&gt; "enabled",
                        "tooltip" =&gt; "This is the tooltip",
                        "choices" =&gt; array(
                            array(
                                "label" =&gt; "Enabled",
                                "name"  =&gt; "enabled"
                            )
                        )
                    )
                )
            )
        );
    }

    public function plugin_settings_fields() {
        return array(
            array(
                "title"  =&gt; "Simple Add-On Settings",
                "fields" =&gt; array(
                    array(
                        "name"    =&gt; "textbox",
                        "tooltip" =&gt; "This is the tooltip",
                        "label"   =&gt; "This is the label",
                        "type"    =&gt; "text",
                        "class"   =&gt; "small"
                    )
                )
            )
        );
    }

}

new GFSimpleAddOn();
</code></pre>

<p>}
?>

For a more complete example, check out the sample add-on available on GitHub:
https://github.com/rocketgenius/simpleaddon


Function Descriptions

You can find a detailed description of each of the functions in the Add-On Framework by opening gravityforms/includes/addon/class-gf-addon.php