Add-On Framework

Contents

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:

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.

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.

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
        <?php
        }

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

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

    }

    new GFSimpleAddOn();
}
?>

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

Search the Documentation