Prepend form ID indicator to form toolbar menu

This feature is now available within the Gravity Hopper plugin.

Here’s another handy addition to ensure easy access to the form ID. The following code will add a small form ID indicator to the toolbar menu when editing a specific form. It carries the same style as the field ID indicator provided earlier.

// Prepend form ID indicator to form toolbar menu
add_filter( 'gform_toolbar_menu', function( $items, $form_id ) {

    $items[] = array(
        'label' => "ID: {$form_id}",
        'menu_class' => 'gform_id_indicator_item',
        'link_class' => 'gform_id_indicator',
        'priority' => '9999'
    );

    return $items;

}, 10, 2 );

add_action( 'admin_print_styles', function() {

    if ( class_exists( 'GFForms' ) && GFForms::is_gravity_page() ) {

        echo '<style>
                .gform-form-toolbar .gform-form-toolbar__menu .gform_id_indicator_item {
                    align-self: center; margin: 0 .4em;
                }
                .gform-form-toolbar .gform-form-toolbar__menu .gform_id_indicator {
                    pointer-events: none; height: auto; padding: .1em .45em;
                    font-size: .75rem; background-color: #ecedf8;
                    border: 1px solid #d5d7e9; border-radius: 4px;
                }
              </style>';

    }

} );Code language: PHP (php)

Here’s what you’ll see…

How do you find this article?