gform_addon_feed_settings_fields

Description

Filter the feed settings fields (typically before they are rendered on the Feed Settings edit view).

Usage

The base filter which would run for all add-on feeds would be used like so:

add_filter( 'gform_addon_feed_settings_fields', 'your_function_name', 10, 2 );

You can target a specific add-on with the following variation of this hook:

add_filter( 'gform_{ADDON_SLUG}_feed_settings_fields', 'your_function_name', 10, 2 );

See the Gravity Forms Add-On Slugs article for a list of possible slugs.

Parameters

Examples

1. Add a Custom Setting to the First Section of All Feeds

add_filter( 'gform_addon_feed_settings_fields', 'add_custom_addon_setting', 10, 2 );
function add_custom_addon_setting( $feed_settings_fields, $addon ) {

$feed_settings_fields[0]['fields'][] = array(
'name'  => 'my_custom_setting',
'label' => 'My Custom Setting',
'type'  => 'text'
);

return $feed_settings_fields;
}

2. Add a Custom Setting After the “Send Email” Setting for All User Registration Feeds

This example shows how the add_field_after() helper can be used to add a new setting after a specific existing setting.

add_filter( 'gform_gravityformsuserregistration_feed_settings_fields', function( $feed_settings_fields, $addon ) {

$feed_settings_fields = $addon->add_field_after( 'sendEmail', array(
array(
'name'  => 'my_custom_setting',
'label' => 'My Custom Setting',
'type'  => 'text'
)
), $feed_settings_fields );

return $feed_settings_fields;
}, 10, 2 );

3. Remove ‘Password’ Setting for User Registration Feeds for a Specific Form

This example shows how the remove_field() helper can be used to remove one of the settings.

add_filter( 'gform_gravityformsuserregistration_feed_settings_fields', function( $feed_settings_fields, $addon ) {

$form = $addon->get_current_form();
if( $form['id'] == 1 ) {
$feed_settings_fields = $addon->remove_field( 'password', $feed_settings_fields );
}

return $feed_settings_fields;
}, 10, 2 );

4. Add a Custom Setting to Certain Payment Add-Ons

This example shows how an add-on which uses the Add-On Framework, in this example it’s the User Registration Add-On, can add a custom setting to add-ons which extend GFPaymentAddOn and support subscription cancellations.

public function init() {
parent::init();
add_filter( 'gform_addon_feed_settings_fields', array( $this, 'add_subscription_feed_setting' ), 10, 2 );
}
public function add_subscription_feed_setting( $feed_settings_fields, $addon ) {
$addon_supports_subscriptions = $addon instanceof GFPaymentAddOn && $addon->method_is_overridden( 'cancel', 'GFPaymentAddOn' );

if ( $addon_supports_subscriptions ) {

$ur_settings = array(
'title'      => esc_html__( 'User Registration Options', 'gravityformsuserregistration' ),
'tooltip'    => sprintf( '<h6>%s</h6> %s', esc_html__( 'User Registration Options', 'gravityformsuserregistration' ), esc_html__( 'The selected form also has a User Registration feed. These options allow you to specify how you would like the PayPal and User Registration Add-ons to work together.', 'gravityformuserregistration' ) ),
'fields'     => array(),
'dependency' => array( 'field' => 'transactionType', 'values' => array( 'subscription' ) ),
);

$ur_settings['fields'][] = array(
'name'       => 'cancellationActionUser',
'label'      => esc_html__( 'Update User on Cancel', 'gravityformsuserregistration' ),
'type'       => 'checkbox_and_select',
'checkbox'   => array(
'label' => esc_html__( 'Update user when subscription is cancelled.', 'gravityformsuserregistration' )
),
'select'     => array(
'choices' => $this->get_update_user_actions_choices()
),
);

$feed_settings_fields = array_merge( $feed_settings_fields, array( $ur_settings ) );
}

return $feed_settings_fields;
}

Further Reading

For more details on adding and removing fields from the settings, see the Helper Functions article.

The Settings API category includes a number of examples showing how you can implement various field types.

Placement

This code should be placed in the functions.php file of your active theme.

Source Code

This filter is located in GFFeedAddOn::get_feed_settings_fields() in /includes/addons/class-gf-feed-addon.php.

Since

This filter was added in Gravity Forms 2.0.