I need to add TinyMCE to descriptions of images. For it, I'm using this code in my functions.php:
function add_tiny_mce_hook() {
if (function_exists('wp_tiny_mce')){
wp_tiny_mce(false,
array(
'remove_linebreaks' => false,
'mode' => 'textareas',
'editor_selector' => 'my-tinymce-class')
);
}}
function alternate_tiny_mce_method($fields, $post) {
if (isset($fields['post_content'])) {
$value = $fields['post_content']['value'];
$label = $fields['post_content']['label'];
$name = 'post_content';
$fields[$name] = array(
'label' => $label,
'input' => 'html',
'html' => '<textarea name="attachments['.$post->ID.']['.$name.']" id="'.$name.'-'.$post->ID.'" class="my-tinymce-class">'.nl2br($value).'</textarea>'
);
}
return $fields;}
add_action('admin_head', 'add_tiny_mce_hook');
add_filter('attachment_fields_to_edit', 'alternate_tiny_mce_method', 10, 2);
On the Edit Media page works fine (wp-admin/media.php?attachment_id=XXX&action=edit). But, I have a problem after opening "Add an Image" modal window, and switching to the "Gallery" tab, from "Edit Post". I can't add a link via TinyMCE editor. Every time I click Add Link from the pop-up modal nothing happens.
I see the problem in gallery.js (gallery.dev.js; wp-admin/js/gallery.js; WordPress loads this JS). There are 3 lines that do me the trouble: .... tinymce = w.tinymce; tinyMCE = w.tinyMCE; t.editor = tinymce.EditorManager.activeEditor; ....
When I drop "tinymce = w.tinymce;" and "tinyMCE = w.tinyMCE;" and replace "tinymce.EditorManager.activeEditor;" with "w.tinymce.EditorManager.activeEditor" - works fine. But, I don't want to do a core mod to WordPress
My WordPress version is 3.2.1
Any help, please.