Using EDD Software Licensing with the Add-On Framework

Using EDD Software Licensing with the Add-On Framework

IntroductionThe ConstantsThe License Key SettingValidating the License KeyActivating and Deactivating the License KeyPerform the Remote RequestPlugin UpdatesImportant

Introduction

In this article we will show how you can integrate your add-on with the Easy Digital Downloads Software Licensing extension to handle license key activation, deactivation, validation, and enabling access to automatic updates.

Before reading on we do recommend you read the following articles from the EDD documentation:

Activating License Keys in WP Plugins and ThemesDeactivating License Keys in WP Plugins and ThemesAutomatic Upgrades for WordPress Plugins

The following examples are based on the Simple Add-On from the Add-On Framework article.

The Constants

Some of the arguments used in the various requests to the EDD Software Licensing API are identical so we are going to store their values in constants.

In our Simple Add-On we have already defined the add-on version number (GF_SIMPLE_ADDON_VERSION) in the root file so we will add our two new constants there.

define( 'GF_SIMPLE_ADDON_VERSION', '2.0' );
define( 'GF_SIMPLE_ADDON_EDD_SL_STORE_URL', 'http://yoursite.com' );
define( 'GF_SIMPLE_ADDON_EDD_SL_ITEM_NAME', 'Simple Add-On' );

GF_SIMPLE_ADDON_EDD_SL_STORE_URL is the URL of the site where you have installed the Easy Digital Downloads plugin and Software Licensing extension.

GF_SIMPLE_ADDON_EDD_SL_ITEM_NAME is the name of the product as you have configured it in EDD.

The License Key Setting

The plugin_settings_fields() function of our example add-on had a simple text field named mytextbox. In the following example we have replaced that field with a new text field named license_key which will use a password type input to capture the license key.

/**
* 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' => 'license_key',
'label' => esc_html__( 'License Key', 'simpleaddon' ),
'type' => 'text',
'input_type' => 'password',
'validation_callback' => array( $this, 'license_validation' ),
'feedback_callback' => array( $this, 'license_feedback' ),
'error_message' => esc_html__( 'Invalid license', 'simpleaddon' ),
'class' => 'large',
'default_value' => '',
),
),
),
);
}

Review the Settings API documentation for more details about how to define sections of fields.

Validating the License Key

The example below shows the function assigned to the feedback_callback property of the license_key field. This function runs when the markup for the text field is being prepared on page display so the validation check can determine which icon is displayed next to the field.

/**
* Determine if the license key is valid so the appropriate icon can be displayed next to the field.
*
* @param string $value The current value of the license_key field.
* @param array $field The field properties.
*
* @return bool|null
*/
public function license_feedback( $value, $field ) {
if ( empty( $value ) ) {
return null;
}

// Send the remote request to check the license is valid
$license_data = $this->perform_edd_license_request( 'check_license', $value );

$valid = null;
if ( empty( $license_data ) || $license_data->license == 'invalid' ) {
$valid = false;
} elseif ( $license_data->license == 'valid' ) {
$valid = true;
}

return $valid;
}

Activating and Deactivating the License Key

The example below shows the function assigned to the validation_callback property of the license_key field. This function runs when the plugin settings are saved. It will deactivate the old license key if the posted value doesn』t match the value found in the existing settings. It will also activate the new license key.

/**
* Handle license key activation or deactivation.
*
* @param array $field The field properties.
* @param string $field_setting The submitted value of the license_key field.
*/
public function license_validation( $field, $field_setting ) {
$old_license = $this->get_plugin_setting( 'license_key' );

if ( $old_license && $field_setting != $old_license ) {
// Send the remote request to deactivate the old license
$this->perform_edd_license_request( 'deactivate_license', $old_license );
}

if ( ! empty( $field_setting ) ) {
// Send the remote request to activate the new license
$this->perform_edd_license_request( 'activate_license', $field_setting );
}
}

Perform the Remote Request

The following example shows the helper being used by the license_feedback() and license_validation() functions to send the license key validation, activation, and deactivation requests to your EDD store url.

