Wordpress wp_editor不会添加图片

时间:2015-02-12 17:34:19

标签: wordpress wordpress-plugin

我在循环中的插件中有以下代码,因此有多个WYSIWYG编辑器:

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

) ); ?>

添加图片时,send-attachment-to-editor内标有wp-includes/js/media-editor.js的XHR请求的wp.media.view.settings.post.id为0.此外,wp.media.view.settings.nonce.sendToEditor始终为此值: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
            }); 

xhr请求触发罚款,但不会添加到任何所见即所得。我确定这是因为post_id没有设置或因为nonce不是唯一的。我能做些什么来完成这项工作?媒体管理器在内容页面上运行得非常好。

源文件:http://pastebin.com/BhvqBLGB

2 个答案:

答案 0 :(得分:7)

来自Codex

  

请注意,传递给wp_editor()函数的ID只能   由小写字母组成。没有下划线,没有连字符。   其他任何东西都会导致WYSIWYG编辑器出现故障。 (作为   3.6.1您可以在ID中使用下划线。)

从我看到你正在使用短划线。尝试更改它,看看它是如何工作的。

答案 1 :(得分:1)

您应该彻底检查wp.media.view.settings.post.id是否为0部分,因为我尝试使用多个metabox重现editors中的错误,并且我获得新帖子的后id等于非零(实际上是auto-draft表中的wp_posts记录),图像分配在这种情况下正常工作。

我认为在你的WordPress实例中将新帖子保存为auto-draft可能有问题(可能是因为某些插件/主题)

相关问题