为什么tinyMCE.编辑不能在tinyMCE上工作

时间:2014-07-20 作者:dramasea

<?php 
/*
Plugin Name: Taggr
Plugin URI: http://example.com/wordpress-plugins/my-plugin
Description: Premium plugin for image and photo tagging
Version: 1.0
Author: Tee Kai Yang
Author URI: http://wrox.com
License: GPLv2
*/


add_action(\'init\', \'register_tagging_post\');

//create taggr post type

 function register_tagging_post(){

       $tagging_args = array(
           \'public\' => true,
           \'supports\' => array(
               \'title\',
               \'thumbnail\'

           ), 
           \'query_var\' => \'tagging\',
           \'rewrite\' => array(
              \'slug\' => \'taggr\',
              \'with_front\' => false
           ),
            \'labels\' => array(
            \'name\' => \'Taggr Albums\',
            \'singular_name\' => \'Album\',
            \'add_new\' => \'Add New Album\',
            \'add_new_item\' => \'Add New Album\',
            \'edit_item\' => \'Edit Album\',
            \'new_item\' => \'New Album\',
            \'view_item\' => \'View Album\',
            \'search_items\' => \'Search Albums\',
            \'not_found\' => \'No Albums Found\',
            \'not_found_in_trash\' => \'No Albums Found In Trash\'
        ),

        \'menu_icon\' => plugins_url() . \'/taggr/images/PhotoAlbum.png\',

        \'menu_position\' => 80, 

       );

       register_post_type(\'tagging\', $tagging_args);


 }

    add_action( \'add_meta_boxes\', \'taggr_create_meta\' );
 function taggr_create_meta(){

     add_meta_box( \'taggrMeta\', \'Upload and edit photos/images\', \'taggr_meta_function\', \'tagging\', \'normal\', \'high\' );

     function taggr_meta_function(){


     ?>

       <?php wp_editor("Enter your text", "my_editor"); ?>

    <script>
    window.onload = function(){
        alert(tinyMCE.editors[0].getContent());
    }
    </script>

        <?php

    }


    }


?> 
以上是我的代码,我在metabox中创建了一个自定义帖子和一个tinyMCE文本编辑器。但为什么执行时alert(tinyMCE.editors[0].getContent()); 行,它不工作,也不显示编辑器的内容。firebug显示以下错误:TypeError: tinyMCE.editors[0] is undefined

1 个回复
SO网友:Domain

您可以提供编辑器textarea的ID来获取tinyMCE的内容,还应该获取保存的post meta的内容,并将其设置为编辑器元素的文本,以显示之前保存的值。您可以使用以下代码作为参考,

<?php
function taggr_meta_function($post){
 $my_editor = get_post_meta($post->ID, \'my_editor\', true);
 wp_editor( $my_editor, "my_editor", array( \'textarea_name\' => "my_editor" ) );
?>
   <script>
    window.onload = function(){
        alert(tinyMCE.get(\'my_editor\').getContent());
    }
   </script>
<?php } ?>

结束

相关推荐

How can I find plugins' slug?

我想知道如何才能找到插件的slug(slug=WordPress用来更新插件和确定哪些插件当前处于活动状态的内部名称)?它通常是插件的文件夹名,但如果插件没有文件夹,则是其文件名(如hello.php)。是否有其他例外情况?大小写字符重要吗</插件的slug是否可以与其文件夹名不同?如果有一个叫做hello的插件呢。php和另一个/您好。php/您好。php