GF_THEME_IMPORT_FILE

GF_THEME_IMPORT_FILE

DescriptionUsagePlacement

Description
Setting this option allows you to specify a Form JSON file from which a set of default forms can be pre-generated when a theme containing this option is activated. This option can also be used in your theme』s functions.php file.
Usage
define( 'GF_THEME_IMPORT_FILE', 'path/to/gf_import.json' );

Note: The path is relative to your theme root.
Placement
This constant should be set in your wp-config.php. See the article Wp Config Options for more details regarding the JSON file.

GF_User_Registration

GF_User_Registration

Introductiongf_user_registration()maybe_process_feed()get_single_submission_feed()get_meta_value()add_validation_error()get_user_by_entry_id()get_site_by_entry_id()insert_feed()add_note()log_debug()log_error()

Introduction
GF_User_Registration is the class which houses the main functionality of the Gravity Forms User Registration Add-on; it extends the GFFeedAddOn class which is part of the add-on framework. Below are a few functions which you may find useful when working on your own custom code.
gf_user_registration()
The gf_user_registration() function is used to return an instance of the GF_User_Registration class.
maybe_process_feed()
Triggers processing of the User Registration feeds for the specified form and entry objects.
$entry = gf_user_registration()->maybe_process_feed( $entry, $form );

$entry Entry Object
The Entry Object to be processed.

$form Form Object
The Form Object to be processed.

Returns Entry Object

get_single_submission_feed()
Retrieves the feed for the specified form and entry objects.
$feed = gf_user_registration()->get_single_submission_feed( $entry, $form );

$entry Entry Object
The Entry Object to be processed.

$form Form Object
The Form Object to be processed.

Returns Feed Object|boolean
The feed which was used to process the supplied entry object or false if a feed wasn』t processed for the entry and an active feed with matching conditional logic could not be found.

get_meta_value()
Retrieves the value to be used for the specified meta key.
$value = gf_user_registration()->get_meta_value( $meta_key, $meta, $form, $entry );

$meta_key string
The meta key for the field which was mapped when configuring the feed.

$meta User Registration Feed Meta
The array containing the feed properties.

$form Form Object
The Form Object being processed.

$entry Entry Object
The Entry Object being processed.

Returns string
The value matching the meta mapping for the given meta key or if not found, an empty string.

add_validation_error()
Useful when performing custom validation using the gform_user_registration_validation filter to add a custom validation error message.
$form = gf_user_registration()->add_validation_error( $field_id, $form, $message );

$field_id integer
The ID of the field the validation error should be applied to.

$form Form Object
The Form Object to be processed.

$message string
The validation message to be applied to the field.

Returns Form Object

get_user_by_entry_id()
Retrieve the user object or id for the user which was created or updated by the supplied entry id.
$user = gf_user_registration()->get_user_by_entry_id( $entry_id );
$user_id = gf_user_registration()->get_user_by_entry_id( $entry_id, true );

$entry_id integer
The ID of the entry the user was created or updated from.

$id_only boolean
Defaults to false. Indicates if the user ID should be returned instead of the full WP_User object

Returns boolean|integer|WP_User
False if a user wasn』t created or updated from the entry, or the user id or WP_User object.

get_site_by_entry_id()
Retrieve the id of the site which was created or updated by the supplied entry id.
$site = gf_user_registration()->get_site_by_entry_id( $entry_id );

$entry_id integer
The ID of the entry the user was created or updated from.

Returns boolean|integer
False if a site wasn』t created or updated from the entry, or the site id.

insert_feed()
The insert_feed() method can be used to add User Registration feeds.
$feed_id = gf_user_registration()->insert_feed( $form_id, $is_active, $meta );

$form_id integer
The ID of the form this feed will be used with.

$is_active boolean
Is this feed active or inactive.

$meta User Registration Feed Meta
An associative array containing the properties which determine if a user will be updated or created when the feed is processed.

Returns integer
The ID of the new feed.

add_note()
Add a note to the specified Entry.
gf_user_registration()->add_note( $entry_id, $note, $note_type );

$entry_id integer
The ID of the Entry this note should be added to.

$note string
The note to be added.

$note_type string
The type of note to be added. Example values: note, success, or error.

log_debug()
Writes a debug message to the log file for the User Registration Add-On. Requires the Logging Add-On.
gf_user_registration()->log_debug( $message );

$message string
The message to be written to the User Registration log.

log_error()
Writes an error message to the log file for the User Registration Add-On. Requires the Logging Add-On.
gf_user_registration()->log_error( $message );

$message string
The message to be written to the User Registration log.

GFAddOn

GFAddOn

IntroductionGetting StartedThe Class VariablesActivating FeaturesRequiring DependenciesInitializationSettings APICreating Form SettingsAccessing Form SettingsAdding Custom Settings to the Main Form Settings TabCreating Plugin SettingsAccessing Plugin SettingsEnqueuing Scripts and StylesResults PageEntry MetaObject Locking APIUninstallingSample Add-On

