|
16 | 16 | add_action( 'admin_init', function() {
|
17 | 17 | if ( GFForms::get_page() === 'form_editor' ) {
|
18 | 18 | wp_enqueue_editor();
|
| 19 | + wp_enqueue_media(); // Required for media uploads |
19 | 20 | }
|
20 | 21 | } );
|
21 | 22 |
|
|
70 | 71 | jQuery( document).on( 'tinymce-editor-setup', function ( event, editor ) {
|
71 | 72 | var editorId = 'field_rich_content';
|
72 | 73 | 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 selection = frame.state().get('selection').first(); |
| 90 | + if (!selection) { |
| 91 | + return; |
| 92 | + } |
| 93 | + |
| 94 | + var attachment = selection.toJSON(); |
| 95 | + var url = attachment.url.replace(/"/g, '"'); |
| 96 | + var alt = (attachment.alt || '').replace(/"/g, '"'); |
| 97 | + editor.insertContent('<img src="' + url + '" alt="' + alt + '" />'); |
| 98 | + } ); |
| 99 | + |
| 100 | + frame.open(); |
| 101 | + } |
| 102 | + } ); |
74 | 103 |
|
75 | 104 | // Switch to visual/text mode.
|
76 | 105 | jQuery(`#wp-${editorId}-wrap .switch-tmce, #wp-${editorId}-wrap .switch-html`).on('click', function() {
|
|
0 commit comments