From 355facdb97348c03600a0f69ac650488c942c72a Mon Sep 17 00:00:00 2001 From: Saif Sultan Date: Mon, 14 Apr 2025 22:04:25 +0530 Subject: [PATCH 1/2] `gw-rich-text-html-fields.php`: Added image upload capabilities. --- gravity-forms/gw-rich-text-html-fields.php | 24 +++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/gravity-forms/gw-rich-text-html-fields.php b/gravity-forms/gw-rich-text-html-fields.php index 2097837c1..6ade9621b 100644 --- a/gravity-forms/gw-rich-text-html-fields.php +++ b/gravity-forms/gw-rich-text-html-fields.php @@ -16,6 +16,7 @@ add_action( 'admin_init', function() { if ( GFForms::get_page() === 'form_editor' ) { wp_enqueue_editor(); + wp_enqueue_media(); // Required for media uploads } } ); @@ -70,7 +71,28 @@ jQuery( document).on( 'tinymce-editor-setup', function ( event, editor ) { var editorId = 'field_rich_content'; if ( editor.id === editorId ) { - editor.settings.toolbar1 = 'bold,italic,underline,bullist,numlist,alignleft,aligncenter,alignright,link'; + editor.settings.toolbar1 = 'bold,italic,underline,bullist,numlist,alignleft,aligncenter,alignright,link,image'; + + // Handle image insertion from media library + editor.addButton( 'image', { + icon: 'image', + tooltip: 'Insert Image', + onclick: function() { + var frame = wp.media({ + title: 'Insert Media', + button: { text: 'Insert into HTML Field' }, + multiple: false, + library: { type: 'image' } + } ); + + frame.on('select', function() { + var attachment = frame.state().get('selection').first().toJSON(); + editor.insertContent('' + attachment.alt + ''); + } ); + + frame.open(); + } + } ); // Switch to visual/text mode. jQuery(`#wp-${editorId}-wrap .switch-tmce, #wp-${editorId}-wrap .switch-html`).on('click', function() { From e0bc1c69bbcd52b9551b3e7f851321f254e26bbf Mon Sep 17 00:00:00 2001 From: Saif Sultan Date: Mon, 5 May 2025 18:54:19 +0530 Subject: [PATCH 2/2] `gw-rich-text-html-fields.php`: Added image upload capabilities. --- gravity-forms/gw-rich-text-html-fields.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/gravity-forms/gw-rich-text-html-fields.php b/gravity-forms/gw-rich-text-html-fields.php index 6ade9621b..db8edde32 100644 --- a/gravity-forms/gw-rich-text-html-fields.php +++ b/gravity-forms/gw-rich-text-html-fields.php @@ -86,8 +86,15 @@ } ); frame.on('select', function() { - var attachment = frame.state().get('selection').first().toJSON(); - editor.insertContent('' + attachment.alt + ''); + var selection = frame.state().get('selection').first(); + if (!selection) { + return; + } + + var attachment = selection.toJSON(); + var url = attachment.url.replace(/"/g, '"'); + var alt = (attachment.alt || '').replace(/"/g, '"'); + editor.insertContent('' + alt + ''); } ); frame.open();