gform_rich_text_editor_buttons

Description

The gform_rich_text_editor_buttons filter allows developers to control the buttons displayed in the first row within the Gravity Forms rich text editor. This hook may be filtered by FORMID or by FORMID + FIELDID.

Usage

Applies to all forms.

add_filter( 'gform_rich_text_editor_buttons', 'my_function', 10, 2 );

To target a specific form append the form id to the hook name. (format: gform_rich_text_editor_buttons_FORMID)

add_filter( 'gform_rich_text_editor_buttons_2', 'my_function', 10, 2 );

To target a specific form field append the form id and field id to the hook name. (format: gform_rich_text_editor_buttons_FORMID_FIELDID)

add_filter( 'gform_rich_text_editor_buttons_2_6', 'my_function', 10, 2 );

Parameters

ParameterTypeDescription
$mce_buttonsarrayArray of buttons to include within the TinyMCE editor inside Gravity Forms.
$editor_idstringThe HTML element ID for the field using the rich text editor.
$field_objectobjectObject containing information about the field.

The default array of buttons is:

array( 'formatselect', 'bold', 'italic', 'bullist', 'numlist', 'blockquote', 'alignleft', 'aligncenter', 'alignright', 'link', 'unlink', 'spellchecker' );

Note: Spell Checker button was removed from WP core since version 3.6; you need to install a third-party plugin if you want to use it, e.g. TinyMCE Spellcheck.

Examples

Add another button.

add_filter( 'gform_rich_text_editor_buttons', 'my_function', 10, 2 );
function my_function( $mce_buttons ) {
	$mce_buttons[] = 'wp_more';
	return $mce_buttons;
}

Remove the majority of the buttons.

add_filter( 'gform_rich_text_editor_buttons', 'my_function', 10, 2 );
function my_function( $mce_buttons ) {
	$mce_buttons = array( 'bold', 'italic', 'bullist' );
	return $mce_buttons;
}

Apply to a specific form.

The following will apply for all fields with the rich text editor enabled in a form with id 2.

add_filter( 'gform_rich_text_editor_buttons_2', 'my_function', 10, 2 );
function my_function() {
	$mce_buttons = array( 'bold', 'italic', 'bullist' ); // Enable only Bold, Italic and Bullet List buttons
	return $mce_buttons;
}

Placement

This code can be used in the functions.php file of the active theme, a custom functions plugin, a custom add-on, or with a code snippets plugin.

See also the PHP section in this article: Where Do I Put This Code?

Filtering additional button rows

Gravity Forms also makes filters available to control the display of buttons in rows two through four of the rich text editor:

These filters can be used in the exact same way as the usage examples for the gform_rich_text_editor_buttons filter above but they allow you to filter additional rows in the rich text editor. Which row is filtered is noted in the filter name.

By default WordPress includes buttons in the first and second row of the TinyMCE editor, but other components in your site’s setup could include buttons in the third and fourth row including via these filters.

Source Code

This filter hook is located in class-gf-field-textarea.php.