Display Indicator on Menu Item if Code Chest Has Code

Read the Walkthrough

Code

Filename: gfcc-add-in-use-menu-indicator.php

<?php
/**
 * Gravity Forms // Code Chest // Display Indicator on Menu Item if Code Chest Has Code
 * https://gravitywiz.com/gravity-forms-code-chest/
 */
add_filter( 'gform_form_settings_menu', function( $menu_items, $form_id ) {

	$form = GFAPI::get_form( $form_id );

	// Check if there is code in the JS or CSS settings using Code Chest methods
    $has_js_code = ! empty( gwiz_gf_code_chest()->get_custom_js( $form ) );
    $has_css_code = ! empty( gwiz_gf_code_chest()->get_custom_css( $form ) );

    // If there is code in either setting, append the ✔ symbol to the Code Chest menu item
    if ( $has_js_code || $has_css_code ) {
        foreach ( $menu_items as &$menu_item ) {
            if ( $menu_item['name'] === 'gf-code-chest' ) {
                $menu_item['label'] .= '';
                break;
            }
        }
    }

    return $menu_items;
}, 16, 2 );

Leave a Reply

Your email address will not be published. Required fields are marked *

  • Trouble installing this snippet? See our troubleshooting tips.
  • Need to include code? Create a gist and link to it in your comment.
  • Reporting a bug? Provide a URL where this issue can be recreated.

By commenting, I understand that I may receive emails related to Gravity Wiz and can unsubscribe at any time.