Using Gravity Forms ‘gform_rich_text_editor_buttons’ PHP filter

The gform_rich_text_editor_buttons filter in Gravity Forms allows you to control the buttons displayed in the first row of the Gravity Forms rich text editor. You can target this filter by form ID or form ID + field ID.

Usage

Apply to all forms:

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

Target a specific form by appending the form ID to the hook name:

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

Target a specific form field by appending the form ID and field ID to the hook name:

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

Parameters

  • $mce_buttons (array): Array of buttons to include within the TinyMCE editor inside Gravity Forms.
  • $editor_id (string): The HTML element ID for the field using the rich text editor.
  • $field_object (object): Object containing information about the field.

More information

See Gravity Forms Docs: gform_rich_text_editor_buttons

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

Filter additional button rows

Gravity Forms provides filters to control buttons in rows two through four of the rich text editor:

  • gform_rich_text_editor_buttons_row_two
  • gform_rich_text_editor_buttons_row_three
  • gform_rich_text_editor_buttons_row_four

These filters can be used similarly to the usage examples for the gform_rich_text_editor_buttons filter, allowing you to filter additional rows in the rich text editor. The row being 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.

Examples

Add a new 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 most 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 for all fields with rich text editor in 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;
}