/**
* Send a request to the EDD store url.
*
* @param string $edd_action The action to perform (check_license, activate_license, or deactivate_license).
* @param string $license The license key.
*
* @return object
*/
public function perform_edd_license_request( $edd_action, $license ) {
// Prepare the request arguments
$args = array(
'timeout' => 10,
'sslverify' => false,
'body' => array(
'edd_action' => $edd_action,
'license' => trim( $license ),
'item_name' => urlencode( GF_SIMPLE_ADDON_EDD_SL_ITEM_NAME ),
'url' => home_url(),
),
);

// Send the remote request
$response = wp_remote_post( GF_SIMPLE_ADDON_EDD_SL_STORE_URL, $args );

return json_decode( wp_remote_retrieve_body( $response ) );
}

Plugin Updates

Adding support for automatic updates is very simple. If you have read the EDD documentation on the subject you will know that the EDD Software Licensing plugin includes a sample plugin containing a file named EDD_SL_Plugin_Updater.php. You will want to include a copy of this file with your add-on.

Next, return to your add-ons root file and add the following to the end of the file.

add_action( 'init', 'gf_simple_addon_edd_plugin_updater', 0 );
function gf_simple_addon_edd_plugin_updater() {

if ( ! class_exists( 'EDD_SL_Plugin_Updater' ) ) {
// load our custom updater if it doesn't already exist
include( dirname( __FILE__ ) . '/EDD_SL_Plugin_Updater.php' );
}

// retrieve the license key
$license_key = trim( gf_simple_addon()->get_plugin_setting( 'license_key' ) );

// setup the updater
$edd_updater = new EDD_SL_Plugin_Updater( GF_SIMPLE_ADDON_EDD_SL_STORE_URL, __FILE__, array(
'version' => GF_SIMPLE_ADDON_VERSION,
'license' => $license_key,
'item_name' => GF_SIMPLE_ADDON_EDD_SL_ITEM_NAME,
'author' => 'John Doe'
)
);

}

That』s all there is to it! As long as the license key entered on the plugin settings page is valid and active, the add-on will have access to updates.

Important

The GFAddon class includes a protected variable named $_enable_rg_autoupgrade which is set to false.

The $_enable_rg_autoupgrade variable is not intended for use in third-party add-ons. It is only used by add-ons developed by Rocketgenius, Inc. to include the class-gf-auto-upgrade.php file which handles integrating the add-ons with our licensing and updates system.

All other add-ons should leave the $_enable_rg_autoupgrade variable set to false.

Forms List Page

Forms List Page

Filter ToolbarSorting OptionsForm Quick ToolbarForm ActionsBulk Actions

The forms list page displays a list of all your forms. From this page you can manage and edit your existing forms and get a quick rundown on basic analytics such as views, number of entries, and the conversation ratio.

Filter Toolbar

The filter toolbar allows you to filter which forms you would like to view: All, Active, Inactive, and Trash. In the parenthesis beside each filter label is the number of forms currently applicable to that filter. By default All forms will be displayed, although you can select to view only Active or Inactive forms.

Sorting Options

StatusTo the left of the form name is the status icon. By default this is checked, which activates the form. To inactivate a form, simply click on the status icon to change the status.

TitleThis is the form name. It is editable by using the form editor.

IDThis is the form id. You can use this for displaying the form via the shortcode or function call.

EntriesThe number of times a form entry has been created by submitting the form.

ViewsThe number of times a form has been viewed.

ConversionThe ratio of entries to views, expressed as a percentage. Note that form previews do not count as views, but entries submitted by a form preview do count as an entry.

Form Quick Toolbar

Each form has a toolbar that displays when you hover over the first cell of a form row. This quick toolbar will allow you to edit the form, view the form settings, view the form entries, preview the form, make a copy of the form, or send the form to the trash to be deleted later.

Animation showing the quick toolbar available by hovering over a form title.

Form Actions

The following form actions are available per form in the Form Quick Toolbar by hovering over a form in the list.

EditEdit the form using the form editor.

SettingsThis deals with all of the settings of your form such as Form Settings, Confirmations, and Notifications.

PreviewPreview the form to see how it will look to the enduser. This can also be used to submit an entry or test.

EntriesView the entries for this form.

DuplicateCreate a duplicate of this form. Duplication includes all form, field, and notification settings.

TrashChoosing this option will send the form to the Trash.

