Description
The “gform_rich_text_editor_buttons” filter in Gravity Forms controls 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
- $mce_buttons array
Array of buttons to include within the TinyMCE editor inside Gravity Forms.
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
This example shows how you can 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; }
This example shows how you can 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; }
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; }
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:
- 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 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.