Introduction

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

InitializationEnforcing Gravity Forms minimum version requirementCreating settings pages (add-on and form settings)Permissions and integration with the Members pluginConditional script enqueuing including no-conflict mode integrationAdding custom meta fields to the entry objectCreating a results pageIntegration with the Gravity Forms Locking APIStandardization of UI elements and stylesAutomatic clean uninstall

Getting Started

These are the first steps you』ll need to take to create an add-on using the Add-On Framework:

Create two PHP files. The first file handles registering your add-on. The second file will contain your add-on』s functionality. See A Simple Add-On in the Add-On Framework article for an example.In the second PHP file you would include the Add-On Framework files by calling the following:

GFForms::include_addon_framework();

Inherit the Add-On Framework by creating a new class which extends GFAddOn:

class GFSimpleAddOn extends GFAddOn {}

Add the class variables to configure the add-on.

protected $_version = '1.0';
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';

Add support for getting an instance of the add-on. When Gravity Forms is loading it initializes the add-ons; it does this by looping through each registered add-on and calling its get_instance function. Adding a get_instance function also helps other developers integrate with your add-on.

/**
* @var object|null $_instance If available, contains an instance of this class.
*/
private static $_instance = null;

/**
* Returns an instance of this class, and stores it in the $_instance property.
*
* @return object $_instance An instance of this class.
*/
public static function get_instance() {
if ( self::$_instance == null ) {
self::$_instance = new self();
}
return self::$_instance;
}

The Class Variables

$_version string
The version of this add-on.

$_min_gravityforms_version string
The version of Gravity Forms required for this add-on.

$_slug string
A short, lowercase, URL-safe unique identifier for the add-on. This will be used in option keys, filter, actions, URLs, and text-domain localization. The maximum size allowed for the slug is 33 characters.

$_path string
Relative path to the plugin from the plugins folder. Example 「gravityforms/gravityforms.php」

$_full_path string
The physical path to the main plugin file. Set this to __FILE__

$_title string
The complete title of the Add-On.

$_short_title string
The short title of the Add-On to be used in limited spaces.

Activating Features

The Add-On Framework contains many features that can be activated by overriding functions in the base class (GFAddOn). To override a function, add a function with the same name (and arguments) as the function in the base class.

A good example of this is the plugin page. If you take a look at the code in GFAddOn you』ll see an empty function called plugin_page() that looks like this:

/**
* Override this function to create a custom plugin page
*/
protected function plugin_page() {}

This function in GFAddOn does nothing; it』s just a placeholder with documentation explaining how to use it. To activate the plugin page and add a menu link for your add-on to the Forms menu, add the following function to the add-on:

/**
* Creates a custom page for this add-on.
*/
public function plugin_page() {
echo 'This page appears in the Forms menu';
}

Now the function in the base class has been overridden, the feature has been activated, and the link to the page will appear in the Forms menu.

There are many features like this in the Add-On Framework. Please read through the documentation on this page for further details of the features and how to activate them.

Requiring Dependencies

If your Gravity Forms add-on has any requirements that might not be present everywhere, it』s a good idea to define those dependencies using the minimum_requirements() class method. Within this class method, you will be able to define things such as Gravity Forms/WordPress/PHP versions, other Gravity Forms add-ons, PHP modules, and even other plugins that your Gravity Forms add-on might require.

Example:

array(
// Require WordPress version 4.6.2 or higher.
'wordpress' => array(
'version' => '4.6.2'
),

// Require PHP version 5.3 or higher.
'php' => array(
'version' => '5.3',

// Require specific PHP extensions.
'extensions' => array(

// Require cURL version 1.0 or higher.
'curl' => array(
'version' => '1.0'
),

// Require any version of mbstring.
'mbstring',
),

// Require specific functions to be available.
'functions' => array(
'openssl_random_pseudo_bytes',
'mcrypt_create_iv'
),
),

// Require other add-ons to be present.
'add-ons' => array(

// Require any version of the Mailchimp add-on.
'gravityformsmailchimp',

// Require the Stripe add-on and ensure the name matches.
'gravityformsstripe' => array(
'name' => 'Gravity Forms Stripe Add-On'
),

// Require the PayPal add-on version 5.0 or higher.
'gravityformspaypal' => array(
'version' => '5.0'
),
),

// Required plugins.
'plugins' => array(

// Require the REST API.
'rest-api/plugin.php',

// Require Jetpack and ensure the name matches.
'jetpack/jetpack.php' => 'Jetpack by WordPress.com',
),

// Any additional custom requirements via callbacks.
array( $this, 'custom_requirement' ),
);

Initialization

The Add-On Framework provides the following functions to help with initialization and to help organize your code:

