Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

share|improve this question

2 Answers 2

i had the same "problem" just two days ago. Finally it worked somehow but wasn't reliable at all. Switching editors just didn't work occasionally and as said, wasn't a reliable solution.

The only reason to use tinyMCE here was the ability to add links to attachments. I took an other route and came to this solution:

http://www.screenr.com/xYas

I've done this for somebody else, so this is just a early demo, quick & dirty. The final script is a bit prettier. If you're interested, please send a short mail to kai@[->myusername<-].de or find me at twitter @ungestaltbar

share|improve this answer

Try increasing priority for the attachment_fields_to_edit filter:

add_filter('attachment_fields_to_edit', 'alternate_tiny_mce_method', 15, 2);
share|improve this answer
    
An explanation would be useful. –  toscho Nov 5 '12 at 3:48

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.