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);

Leave a Reply