pre_init()Override this function to perform any tasks that need to be done before the WordPress action 「init」 fires   init()Override this function to perform tasks during WordPress initialization init_admin()Override this function to perform tasks only in the admin back-end init_frontend()Override this function to perform tasks only in the front-end init_ajax()Override this function to perform tasks only while processing ajax requests

IMPORTANT: call the parent function first. e.g. parent::init();

Example:

GFForms::include_addon_framework();
class GFSimpleAddOn extends GFAddOn {

// [snip: class variables]

public function pre_init() {
parent::pre_init();
// add tasks or filters here that you want to perform during the class constructor - before WordPress has been completely initialized
}

public function init() {
parent::init();
// add tasks or filters here that you want to perform both in the backend and frontend and for ajax requests
}

public function init_admin() {
parent::init_admin();
// add tasks or filters here that you want to perform only in admin
}

public function init_frontend() {
parent::init_frontend();
// add tasks or filters here that you want to perform only in the front end
}

public function init_ajax() {
parent::init_ajax();
// add tasks or filters here that you want to perform only during ajax requests
}
}

Settings API

The Add-On Framework includes a Settings API that can be used to create form and plugin settings pages. The API provides the mechanisms for rendering field UIs and saving values automatically. It supports standard field types like radio buttons, text boxes, and checkboxes and also custom field types.

See the Settings API for details about how to define sections of fields.

See the following articles for implementation examples of the various field types.

Text (『type』 => 『text』)Textarea Field (『type』 => 『textarea』)Hidden Field (『type』 => 『hidden』)Radio Field (『type』 => 『radio』)Checkbox Field (『type』 => 『checkbox』)Select Field (『type』 => 『select』)Select_Custom Field (『type』 => 『select_custom』)Field_Map Field (『type』 => 『field_map』)Field_Select Field (『type』 => 『field_select』)Dynamic_Field_Map Field (『type』 => 『dynamic_field_map』)Checkbox_And_Select Field (『type』 => 『checkbox_and_select』)Save Button (『type』 => 『save』)Custom Field Type

There are also a number of Helper Functions available for use when rendering custom settings.

Creating Form Settings

To create a tab on the Form Settings page, override the form_settings_fields() function returning an array with the configuration for the settings.

Complete example with all field types:

/**
* 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 checkbox', 'simpleaddon' ),
'type' => 'checkbox',
'name' => 'enabled',
'tooltip' => esc_html__( 'This is the tooltip', 'simpleaddon' ),
'choices' => array(
array(
'label' => esc_html__( 'Enabled', 'simpleaddon' ),
'name' => 'enabled',
),
),
),
array(
'label' => esc_html__( 'My checkboxes', 'simpleaddon' ),
'type' => 'checkbox',
'name' => 'checkboxgroup',
'tooltip' => esc_html__( 'This is the tooltip', 'simpleaddon' ),
'choices' => array(
array(
'label' => esc_html__( 'First Choice', 'simpleaddon' ),
'name' => 'first',
),
array(
'label' => esc_html__( 'Second Choice', 'simpleaddon' ),
'name' => 'second',
),
array(
'label' => esc_html__( 'Third Choice', 'simpleaddon' ),
'name' => 'third',
),
),
),
array(
'label' => esc_html__( 'My Radio Buttons', 'simpleaddon' ),
'type' => 'radio',
'name' => 'myradiogroup',
'tooltip' => esc_html__( 'This is the tooltip', 'simpleaddon' ),
'choices' => array(
array(
'label' => esc_html__( 'First Choice', 'simpleaddon' ),
),
array(
'label' => esc_html__( 'Second Choice', 'simpleaddon' ),
),
array(
'label' => esc_html__( 'Third Choice', 'simpleaddon' ),
),
),
),
array(
'label' => esc_html__( 'My Horizontal Radio Buttons', 'simpleaddon' ),
'type' => 'radio',
'horizontal' => true,
'name' => 'myradiogrouph',
'tooltip' => esc_html__( 'This is the tooltip', 'simpleaddon' ),
'choices' => array(
array(
'label' => esc_html__( 'First Choice', 'simpleaddon' ),
),
array(
'label' => esc_html__( 'Second Choice', 'simpleaddon' ),
),
array(
'label' => esc_html__( 'Third Choice', 'simpleaddon' ),
),
),
),
array(
'label' => esc_html__( 'My Dropdown', 'simpleaddon' ),
'type' => 'select',
'name' => 'mydropdown',
'tooltip' => esc_html__( 'This is the tooltip', 'simpleaddon' ),
'choices' => array(
array(
'label' => esc_html__( 'First Choice', 'simpleaddon' ),
'value' => 'first',
),
array(
'label' => esc_html__( 'Second Choice', 'simpleaddon' ),
'value' => 'second',
),
array(
'label' => esc_html__( 'Third Choice', 'simpleaddon' ),
'value' => 'third',
),
),
),
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',
),
array(
'label' => esc_html__( 'My Hidden Field', 'simpleaddon' ),
'type' => 'hidden',
'name' => 'myhidden',
),
array(
'label' => esc_html__( 'My Custom Field', 'simpleaddon' ),
'type' => 'my_custom_field_type',
'name' => 'my_custom_field',
'args' => array(
'text' => array(
'label' => esc_html__( 'A textbox sub-field', 'simpleaddon' ),
'name' => 'subtext',
'default_value' => 'change me',
),
'checkbox' => array(
'label' => esc_html__( 'A checkbox sub-field', 'simpleaddon' ),
'name' => 'my_custom_field_check',
'choices' => array(
array(
'label' => esc_html__( 'Activate', 'simpleaddon' ),
'name' => 'subcheck',
'default_value' => true,
),
),
),
),
),
),
),
);
}

/**
* Define the markup for the my_custom_field_type type field.
*
* @param array $field The field properties.
*/
public function settings_my_custom_field_type( $field ) {
echo '

' . esc_html__( 'My custom field contains a few settings:', 'simpleaddon' ) . '

';

// get the text field settings from the main field and then render the text field
$text_field = $field['args']['text'];
$this->settings_text( $text_field );

// get the checkbox field settings from the main field and then render the checkbox field
$checkbox_field = $field['args']['checkbox'];
$this->settings_checkbox( $checkbox_field );
}

