Gravity Forms
Add-On Framework
Getting started
About Me
From Graphic Designer to Multimedia Designer/Developer to Web Developer.
Gravity Forms
A shotgun introduction
Amazing Features
My 'go-to' forms plugin for WP sites
Advanced forms, surveys etc
Extendable, hooks, API functions
3rd party integrations
Easy to use, clients love it
Over a million sites using it*
GF itself doesn't provide everything
New fields, extended functionality
3rd party integration
Improved usability
Why Add-ons?
- Jump-starts your plugin dev
- Takes care of some of the standard crap
- Better integration
- Min. GF version
- Script enqueuing
- Locking API
- Clean uninstall
- Standardised UI elements
Add-On Framework
How it works
Extend one of the following classes:
- GFAddon
- GFFeedAddon
- GFPaymentAddon
GFAddon Class
For add-ons that are very simple
or don't fit into one of the more specialised cases
https://www.gravityhelp.com/documentation/article/gfaddon/
GFFeedAddon Class
For add-ons that allow users to create form feeds
- Easily add feed settings UI, conditional processing
- Eg. MailChimp add-on
https://www.gravityhelp.com/documentation/article/gffeedaddon/
GFPaymentAddon Class
For add-ons that collect payments. Handles:
- Payments via 3rd party websites (eg PayPal Standard)
- Credit card payments behind the scenes (eg Stripe)
https://www.gravityhelp.com/documentation/article/gfpaymentaddon/
Creating your own
Min. two main files:
- Your bootstrap / plugin file
- Your add-on class
Two files because add-ons could be attempting to load before Gravity Forms. This method waits for the "gform_loaded" filter to fire before loading your class.
Simple example
https://github.com/rocketgenius/simpleaddon
Bootstrap / plugin file:
/*
...
*/
define( 'GF_SIMPLE_ADDON_VERSION', '2.0' );
add_action( 'gform_loaded', array( 'GF_Simple_AddOn_Bootstrap', 'load' ), 5 );
class GF_Simple_AddOn_Bootstrap {
public static function load() {
if ( ! method_exists( 'GFForms', 'include_addon_framework' ) ) {
return;
}
require_once( 'class-gfsimpleaddon.php' );
GFAddOn::register( 'GFSimpleAddOn' );
}
}
function gf_simple_addon() {
return GFSimpleAddOn::get_instance();
}
Add-on class (class-gfsimpleaddon.php):
GFForms::include_addon_framework();
class GFSimpleAddOn extends GFAddOn {
protected $_version = GF_SIMPLE_ADDON_VERSION;
protected $_min_gravityforms_version = '1.9';
protected $_slug = 'simpleaddon';
protected $_path = 'simpleaddon/simpleaddon.php';
protected $_full_path = __FILE__;
protected $_title = 'Gravity Forms Simple Add-On';
protected $_short_title = 'Simple Add-On';
private static $_instance = null;
/**
* Get an instance of this class.
*
* @return GFSimpleAddOn
*/
public static function get_instance() {
if ( self::$_instance == null ) {
self::$_instance = new GFSimpleAddOn();
}
return self::$_instance;
}
...
Simple example
Scripts...
/**
* Return the scripts which should be enqueued.
*
* @return array
*/
public function scripts() {
$scripts = array(
array(
'handle' => 'my_script_js',
'src' => $this->get_base_url() . '/js/my_script.js',
'version' => $this->_version,
'deps' => array( 'jquery' ),
'strings' => array(
'foo' => esc_html__( 'Foo', 'simpleaddon' ),
'bar' => esc_html__( 'Bar', 'simpleaddon' )
),
'enqueue' => array(
array(
'admin_page' => array( 'form_settings' ),
'tab' => 'simpleaddon'
)
)
),
);
return array_merge( parent::scripts(), $scripts );
}
Styles...
/**
* Return the stylesheets which should be enqueued.
*
* @return array
*/
public function styles() {
$styles = array(
array(
'handle' => 'my_styles_css',
'src' => $this->get_base_url() . '/css/my_styles.css',
'version' => $this->_version,
'enqueue' => array(
array( 'field_types' => array( 'poll' ) )
)
)
);
return array_merge( parent::styles(), $styles );
}
Plugin page...
/**
* Creates a custom page for this add-on.
*/
public function plugin_page() {
echo 'This page appears in the Forms menu';
}
Plugin page...
Add-on settings...
/**
* Configures the settings which should be rendered on the add-on settings tab.
*
* @return array
*/
public function plugin_settings_fields() {
return array(
array(
'title' => esc_html__( 'Simple Add-On Settings', 'simpleaddon' ),
'fields' => array(
array(
'name' => 'mytextbox',
'tooltip' => esc_html__( 'This is the tooltip', 'simpleaddon' ),
'label' => esc_html__( 'This is the label', 'simpleaddon' ),
'type' => 'text',
'class' => 'small',
'feedback_callback' => array( $this, 'is_valid_setting' ),
)
)
)
);
}
Extract value with
$this->get_plugin_setting('mytextbox')
Add-on settings...
Form settings...
/**
* Configures the settings which should be rendered
* on the Form Settings > Simple Add-On tab.
*
* @return array
*/
public function form_settings_fields( $form ) {
return array(
array(
'title' => esc_html__( 'Simple Form Settings', 'simpleaddon' ),
'fields' => array(
array(
'label' => esc_html__( 'My Text Box', 'simpleaddon' ),
'type' => 'text',
'name' => 'mytext',
'tooltip' => esc_html__( 'This is the tooltip', 'simpleaddon' ),
'class' => 'medium',
'feedback_callback' => array( $this, 'is_valid_setting' ),
),
array(
'label' => esc_html__( 'My Text Area', 'simpleaddon' ),
'type' => 'textarea',
'name' => 'mytextarea',
'tooltip' => esc_html__( 'This is the tooltip', 'simpleaddon' ),
'class' => 'medium merge-tag-support mt-position-right',
),
),
),
);
}
Form settings...
Monetising
& Licensing
GFAddon > EDD > Licensing > Updates
Real-world demo
Bulk Actions
for Gravity Forms
Thanks
@BK4D
jetsloth.com
fullstackpasswords.io
Questions?
Gravity FormsAdd-On Framework
By bk4d
Gravity FormsAdd-On Framework
- 1,647