Using Gravity Forms ‘gform_export_menu’ PHP action

The gform_export_menu Gravity Forms PHP filter allows you to add new or modify default menu items that appear in the Import/Export section menu.

Usage

Apply to all forms:

add_filter('gform_export_menu', 'my_custom_function');

Parameters

  • $menu_items (array): An array of menu items to be displayed on the Import/Export page menu.

More information

See Gravity Forms Docs: gform_export_menu

Examples

Add a custom menu item to the Import/Export page menu

This example shows how to add a custom menu item to the Import/Export page menu and display content for this page when selected.

// Add custom menu item
add_filter('gform_export_menu', 'my_custom_export_menu_item');
function my_custom_export_menu_item($menu_items) {
    $menu_items[] = array(
        'name' => 'my_custom_export_page',
        'label' => __('My Custom Export Page')
    );
    return $menu_items;
}

// Display content for custom menu item when selected
add_action('gform_export_page_my_custom_export_page', 'my_custom_export_page');
function my_custom_export_page() {
    GFExport::page_header();
    echo 'My Custom Export Page Settings!';
    GFExport::page_footer();
}

Modify an existing menu item in the Import/Export page menu

This example shows how to change the label of an existing menu item in the Import/Export page menu.

add_filter('gform_export_menu', 'modify_export_menu_item');
function modify_export_menu_item($menu_items) {
    foreach ($menu_items as &$item) {
        if ($item['name'] === 'existing_menu_item') {
            $item['label'] = __('New Label');
        }
    }
    return $menu_items;
}

Remove a menu item from the Import/Export page menu

This example shows how to remove a specific menu item from the Import/Export page menu.

add_filter('gform_export_menu', 'remove_export_menu_item');
function remove_export_menu_item($menu_items) {
    foreach ($menu_items as $key => $item) {
        if ($item['name'] === 'item_to_remove') {
            unset($menu_items[$key]);
        }
    }
    return $menu_items;
}

Add multiple custom menu items to the Import/Export page menu

This example shows how to add multiple custom menu items to the Import/Export page menu.

add_filter('gform_export_menu', 'add_multiple_export_menu_items');
function add_multiple_export_menu_items($menu_items) {
    $new_items = array(
        array(
            'name' => 'custom_export_page_1',
            'label' => __('Custom Export Page 1')
        ),
        array(
            'name' => 'custom_export_page_2',
            'label' => __('Custom Export Page 2')
        )
    );
    return array_merge($menu_items, $new_items);
}

Reorder menu items in the Import/Export page menu

This example shows how to reorder menu items in the Import/Export page menu.

add_filter('gform_export_menu', 'reorder_export_menu_items');
function reorder_export_menu_items($menu_items) {
    usort($menu_items, function($a, $b) {
        return strcmp($a['label'], $b['label']);
    });
    return $menu_items;
}