gform_userregistration_feed_settings_fields

Description

This filter can be used to modify the setting fields that appear on the feed page.

Usage

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

Parameters

Add a Custom Setting

add_filter( 'gform_userregistration_feed_settings_fields', 'add_custom_user_registration_setting', 10, 2 );

function add_custom_user_registration_setting( $fields, $form ) {
    $fields['additional_settings']['fields'][] = array(
        'name'       => 'myCustomSetting',
        'label'      => __( 'My Custom Setting', 'my-text-domain' ),
        'type'       => 'checkbox',
        'choices'    => array(
            array(
                'label' => __( 'This is the checkbox label', 'my-text-domain' ),
                'value' => 1,
                'name'  => 'myCustomSetting',
            ),
        ),
        'tooltip'    => sprintf(
            '<h6>%s</h6> %s',
            __( 'Tooltip Header', 'my-text-domain' ),
            __( 'This is the tooltip description', 'my-text-domain' )
        ),
        'dependency' => array(
            'field'  => 'feedType',
            'values' => 'create',
        ),
    );

    return $fields;
}

Remove a Setting

This example shows how to remove the “Role” dropdown from the User Registration feed for any user without the Administrator role.

add_filter( 'gform_userregistration_feed_settings_fields', 'remove_role_assignment', 10, 2 );
function remove_role_assignment( $fields, $form ) {
    // Return early if the user is an administrator
    if ( current_user_can( 'administrator' ) ) {
        return $fields;
    }

    foreach ( $fields['user_settings']['fields'] as $index => $field ) {
        if ( isset( $field['name'] ) && $field['name'] === 'role' ) {
            unset( $fields['user_settings']['fields'][ $index ] );
        }
    }

    // Re-index the array
    $fields['user_settings']['fields'] = array_values( $fields['user_settings']['fields'] );

    return $fields;
}

Placement

This code can be used in the functions.php file of the active theme, a custom functions plugin, a custom add-on, or with a code snippets plugin.

See also the PHP section in this article: Where Do I Put This Code?

Since

This filter was added in version 3.0.

Source Code

$fields = apply_filters( 'gform_userregistration_feed_settings_fields', $fields, $form );

This filter is located in GF_User_Registration::feed_settings_fields() in class-gf-user-registration.php.