Skip to content

Commit 355facd

Browse files
committed
gw-rich-text-html-fields.php: Added image upload capabilities.
1 parent 0390f25 commit 355facd

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

gravity-forms/gw-rich-text-html-fields.php

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
add_action( 'admin_init', function() {
1717
if ( GFForms::get_page() === 'form_editor' ) {
1818
wp_enqueue_editor();
19+
wp_enqueue_media(); // Required for media uploads
1920
}
2021
} );
2122

@@ -70,7 +71,28 @@
7071
jQuery( document).on( 'tinymce-editor-setup', function ( event, editor ) {
7172
var editorId = 'field_rich_content';
7273
if ( editor.id === editorId ) {
73-
editor.settings.toolbar1 = 'bold,italic,underline,bullist,numlist,alignleft,aligncenter,alignright,link';
74+
editor.settings.toolbar1 = 'bold,italic,underline,bullist,numlist,alignleft,aligncenter,alignright,link,image';
75+
76+
// Handle image insertion from media library
77+
editor.addButton( 'image', {
78+
icon: 'image',
79+
tooltip: 'Insert Image',
80+
onclick: function() {
81+
var frame = wp.media({
82+
title: 'Insert Media',
83+
button: { text: 'Insert into HTML Field' },
84+
multiple: false,
85+
library: { type: 'image' }
86+
} );
87+
88+
frame.on('select', function() {
89+
var attachment = frame.state().get('selection').first().toJSON();
90+
editor.insertContent('<img src="' + attachment.url + '" alt="' + attachment.alt + '" />');
91+
} );
92+
93+
frame.open();
94+
}
95+
} );
7496

7597
// Switch to visual/text mode.
7698
jQuery(`#wp-${editorId}-wrap .switch-tmce, #wp-${editorId}-wrap .switch-html`).on('click', function() {

0 commit comments

Comments
 (0)