Removing “Visual” tab from Gravity Forms notification editor

When you’re editing Gravity Forms notifications (i.e. emails), you see the same editor that shows up in other places in WordPress. It can be really nice to have the visual editor there depending on what you’re doing. So what’s the problem?

The Problem

If you’re writing HTML emails in the Text tab, you can lose some of your markup just by clicking the Visual tab and then immediately switching back to the Text tab. It gets deleted without telling you about it!

This can be very frustrating, especially if you have multiple users who are editing notification messages. You could lose markup without realizing it very easily.

The Solution

So how do we disable the visual editor tab? It can be disabled globally for a user on the user settings page, but that’s definitely overkill, especially if those users should be able to use the visual editor for other content like posts and pages.

The Filter

Fortunately, WordPress has a filter named wp_editor_settings that allows us to modify the array of editor settings before it renders the editor. The first parameter, $settings, is the array of settings used to render the editor. The second parameter, $editor_id, uniquely identifies which editor is about to be rendered.

When the editor is being rendered on the Gravity Forms notification editing page, $editor_id comes through as "gform_notification_message". This allows us to check if WordPress is about to render a gravity forms notification message editor, and if so, disable tinymce, the visual editor tab. If it doesn’t match, we can just return the $settings array without modifying it.

The Code

Here’s the full working code you can drop into your functions.php:


function remove_gf_notification_visual_editor($settings, $editor_id)
{
    if ($editor_id === 'gform_notification_message') {
    $settings['tinymce'] = false;
}
    return $settings;
}

add_filter('wp_editor_settings', 'remove_gf_notification_visual_editor', 10, 2);

3 Comments

  1. wschipper on May 9, 2018 at 4:03 am

    Awesome! Thank you!

    • John on May 9, 2018 at 7:54 am

      Glad to hear this helped you out!

  2. hi-sky.net on January 7, 2019 at 7:55 pm

    best solution , you must be reworded 🙂

Leave a Comment