Bulk Actions

Using bulk actions you may apply the same action to multiple forms at once. To use bulk actions, you must first select the checkbox next to each form you would like to modify. Then select the desired action from the Bulk Actions drop down list, and click 「Apply.」

The following bulk actions are available:

Mark as Active/InactiveMark all selected forms as active/inactive.

Reset ViewsReset the counter for the number of times a form has been viewed.

Permanently Delete EntriesDelete all of the entries associated with the selected form. These entries cannot be restored.

Move to trashSend the selected forms to the Trash.

The short animation shows the application of a bulk action.

Email Field CSS Selectors

Email Field CSS Selectors

ContainerInput

Container
example: email field container (div) – applies to all forms
1body .gform_wrapper .gform_body .gform_fields .gfield .ginput_container_email {border: 1px solid red;}
example: email field container (div) – applies just to form ID #1
1body #gform_wrapper_1 .gform_body .gform_fields .gfield .ginput_container_email {border: 1px solid red;}
example: email field container (div) – applies just to specific container (based on the unique parent element ID – replace 「XX_X」 with your actual element ID)
1body #gform_wrapper_1 .gform_body .gform_fields #field_XX_X.gfield .ginput_container_email {border: 1px solid red;}
Input
example: email field input (input) – applies to all forms
1body .gform_wrapper .gform_body .gform_fields .gfield .ginput_container_email input {border: 1px solid red;}
example: email field input (input) – applies just to form ID #1
1body #gform_wrapper_1 .gform_body .gform_fields .gfield .ginput_container_email input {border: 1px solid red;}
example: email field input (input) – applies just to specific container (based on the unique parent element ID – replace 「XX_X」 with your actual element ID)
1body #gform_wrapper_1 .gform_body .gform_fields #field_XX_X.gfield .ginput_container_email input {border: 1px solid red;}

Email Routing in Gravity Forms Notifications

Email Routing in Gravity Forms Notifications

IntroductionConfigurationTroubleshooting

Introduction

Within each Gravity Forms notification, you have the option of configuring additional routing. This is similar to conditional logic, in that different events can cause the notification to go to a different recipient. But unlike conditional logic, Routing can』t prevent the notification processing, it only provides the email address to be used for the Send To setting, therefore it』s important to make sure your routing rules will cover all the possible user choices to prevent scenarios where your routing setup doesn』t provide any email address and therefore the notification is processed with an empty value for the Send To.

In this article, we will show you how to configure routing options within your notification.

Configuration

This short animation shows how to access and modify Notifications for a form.

First, start by accessing the notification that you want to configure additional routing for. This can be done by accessing the form associated with the notification, hovering over Settings, clicking on Notifications, and then accessing the notification you want to manage. If you want to create a new notification, simply click the Add New button. Within the settings for your notification, you will see an option labeled Send To. If you select Configure Routing, additional options similar to conditional logic will appear. Inside the routing configuration, the first thing you will need to do is determine where the notification will be sent if the routing condition is met. Simply enter the email address of the user that you want to send the notification. Next, you』ll need to configure the field that the routing condition will use. To do so, use the dropdown box to select the field that the condition will be based on. Now that the field is selected, you』ll need to set the operator used to compare the field and value. For example, if you only want to send this notification if a particular radio button is checked, you would select is within the operator dropdown. Conversely, if you do not want a notification to be sent when that radio button field is selected, you would use is not. Finally, you』ll need to set the value that will be used to compare against the field submission result. If using pre-selected options, this will appear as a dropdown. If the field is something like a text field where the user will enter their own value, the condition value will appear as a text box. Within the condition value, enter the value to compare with the submission. If you want to add additional conditions or remove a condition, use the + and – icons to the right of the condition item to either add or remove it.

You can now continue configuring your notification as seen fit.

Troubleshooting

If Routing rules are not working as you expected there is a high likelihood that you』re facing one of the following:

