Wordpress管理员:如何将文本编辑器添加到插件textarea?

时间:2015-10-02 16:23:18

标签: php jquery wordpress wordpress-plugin tinymce

我最近不得不更新一个旧的(3.0.1)Wordpress网站,同时保持所有管理功能,插件等与以前一样。唯一搞砸的是旧的'More Fields'插件中的wysiwyg字段,它曾经作为一个tinyMCE文本编辑器工作,现在它只是一个带有html标记的textarea。

据我所知,这是从more-fields-object.php调用的方式:

    $wysiwyg = new mf_field_type;
    $wysiwyg->title = __('WYSIWYG', 'more-fields');
    $wysiwyg->html_before = '

    <script type="text/javascript">
        /* <![CDATA[ */
//  jQuery(document).ready( function () { 
//      tinyMCE2 = tinyMCE;
        tinyMCE.init({
            mode:"textareas",
            width:"100%",
            theme:"advanced",
            skin:"wp_theme",
            theme_advanced_buttons1:"bold,italic,strikethrough,|,bullist,numlist,blockquote,|,justifyleft,justifycenter,justifyright,|,link,unlink,wp_more,|,spellchecker,fullscreen,wp_adv",
            theme_advanced_buttons2:"", //formatselect,underline,justifyfull,forecolor,|,pastetext,pasteword,removeformat,|,media,charmap,|,outdent,indent,|,undo,redo,wp_help",
            theme_advanced_buttons3:"",
            theme_advanced_buttons4:"",language:"en",spellchecker_languages:"+English=en,Danish=da,Dutch=nl,Finnish=fi,French=fr,German=de,Italian=it,Polish=pl,Portuguese=pt,Spanish=es,Swedish=sv",
            theme_advanced_toolbar_location:"top",
            theme_advanced_toolbar_align:"left",
            theme_advanced_statusbar_location:"bottom",
            theme_advanced_resizing:"0",
            theme_advanced_resize_horizontal:"",
            plugins:"safari,inlinepopups,spellchecker,paste,wordpress,media,fullscreen,wpeditimage",
            editor_selector:"%key%"
        });
//  });     

        jQuery(document).ready( function () { 
            jQuery("#%key%").addClass("mceEditor");
            if ( typeof( tinyMCE ) == "object" && typeof( tinyMCE.execCommand ) == "function" ) {
            tinyMCE.execCommand("mceAddControl", false, "%key%");
            }
        }); 

        /* ]]> */
        </script>
        <div style="width: 100%">
    <textarea class="%class% %key%" name="%key%" id="%key%">' . "\n";

    $wysiwyg->html_item = "%value%";
    $wysiwyg->html_after = "</textarea></div>\n";
    $this->field_types[] = $wysiwyg;

This is the whole file

我已经尝试过以各种方式在wp_editor中进行欺骗,但我的php技能非常基本,所以有人可以告诉我如何将textarea变成文本编辑器框吗?无论是使用php还是jQuery,它都需要只有一堆格式化按钮,因此编辑器更容易发布内容。

谢谢!

1 个答案:

答案 0 :(得分:0)

使用此

// jQuery
wp_enqueue_script('jquery');

         <?php
             $settings = array(
            'teeny' => true,
            'textarea_rows' => 5,
            'tabindex' => 1,
            'media_buttons' => false
             );
             wp_editor( __(get_option('whatever_you_need', 'field_value' )), 'field_name', $settings);
         ?>