/**
* The feedback callback for the 'mytextbox' setting on the plugin settings page and the 'mytext' setting on the form settings page.
*
* @param string $value The setting value.
*
* @return bool
*/
public function is_valid_setting( $value ) {
return strlen( $value ) > 10;
}

The code above will create a tab on the Form Settings page for the Simple Add-On and look similar to the following:

Accessing Form Settings

The form settings for the current add-on can be accessed easily by using the function get_form_settings($form). This returns an associative array with the settings for the current add-on for the given form.

Example:

$settings = $this->get_form_settings( $form );

Adding Custom Settings to the Main Form Settings Tab

To add a custom setting to the main form settings tab, please consult the documentation for the gform_form_settings hook. Here』s a quick example of how you』d implement it with the Add-On Framework:

GFForms::include_addon_framework();
class GFSimpleAddOn extends GFAddOn {

// [snip: class variables]

public function init() {
parent::init();
add_filter( 'gform_form_settings', array( $this, 'my_custom_form_setting' ), 10, 2 );
add_filter( 'gform_pre_form_settings_save', array( $this, 'save_my_custom_form_setting' ) );
}

function my_custom_form_setting( $settings, $form ) {
$settings['Form Basics']['my_custom_setting'] = '

';

return $settings;
}

function save_my_custom_form_setting( $form ) {
$form['my_custom_setting'] = rgpost( 'my_custom_setting' );
return $form;
}
}

Creating Plugin Settings

Plugin settings pages appear in a tab in the Gravity Forms settings page. To create a settings page, override the plugin_settings_fields() function using the same array structure as described above for the form settings.

Example:

