Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wordpress wp_editor won't add image

Tags:

wordpress

I have the following code inside a plugin in a loop, so there are multiple WYSIWYG editors:

<?php wp_editor( stripslashes($arr['item-content']), $key.'-item-content', array(
    'editor_class' => 'tsort-contarea',
    'media_buttons' => true,
    'editor_height' => 360,

) ); ?>

When adding an image, the XHR request labelled send-attachment-to-editor inside wp-includes/js/media-editor.js has a wp.media.view.settings.post.id of 0. Also, wp.media.view.settings.nonce.sendToEditor is always this value: e8b2eea867

return wp.media.post( 'send-attachment-to-editor', {
                nonce:      wp.media.view.settings.nonce.sendToEditor,
                attachment: options,
                html:       html,
                post_id:    wp.media.view.settings.post.id
            }); 

The xhr request fires off fine, but doesn't add to any of the WYSIWYG. I'm sure that's because the post_id isn't set or because the nonce is not unique. What can I do to make this work? The Media Manager works absolutely fine on content pages.

Source file: http://pastebin.com/BhvqBLGB

like image 655
rickyduck Avatar asked Feb 10 '23 22:02

rickyduck


2 Answers

From Codex:

Note that the ID that is passed to the wp_editor() function can only be composed of lower-case letters. No underscores, no hyphens. Anything else will cause the WYSIWYG editor to malfunction. (As of 3.6.1 you can use underscores in the ID.)

From what I see you are currently using a dash. Try changing that, and see how that works.

like image 99
Manolis Avatar answered Feb 13 '23 11:02

Manolis


You should check thoroughly for the wp.media.view.settings.post.id is 0 part, as I tried to reproduce the bug in metabox with multiple editors and I get post-id for the new post equal to non-zero (which is actually an auto-draft record in wp_posts table), image assignment is working properly for this case.

I believe there is something wrong with saving new post as auto-draft in your instance of WordPress (might be because of some plugin/theme)

like image 32
Dharmang Avatar answered Feb 13 '23 11:02

Dharmang