【问题标题】:Wordpress admin: how to add text editor into plugin textarea?Wordpress 管理员:如何将文本编辑器添加到插件 textarea 中?
【发布时间】:2015-12-30 22:13:34
【问题描述】:

我最近不得不更新旧的 (3.0.1) Wordpress 网站,同时保持所有管理功能、插件等与以前相同。唯一搞砸的是旧的“更多字段”插件中的所见即所得字段,它曾经用作 tinyMCE 文本编辑器,现在它只是一个带有 html 标记的文本区域。

据我所知,这是从 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 中以各种方式进行 crowbarring,但我的 php 技能非常基础,所以谁能告诉我如何将 textarea 变成文本编辑器框?不管是用 php 还是 jQuery 什么的,它真的只需要一堆格式化按钮,这样编辑器就可以更容易地发布内容了。

谢谢!

【问题讨论】:

    标签: php jquery wordpress tinymce


    【解决方案1】:

    使用这个

    // 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);
             ?>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-12-20
      • 1970-01-01
      • 2011-03-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多