/**
* 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' ),
)
)
)
);
}
[/php]

Accessing Plugin Settings

The plugin settings for the current add-on can be accessed easily by using the following functions:

get_plugin_settings()returns all plugin settings in an associative array   get_plugin_setting( $setting_name )returns a single setting with the given setting name e.g. 「my_setting_name」

Example:

$all_plugin_settings = $this->get_plugin_settings();
$text = $this->get_plugin_setting( 'mytextbox');

Enqueuing Scripts and Styles

See the Including Scripts and Styles When Using the Add-on Framework article.

Results Page

To add a results page, override the get_results_page_config() function and return the configuration array with the following properties:

title string
The title of the results page.

capabilities array
An array of capabilities that can view the results page.

callbacks array
An array of callback functions. Possible values: fields, markup, calculation

Example:

public function get_results_page_config() {
return array(
'title' => 'Poll Results',
'capabilities' => array( 'gravityforms_polls_results' ),
'callbacks' => array(
'fields' => array( $this, 'results_fields' )
)
);
}

public function results_fields( $form ) {
return GFAPI::get_fields_by_type( $form, array( 'poll' ) );
}
[/php]

Entry Meta

See the Including and using Entry Meta with the Add-On Framework article.

Object Locking API

The Gravity Forms Object Locking API prevents conflicts from occurring by preventing concurrent editing by different users of forms, entries, form settings and plugin settings. This eliminates the problem of users overwriting the changes made be other users. When one user is editing an object, the second user will be offered the choice to request control over the object. The first user will then be offered the choice to accept or deny that request. If the first user fails to respond, the second user will be offered control.

The Locking API uses the WordPress Heartbeat API to send updates at regular intervals, usually every 15 seconds when the page has focus, and every 2 minutes when the page doesn』t have the focus.

The Add-On Framework provides developers access to the Object Locking API in 2 ways:

Locking is automatically implemented for form settings and plugin settings – nothing additional is required for this to work.  Locking for custom objects. For example, an add-on that manages employee information may have an 「employee」 object. The Add-On Framework will prevent concurrent editing of the employee profile.

Locking is activated by overriding the following functions:

get_locking_config()Return an array with the locking configuration to activate locking   get_locking_object_id()Return the object id is_locking_edit_page()Return true if the current page is the edit page is_locking_view_page()Return true if the current page is the view page is_locking_list_page()Return true if the current page is the list page

public function get_locking_config(){
$strings = array(
"currently_locked" => __('This contact is currently locked. Click on the "Request Control" button to let %s know you'd like to take over.', "gravityforms"),
"currently_editing" => "%s is currently editing this contact",
"taken_over" => "%s has taken over and is currently editing this contact.",
"lock_requested" => __("%s has requested permission to take over control of this contact.", "gravityforms")
);
$contact_id = $this->get_object_id();
$config = array(
"object_type" => "contact",
"capabilities" => array("gravityforms_contacts_edit_contacts"),
"redirect_url" => admin_url(sprintf("admin.php?page=gf_contacts&view=contact&subview=profile&id=%d&edit=0", $contact_id)),
"edit_url" => admin_url(sprintf("admin.php?page=gf_contacts&view=contact&subview=profile&id=%d&edit=1", $contact_id)),
"strings" => $strings
);
return $config;
}
public function get_locking_object_id(){
return rgget("id");
}
public function is_locking_edit_page(){
$is_edit_page = rgget("page") == "gf_contacts" && rgget("view") == "contact" && rgget("subview") == "profile" && rgget("edit") == 1;
return $is_edit_page;
}
public function is_locking_view_page(){
$is_view_page = rgget("page") == "gf_contacts" && rgget("view") == "contact" && rgget("subview") == "profile" && rgget("edit") == 0;
return $is_view_page;
}
public function is_locking_list_page(){
$is_list_page = rgget("page") == "gf_contacts" && rgempty("view", $_GET);
return $is_list_page;
}

Uninstalling

All Gravity Forms Add-Ons should provide a way to remove settings completely before the user deactivates and deletes the plugin. The Add-On Framework handles much of this for you so you don』t need to configure anything unless you』ve added settings or database tables of your own. The uninstall button will be on the plugin settings page. The following elements will be removed automatically when the user uninstalls the add-on.

Form settingsPlugin settingsEntry metaVersion information

If you need to perform additional tasks such as removing custom options or database tables then override the uninstall() function. This will be called after permissions have been checked and before removing all the settings.

Example:

public function uninstall() {
// custom code to drop database tables and remove custom options
}

The uninstall section of the settings page can be modified or removed completely by overriding the render_uninstall() function.

Example:

public function render_uninstall() {
// an empty function will remove the uninstall section on the settings page
}

Sample Add-On

A sample add-on is available which demonstrates the basic features of the Add-On Framework:

Plugin pageForm SettingsPlugin SettingsScripts and Styles

https://github.com/rocketgenius/simpleaddon

GFCoupons

GFCoupons

gf_coupons()get_submitted_coupon_codes()get_coupons_by_codes()insert_feed()

GFCoupons is the class which houses the main functionality of the Gravity Forms Coupons Add-on, it extends the GFFeedAddOn class which is part of the add-on framework. Below are a few functions which you may find useful when working on your own custom code.
gf_coupons()
The gf_coupons() function is used to return an instance of the GFCoupons class.
get_submitted_coupon_codes()
Retrieves any submitted coupon codes from the entry object.
$coupon_codes = gf_coupons()->get_submitted_coupon_codes( $form, $entry );

$form Form Object
The form object currently being processed.

$entry Entry Object
The entry object currently being processed.

Returns array | boolean
An array of coupon codes or false if no codes were submitted.

get_coupons_by_codes()
Retrieves the properties for the specified coupon codes.
$coupons = gf_coupons()->get_coupons_by_codes( $codes, $form );

$codes string | array
The codes for the coupons to be retrieved.

$form Form Object
The form object currently being processed.

Returns array|boolean
An associative array with the coupon code as key to the array containing that coupons properties. False if no coupon feeds were found.

insert_feed()
The insert_feed() method can be used to add new coupons.
$feed_id = gf_coupons()->insert_feed( $form_id, $is_active, $meta );

$form_id integer
The ID of the form this coupon can be used with or 0 if it can be used with all forms.

$is_active boolean
Is this coupon active or inactive.

$meta Coupons Feed Meta
An associative array containing the properties which determine the type of coupon and discount available.

Returns integer
The ID of the new feed.

GFFeedAddOn

GFFeedAddOn

IntroductionCreating Feed SettingsFeed Settings Fields ExampleDynamic Feed MappingAdding Columns to Feed ListAdding Columns to Feed List ExampleProcessing FeedsImplementing a Feed Condition SettingFeed Condition Field ExamplesAsynchronous Feed ProcessingGFFeedAddOn $_async_feed_processing Propertygform_is_feed_asynchronous FilterFurther ReadingSample Feed Add-On

Introduction

The GFFeedAddOn class provides basic functionality for developers when creating new feed-based add-ons for Gravity Forms. It includes all the features of the GFAddOn class with one exception; the Form Settings are replaced by the Feed Settings UI.

Before reading any further please review the documentation for creating a simple add-on using the GFAddOn class.

Settings APICreating Plugin SettingsIncluding Scripts And Styles When Using The Add-On FrameworkIncluding And Using Entry Meta With The Add-On FrameworkObject LockingCreating a Results PageUninstalling

Creating Feed Settings

The feed settings UI is generated by overriding the feed_settings_fields() function and returning an array with the configuration for each of the fields. The configuration array follows the same structure as the form settings configuration. See the Settings API for further details on the structure of the array.

Feed Settings Fields Example

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142public function feed_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'                        )                     )                ),                array(                    'label'   => 'My checkboxes',                    'type'    => 'checkbox',                    'name'    => 'checkboxgroup',                    'tooltip' => 'This is the tooltip',                    'choices' => array(                        array(                            'label' => 'First Choice',                            'name'  => 'first'                        ),                        array(                            'label' => 'Second Choice',                            'name'  => 'second'                        ),                        array(                            'label' => 'Third Choice',                            'name'  => 'third'                        )                    )                ),                array(                    'label'   => 'My Radio Buttons',                    'type'    => 'radio',                    'name'    => 'myradiogroup',                    'tooltip' => 'This is the tooltip',                    'choices' => array(                        array(                            'label' => 'First Choice'                        ),                        array(                            'label' => 'Second Choice'                        ),                        array(                            'label' => 'Third Choice'                        )                    )                ),                array(                    'label'      => 'My Horizontal Radio Buttons',                    'type'       => 'radio',                    'horizontal' => true,                    'name'       => 'myradiogrouph',                    'tooltip'    => 'This is the tooltip',                    'choices'    => array(                        array(                            'label' => 'First Choice'                        ),                        array(                            'label' => 'Second Choice'                        ),                        array(                            'label' => 'Third Choice'                        )                    )                ),                array(                    'label'   => 'My Dropdown',                    'type'    => 'select',                    'name'    => 'mydropdown',                    'tooltip' => 'This is the tooltip',                    'choices' => array(                        array(                            'label' => 'First Choice',                            'value' => 'first'                        ),                        array(                            'label' => 'Second Choice',                            'value' => 'second'                        ),                        array(                            'label' => 'Third Choice',                            'value' => 'third'                        )                    )                ),                array(                    'label'             => 'My Text Box',                    'type'              => 'text',                    'name'              => 'mytext',                    'tooltip'           => 'This is the tooltip',                    'class'             => 'medium',                    'feedback_callback' => array( $this, 'is_valid_setting' )                ),                array(                    'label'   => 'My Text Area',                    'type'    => 'textarea',                    'name'    => 'mytextarea',                    'tooltip' => 'This is the tooltip',                    'class'   => 'medium merge-tag-support mt-position-right'                ),                array(                    'label'   => 'My Hidden Field',                    'type'    => 'hidden',                    'name'    => 'myhidden'                ),                array(                    'label'   => 'My Custom Field',                    'type'    => 'my_custom_field_type',                    'name'    => 'my_custom_field'                ),                array(                    'type'           => 'feed_condition',                    'name'           => 'mycondition',                    'label'          => __( 'Opt-In Condition', 'simplefeedaddon' ),                    'checkbox_label' => __( 'Enable Condition', 'simplefeedaddon' ),                    'instructions'   => __( 'Process this example feed if', 'simplefeedaddon' )                ),            )        ),        array(            'title'  => esc_html__( 'This is the title for Section 1', 'sometextdomain' ),            'fields' => array(                array(                    'name'                => 'metaData',                    'label'               => esc_html__( 'Metadata', 'sometextdomain' ),                    'type'                => 'dynamic_field_map',                    'limit'               => 20,                    'exclude_field_types' => 'creditcard',                    'tooltip'             => '

' . esc_html__( 'Metadata', 'sometextdomain' ) . '

' . esc_html__( 'You may send custom meta information to [...]. A maximum of 20 custom keys may be sent. The key name must be 40 characters or less, and the mapped data will be truncated to 500 characters per requirements by [...]. ', 'sometextdomain' ),                    'validation_callback' => array( $this, 'validate_custom_meta' ),                ),            ),        ),    );}

The code above will render a Form Settings page for the Simple Add-On similar to this:

Dynamic Feed Mapping

Dynamic feed mapping can be used to create fields which automatically map to values in the form. For example, if you need to create a feed that uses information such as a first name and last name, field mapping would be used to map the form fields to those values.

A dynamically mapped field can be implemented just like many of the other feed settings fields and setting the setting field type to dynamic_field_map. Adding a feed section containing dynamically mapped fields would look something like the following:

1234567891011121314array(    'title'  => esc_html__( 'This is the title for Section 1', 'sometextdomain' ),    'fields' => array(        array(            'name'                => 'metaData',            'label'               => esc_html__( 'Metadata', 'sometextdomain' ),            'type'                => 'dynamic_field_map',            'limit'               => 20,            'exclude_field_types' => 'creditcard',            'tooltip'             => '

' . esc_html__( 'Metadata', 'sometextdomain' ) . '

' . esc_html__( 'You may send custom meta information to [...]. A maximum of 20 custom keys may be sent. The key name must be 40 characters or less, and the mapped data will be truncated to 500 characters per requirements by [...]. ', 'sometextdomain' ),            'validation_callback' => array( $this, 'validate_custom_meta' ),        ),    ),)

More information on the dynamic_field_map field type can be found on the dynamic_field_map Field documentation.

Adding Columns to Feed List

To add columns to the list of feeds, override the feed_list_columns() function and return an array of column keys with their corresponding titles. The values will be rendered to the list automatically, but if you need to customize the value just before it is rendered to the list, declare a function with the name get_column_value_[column key] and pass the $feed object as a parameter to the function. The feed object is an associative array with the keys as defined in feed_settings_fields() with the corresponding values for the current row.

Adding Columns to Feed List Example

This example adds two columns to the feed list. The columns are titled 「Name」 and 「My Textbox」. The get_column_value_mytext function returns the value for the 「mytext」 field as bold text.

1234567891011protected function feed_list_columns() {    return array(        'feedName' => __( 'Name', 'simplefeedaddon' ),        'mytext'   => __( 'My Textbox', 'simplefeedaddon' )    );} // customize the value of mytext before it is rendered to the listpublic function get_column_value_mytext( $feed ){    return '' . rgars( $feed, 'meta/mytext' ) . '';}

The code above will render a Feed List page similar to the following:

Processing Feeds

Override the process_feed() method to add code to handle feed processing, such as passing the form entry values to a third-party service.

1public function process_feed( $feed, $entry, $form ) {}

We recommend using get_field_value() to retrieve the entry value for a mapped field e.g.

1$email = $this->get_field_value( $form, $entry, $feed['meta']['listFields_email'] );

Implementing a Feed Condition Setting

A feed condition setting is a feed setting that automatically adds an optional conditional logic setting to the feed. The field is configured just like the other fields (see the Settings API) with the the following properties:

type string『feed condition』name stringThe name for the setting.label stringThe label for the feed condition setting.checkbox_label stringThe label that appears to the right of the checkbox used to enable the condition. If this is not set, the default translated string 「Enable Condition」 is used.instructions stringThe instruction text appears above the conditional logic drop downs, is followed by the All/Any drop down selection, and the translated text 「of the following match」. If you do not specify instruction text, the text 「Process this feed if」 is used.

Feed Condition Field Examples

This is a simple example that uses the basic settings to create the feed condition field.

12345array(    'type'  => 'feed_condition',    'name'  => 'sample_condition',    'label' => 'Feed Condition',)

The code above will render the feed condition field as follows:

This example includes setting the checkbox_label and instructions.

1234567array(    'type'           => 'feed_condition',    'name'           => 'mycondition',    'label'          => __( 'Opt-In Condition', 'simplefeedaddon' ),    'checkbox_label' => __( 'Enable Condition', 'simplefeedaddon' ),    'instructions'   => __( 'Process this example feed if', 'simplefeedaddon' ))

The code above will render the feed condition field as follows:

Asynchronous Feed Processing

As of Gravity Forms version 2.2, feeds can be loaded asynchronously. This means that instead of processing all of the feeds at once, the feeds will be loaded individually.

GFFeedAddOn $_async_feed_processing Property

To load a feed asynchronously, set the $_async_feed_processing property within the GFFeedAddOn class to true.

Example:

123class My_Feed_AddOn extends GFFeedAddOn {    public $_async_feed_processing = true;}

gform_is_feed_asynchronous Filter

Example:

1add_filter( 'gform_is_feed_asynchronous'. '__return_true' );

See gform_is_feed_asynchronous

Further Reading

The following articles may also be useful:

Sending Notifications on Custom Events when using the Add-On FrameworkAdding a Note to the Entry when using the Add-On FrameworkAccessing Mapped Field Values During Feed Processing

Sample Feed Add-On

A sample feed add-on is available which demonstrates the basic functions of GFFeedAddOn:

Feed settings including feed conditionsPlugin pagePlugin SettingsScripts and Styles

https://github.com/rocketgenius/simplefeedaddon

gform_action_pre_payment_callback

gform_action_pre_payment_callback

DescriptionUsageParametersExamplesSource Code

Description
Runs a function after payment, before the callback occurs.
Usage
1add_action( 'gform_action_pre_payment_callback', 'my_function', 10, 2 );

Parameters

$action array
Array for the payment action triggered.

$entry Entry Object
Entry object for the new entry.

Examples
123456function my_function($action, $entry) {    if( $action['type'] == 'complete_payment' ) {        // Do something    }}add_action( 'gform_action_pre_payment_callback', 'my_function', 10, 2 );
Source Code
1do_action( 'gform_action_pre_payment_callback', $action, $entry );
This action hook is located in GFPaymentAddOn::process_callback_action() in includes/addon/class-gf-payment-addon.php.

gform_activate_user

gform_activate_user

DescriptionUsageParametersExamplePlacementSource Code

Description
The 「gform_activate_user」 action fires after a user signup has been activated. This action is used in the User Registration plugin for Gravity Forms.
Usage
1add_action( 'gform_activate_user', 'your_function_name, 10, 3 );

Parameters

$user_id int
The user id of the signup user just activated.

$user_data array
An array of the user information.

$signup_meta array
All the metadata in an array (user login, email, password, etc.)

Example
12345add_action( 'gform_activate_user', 'after_user_activate', 10, 3 );function after_user_activate( $user_id, $user_data, $signup_meta ) {    //add note to entry    GFFormsModel::add_note( $signup_meta['lead_id'], $user_id, 'admin', 'The user signup has completed for ' . $user_data['display_name'] . '.');}
Placement
This code should be placed in the functions.php file of your active theme.
Source Code
This action is located in GF_User_Registration::activate_signup() in gravityformsuserregistration/includes/signups.php.

Getting Started: A Checklist for the New User

Getting Started: A Checklist for the New User

Welcome To Gravity Forms!The BasicsExpanding Further

Welcome To Gravity Forms!
Getting started with Gravity Forms is a simple process, but there are a few steps you need to take. If you』re already familiar with installing WordPress plugins, you』re already ahead of the game.
In this article we have a checklist of the things you will need to do from the first moment you decide to use Gravity Forms, and links to a selection of the articles that can help you do it!
The Basics

Review our system requirements.
Purchase and pay for a Gravity Forms license key, which will then add your new license key to your Gravity Forms account. If you need to try out some functionality first, you can experiment with our fully functional online demo.
Download the Gravity Forms plug-in from your account.
Install the Gravity Forms plug-in.
Enter your license key into your plugin Settings to validate your installation of Gravity Forms.
Create your first form, and then start testing it out in the preview view, or add it to your test site and experiment!

You are up and running!
Expanding Further
Next steps or areas you might be interested in could include:

setting up notifications and confirmations.
reviewing your form submission, which Gravity Forms calls entries.
experimenting with more advanced fields.
extend your capabilities with our official add-ons or our community contributed third party add-ons!

Whatever you might need for your sites, Gravity Forms (and our online documentation) can help!

Getting the Form Field Filters with REST API v2

Getting the Form Field Filters with REST API v2

IntroductionMethodPathRequired PropertiesOptional PropertiesResponse [json]Usage ExamplesExample 1Example 2

Introduction
The field-filters endpoint was added in Gravity Forms 2.4.21.8, it returns the field filters for the specified form. Internally Gravity Forms uses the field filters to populate the search drop down on the entries list page and the filter condition settings on the sales/results pages. You can use the response from this endpoint to create similar features on remote sites or simply use it to help determine which keys and operators to use with the field_filters array of the GET entries search property.
Method
This endpoint only accepts GET requests.
Path
/gf/v2/forms/[FORM_ID]/field-filters
Required Properties
There are no required properties.
Optional Properties

_admin_labels – Use the value 「1」 to include the field admin labels in the response, if configured.

Response [json]
The response will contain a JSON object which contains the field filters for the specified form. Examples can be found below.
Usage Examples
Example 1
This example shows how to get the field filters for form id 577.

Example 2
This example shows how to get the field filters for form id 577 using the field admin labels, if configured.

Obtaining Your Agile CRM API Key

Obtaining Your Agile CRM API Key

When using the Agile CRM Add-On for Gravity Forms, you will need to be able to authenticate with Agile CRM from your site. In this article, we will show you how to obtain your Agile CRM API key.

Log into your Agile CRM account.
From the top right of your main Agile CRM dashboard page, click on your name/icon, then click on Admin Settings.
From the left-hand menu, click on Developers & API. You will see your API key as well as your Javascript API key for tracking.