You added or modified field values after configuring Routing. Routing rules are based on existing values when you saved them, if you use a choices field like a Drop Down for your Routing rules, and you change any of these field choices after configuring Routing, you need to update your Routing rules to select the new or modified choice(s) and save your notification settings. It doesn』t matter if you just changed a single character, any change done to choices used in your Routing rules matters. The following screenshot shows an example of an outdated Routing rule, when it was configured the choice selected was Jim, but currently, that choice no longer exists, the Drop Down was edited and Jim was replaced by Samuel, therefore, the Routing rule will not work. Your routing rules are not covering all the possible user selection. If your Routing rules are based on a drop down that has three choices, but you only have Routing rules added for two of the choices, the notification will fail when the user selects the third choice without a matching Routing rule.

Email Tracking with Mailgun

Email Tracking with Mailgun

In addition to being able to send your notifications using Mailgun, the Mailgun Add-On also includes the ability to integrate with Mailgun』s email tracking. With email tracking, you』ll be able to see if the notification was opened or links were clicked, allowing for better management of your notifications. In this article, we』ll show you how to enable email tracking in the Mailgun add-on for Gravity Forms.

Access the form notification that is configured to use Mailgun. If you don』t already have a notification that is using Mailgun, see our article on sending form notifications with Mailgun.Scroll down in the settings until you see an option labeled Email Tracking.To enable tracking of link clicks, check the checkbox labeled Enable click tracking for this notification.To enable tracking of who has opened your form notifications, check the checkbox labeled Enable open tracking for this notification.Once complete, save your notification settings.

That』s all there is to it! With tracking settings enabled, you will be able to better track if a form notification is opened or a link within the notification is clicked.

Email Tracking with Postmark

Email Tracking with Postmark

By using the Postmark Add-On to send form notifications, you have the ability to take advantage of additional email features within Postmark. These features include the ability to track data within the form notifications, such as if the notification has been opened. In this article, we』ll show you how to enable tracking within your form notifications.

Access the form notification that is configured to use Postmark. If you don』t already have a notification that is using Postmark, see our article on sending form notifications with Postmark.Scroll down in the settings until you see an option labeled Email Tracking.Check the box labeled Enable open tracking for this notification to enable tracking of who has opened your form notifications.Save your settings.

That』s all there is to it! With tracking settings enabled, you will be able to better track if a form notification has been opened.

Email

Email

SummaryCommon SettingsGeneral SettingsMerge TagsUsageModifiers

Summary

The Email field allows you to present a field that captures email data. It is available under the Advanced Fields section within the form editor.

Email field as displayed in the Field Library

Email field as displayed in the Form Editor.

Common Settings

This field uses only common field settings for the Appearance and Advanced settings. For a description of each of the common field settings, refer to this article. Below you will find description of specialty settings that are particular to this field.

General Settings

SettingDescriptionEnable Email ConfirmationPrompts the user to confirm the email address.

Merge Tags

For more information on the use of merge tags, refer to these articles.

Usage

{Field Name:2}

Modifiers

This merge tag does not have any modifiers.

EmailOctopus Change Log

EmailOctopus Change Log

1.2 | 2020-09-081.1 | 2020-03-161.0 | 2020-01-15

1.2 | 2020-09-08

Added support for Gravity Forms 2.5.

1.1 | 2020-03-16

Added translation files
Fixed a PHP notice and warning which occur when editing an existing feed when the add-on is connected to a different EmailOctopus account.

1.0 | 2020-01-15

It's all new!

{embed_post} Merge Tag

{embed_post} Merge Tag

SummaryUsageMember VariablesExamples

Summary

Displays the member-variable data specified for the singular post or page from which the entry was submitted.

Note: This is not designed for use with forms embedded on blog or archive type pages.

Usage

{embed_post:[member_variable]}

Member Variables

For a list of all the member variables of a post object that you can use in your merge tag, review this WordPress reference document.

Examples

ExampleDescription{embed_post:ID}Display the ID of the post/page.{embed_post:post_title}Display the title of the post/page.{embed_post:post_author}Display the author ID of the post/page.

Below is a confirmation created with the above example merge tags:

This is what the user will see when they submit the form:

{embed_url} Merge Tag

{embed_url} Merge Tag

SummaryUsage

Summary
The {embed_url} merge tag in Gravity Forms displays the URL from which the form was submitted. Gravity Forms uses merge tags to allow you to dynamically populate submitted field values and other dynamic information in notification emails, post content templates and more.
Usage
{embed_url}