Skip to content

Instantly share code, notes, and snippets.

@goldenapples
Created May 26, 2012 20:19
Show Gist options
  • Save goldenapples/2795190 to your computer and use it in GitHub Desktop.
Save goldenapples/2795190 to your computer and use it in GitHub Desktop.
Rich text editors for Gravity Forms
<?php
/*
Plugin Name: Rich Text editors for Gravity Forms
Description: Converts the textarea fields in Gravity Forms to WordPress rich text editors
Author: Nathaniel Taintor
Author URI: http://goldenapplesdesign.com
Version: 1.0
License: GPLv2
*/
/*
* Gravity Forms filter to allow the post body and textarea inputs to use the wp_editor
* visual editor. To use wp_editor instead of default textarea, just set css class
* to "richtext"
*
* @uses wp_editor() Requires WordPres >= 3.3.0 for this function
*
* see http://codex.wordpress.org/Function_Reference/wp_editor for arguments to
* pass to the wp_editor() function. At the very minimum, you probably will need
* to pass some styles in 'editor_css'; otherwise the gravityforms styles and your
* theme styles will likely override some of the styles applied to the editor
* buttons and text.
*
*/
add_action( 'gform_field_input', 'gforms_wp_editor', 10, 5 );
function gforms_wp_editor( $input, $field, $value, $lead_id, $form_id ) {
if( $field["cssClass"] == 'richtext' ) {
ob_start();
wp_editor( $value, "input_{$form_id}_{$field['id']}",
array(
'media_buttons' => false,
'textarea_name' => "input_{$field['id']}"
) );
$input = ob_get_clean();
}
return $input;
}
@lekiend
Copy link

lekiend commented May 10, 2023

Hello,
I would change the test with the following:
if( $field["useRichTextEditor"] == '1' ) {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment