简体   繁体   English

动态生成的Wordpress Wysiwyg编辑器(wp_editor)无法正常显示

[英]Dynamically generated Wordpress Wysiwyg Editor ( wp_editor ) not displaying properly

I have 2 html wysiwyg editors on a wordpress admin page. 我在wordpress管理页面上有2个html wysiwyg编辑器。 Both use WP_EDITOR() function. 两者都使用WP_EDITOR()函数。 The first one is hard coded into the page: 第一个硬编码到页面中:

<form name="form1" id="form1" method="post" action="" style="display:block;">
  <p>
    <!-- editor here -->
    <?php
       wp_editor( 'CONTENT WILL APPEAR HERE!', 'addsometxt', array('textarea_name'=>'create_txt','textarea_rows'=>10,'wpautop'=>false));
    ?>
  </p>
  <p>
   <input name="save" type="submit" class="button-primary" id="save" style="margin:5px;" value="Save Input" /></p>
</form>

The second one is generated dynamically with a PHP function using an AJAX call (wp_ajax_ and $.post). 第二个是使用AJAX调用(wp_ajax_和$ .post)使用PHP函数动态生成的。 I've test the ajax call and know it works; 我测试了ajax调用并知道它有效; so, for brevity, here's the php function: 所以,为了简洁起见,这里是php函数:

<?php
function display_editor2() {
// grab data from database (data_from_db) and display in editor
  wp_editor( $row->data_from_db, 'editsometxt', array('textarea_name'=>'edit_txt','textarea_rows'=>10,'wpautop'=>false));

} 
?>

The problem is that even though the 2nd editor is displaying; 问题是即使第二个编辑器正在显示; it's missing all the tool bar buttons. 它缺少所有工具栏按钮。 See image below for illustration. 请参见下图以获取说明。 Anyone know who to fix this? 有人知道该解决这个问题吗?

在此输入图像描述

I had the same problem. 我有同样的问题。

When I add the code <?php wp_footer(); ?> 当我添加代码<?php wp_footer(); ?> <?php wp_footer(); ?> in my footer.php, it works. <?php wp_footer(); ?>在我的footer.php,它的工作原理。

I had the exact same issue and solved it this way (WP 4.7): 我有完全相同的问题并以这种方式解决(WP 4.7):

First create an hidden editor in your template so WP load all the necessary files for TinyMCE (the ID doesn't matter): 首先在模板中创建一个隐藏的编辑器,以便WP为TinyMCE加载所有必需的文件(ID无关紧要):

<div style="display:none"><?php wp_editor('', 'hidden_editor'); ?></div>

Then after you appended the new editor to the DOM, use the following functions: 然后在将新编辑器附加到DOM后,使用以下函数:

quicktags({id :'your_new_editor_id'});
tinymce.execCommand('mceAddEditor', true, 'your_new_editor_id');

Using tinymce.init didn't worked for me, as the new editor ID wasn't recognized. 使用tinymce.init对我没有用,因为新的编辑器ID无法识别。 Those two lines reinstantiate the quicktags and add the new editor. 这两行重新实现了quicktags并添加了新的编辑器。

Probably you need to add media_buttons and tinymce parameter on your AJAX call. 您可能需要在AJAX调用中添加media_buttonstinymce参数。

Something like this: 像这样的东西:

<?php
function display_editor2() {
    // grab data from database (data_from_db) and display in editor
    wp_editor( $row->data_from_db, 'editsometxt', array('textarea_name'=>'edit_txt','media_buttons'=>true,'tinymce'=>true,'textarea_rows'=>10,'wpautop'=>false));

    } 
?>

I recommend you check wp_editor() Function Reference page at Wordpress Codex. 我建议您检查Wordpress Codex中的wp_editor()函数参考页面。

Hey I too had the same problem! 嘿我也有同样的问题!

I just deactivated all the plug-ins which are installed by me and refreshed the page, and then I tried to edit the post/pages in the visual area also. 我刚刚停用了我安装的所有插件并刷新了页面,然后我也尝试在可视区域编辑帖子/页面。 Check once it will work for you. 检查一下它是否适合您。 :) :)

I hade the same problem, using this: 我讨厌同样的问题,用这个:

<?php wp_editor(get_the_content()); ?>

By passing a ID (second parameter to wp_editor) I got the buttons. 通过传递ID(第二个参数到wp_editor)我得到了按钮。 Like this: 像这样:

<?php wp_editor(get_the_content(), "with_a_ID_its_buttons_are_showing"); ?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM