Call TinyMCE in a WordPress plugin

后端 未结 8 1335
悲哀的现实
悲哀的现实 2020-12-24 05:33

Is there a way to add TinyMCE into my own WordPress plugin?

I have a textarea in my back end script and want to make this area into a TinyMCE WYSIWYG editable field.

相关标签:
8条回答
  • 2020-12-24 06:19

    I had quite a bit of trouble with this. After searching all day and trying dozens of code examples, I couldn't get Wordpress theme options to save MCE values to database. I tried everything, the jQuery answers, the hidden fields, etc etc. None of that would work for me, probably because I was missing a step somewhere.

    Finally I found this page: http://wptheming.com/options-framework-theme/

    Download from Github & install as directed (easy). Once installed, the last tab in your theme options has an MCE editor. Enter some test paragraphs. Now open the index.php file in the download to see the examples of how to include each thingy in your page. For example, I open footer.php and add a bit of code.

    The only edit I needed to make was:

    <?php
    $ft = of_get_option('example_editor', 'no entry');
    $format_ft = wpautop( $ft, false );
    echo ($format_ft);
    ?>
    

    The function wpautop() from Wordpress adds in paragraph tags, since they aren't ever saved in the wp database. I put that code in my footer to display the contents of the MCE.

    0 讨论(0)
  • 2020-12-24 06:31

    Camden already answered this, but in case somebody needs the full code... Be sure to hook in admin_head, hooking into admin_enqueue_scripts will cause it to load before other scripts, such as jQuery, so it will not work.

    add_action("admin_head","load_custom_wp_tiny_mce");
    function load_custom_wp_tiny_mce() {
    
    if (function_exists('wp_tiny_mce')) {
    
      add_filter('teeny_mce_before_init', create_function('$a', '
        $a["theme"] = "advanced";
        $a["skin"] = "wp_theme";
        $a["height"] = "200";
        $a["width"] = "800";
        $a["onpageload"] = "";
        $a["mode"] = "exact";
        $a["elements"] = "intro";
        $a["editor_selector"] = "mceEditor";
        $a["plugins"] = "safari,inlinepopups,spellchecker";
    
        $a["forced_root_block"] = false;
        $a["force_br_newlines"] = true;
        $a["force_p_newlines"] = false;
        $a["convert_newlines_to_brs"] = true;
    
        return $a;'));
    
     wp_tiny_mce(true);
    }
    
    
    }
    

    Then somewhere in your template insert a regular textarea:

    <textarea id="intro"></textarea>
    
    0 讨论(0)
提交回复
热议问题