logo
Ask your WordPress questions! Pay money and get answers fast! (more info)

Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

If the asker does not get an answer then they have 10 days to request a refund.

$40
How To Add a TinyMCE Editor To an Options Page?

Hi,

I would like to know how to add a TinyMCE editor to this options page:
http://net.tutsplus.com/tutorials/wordpress/how-to-create-a-better-wordpress-options-panel/

I've followed this tutorial,
http://www.zen-dreams.com/en/2009/06/30/integrate-tinymce-into-your-wordpress-plugins/
and everything is showing up correctly, but I don't know how to save the data entered to the database.

When I click "Save Changes" nothing gets saved.

It appears the linked tutorial is incomplete because it doesn't contain the information needed to make the TinyMCE editor save the data.

This is the code I'm using now in my functions.php for the case part:

case 'editor':
?>
<div class="rm_input rm_textarea">
<label for="<?php echo $value['id']; ?>"><?php echo $value['name']; ?></label>
<div class="editor_holder"><?php the_editor($content_to_load);?></div>
</div>
<?php
break;


Then for the array part:

array( "name" => "Description Box Contents",
"desc" => "Description copy",
"id" => $shortname."_editor_content",
"type" => "editor",
"std" => ""),



The function to create TinyMCE:

add_filter('admin_head','ShowTinyMCE');
function ShowTinyMCE() {
// conditions here
wp_enqueue_script( 'common' );
wp_enqueue_script( 'jquery-color' );
wp_print_scripts('editor');
if (function_exists('add_thickbox')) add_thickbox();
wp_print_scripts('media-upload');
if (function_exists('wp_tiny_mce')) wp_tiny_mce();
wp_admin_css();
wp_enqueue_script('utils');
do_action("admin_print_styles-post-php");
do_action('admin_print_styles');
}


And calling the contents submitted through the editor in the template:

<?php echo get_option('nt_editor_content'); ?>


Your help is much appreciated.

This question has been answered.

Edwin | 10/16/10 at 4:50pm Edit


The experts have suggested, on average, a prize of $30 for this question.

(6) Possible Answers Submitted...

See a chronological view of answers?

Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

  • avatar
    Last edited:
    10/16/10
    5:06pm
    Baki Goxhaj says:

    Try to convert this into a real textarea:

    <div class="editor_holder"><?php the_editor($content_to_load);?></div>

    • 10/17/10 5:00am

      Edwin says:

      Could you post a code example of how to do this?
      Thanks!

    • 10/17/10 5:03am

      Baki Goxhaj says:

      This simple:

      <textarea class="editor_holder"><?php the_editor($content_to_load);?></textarea>

    • 10/17/10 5:11am

      Edwin says:

      Hi Baki,

      Unfortunately it didn't work, it basically killed the TinyMCE editor entirely.

      Attached Image

  • avatar
    Last edited:
    10/16/10
    5:07pm
    flashingcursor says:

    This may be cheating, but I found this tutorial very helpful -- it's pretty much exactly the way I started doing it in my plugins.

    http://farinspace.com/multiple-wordpress-wysiwyg-visual-editors/

    If you need more help with it, please don't hesitate to ask. I'd be happy to walk you through it.

    • 10/17/10 5:04am

      Edwin says:

      Well you've got the code I'm using above, if you can alter it as such that the editor passes and saves the submitted content to the database then I can select you as the winner to my question.

      The code I posted above misses something, but I have no idea what at this time.

  • avatar
    Last edited:
    10/16/10
    5:53pm
    Joe Jenkins says:

    Make life easy for yourself, and get this plugin:

    http://codecanyon.net/item/wordpress-adminpage-class/115872

    It costs $8, but will allow you to easily create option pages and sub-pages, allowing for everything from uploading images, wysiwyg editor, drop-down menus, etc

  • avatar
    Last edited:
    10/16/10
    5:59pm
    Frank Bültge says:

    You can add the tinymce via JS to an ID of textarea on custom pages.

    Example, we include the editor to the ID hh-zusatzinfo of an textarea:
    this is the textarea in the plugin:

    <textarea cols="16" rows="5" id="hh-zusatzinfo" name="hh-zusatzinfo" class="zusatzinfo form-input-tip code" size="20" autocomplete="off" tabindex="6" style="width:90%"/><?php echo wpautop( $value['zusatzinfo'] ); ?></textarea>


    my script; in js/script.js inside the plugin:

    jQuery(document).ready( function () { 
    jQuery("#hh-zusatzinfo").addClass("mceEditor");
    if ( typeof( tinyMCE ) == "object" && typeof( tinyMCE.execCommand ) == "function" ) {
    jQuery("#hh-zusatzinfo").wrap( "<div id='editorcontainer'></div>" );
    tinyMCE.execCommand("mceAddControl", false, "hh-zusatzinfo");
    }
    jQuery("#hh-zusatzinfo2").addClass("mceEditor");
    if ( typeof( tinyMCE ) == "object" && typeof( tinyMCE.execCommand ) == "function" ) {
    jQuery("#hh-zusatzinfo2").wrap( "<div id='editorcontainer'></div>" );
    tinyMCE.execCommand("mceAddControl", false, "hh-zusatzinfo2");
    }
    });


    now we load the script in a function:

    function enqueue_script() {
    wp_enqueue_script( 'tinymce4hh', WP_PLUGIN_URL . '/' . FB_HH_BASEDIR . '/js/script.js', array('jquery') );
    }



    this function we include via hook an the page, change the hook (post.php and post-new.php) to your options-page; this folow example is for the edit post and page:

    add_action("admin_print_scripts-post.php", array($this, 'enqueue_script'));
    add_action("admin_print_scripts-post-new.php", array($this, 'enqueue_script'));
    add_action("admin_print_scripts-page.php", array($this, 'enqueue_script'));
    add_action("admin_print_scripts-page-new.php", array($this, 'enqueue_script'));

    • 10/17/10 5:13am

      Edwin says:

      Sorry Frank, I have no idea how to use the code you have posted to fix my code.

    • 10/17/10 8:07am

      Frank Bültge says:

      @Edwin: you must use the core-functions for include tinymce on custom option-page; my code is only an axample for an textarea with the id. You can also use, read my plugin - use tinymce on an custom textarea: http://github.com/bueltge/different-type

  • avatar
    Last edited:
    10/21/10
    3:00am
    Denzel Chia says:

    Hi,

    You said you follow this tutorial for creating options page.
    http://net.tutsplus.com/tutorials/wordpress/how-to-create-a-better-wordpress-options-panel/
    Did you include step 5? Step 5 updates the input into WordPress options table, using update_option function.

    If you include step 5 then something must be wrong with the name attribute of the input field, it must be the same as post and updated into database.

    Please paste all your codes here so that people can help you.

    Get the option page correct first, make sure you and able to update and get option before adding tiny mce editor.

    Thanks

    • 10/17/10 11:23am

      Denzel Chia says:

      You used get_option('nt_editor_content'), make sure in your step 5 you use update_option('nt_editor_content','your_input_name') to save data in wordpress.
      Whereby your_input_name is the name attribute of your textarea. This is basic HTML.

  • avatar
    Last edited:
    10/18/10
    8:35am
    Milan Petrovic says:

    My tutorial:

    http://www.dev4press.com/2010/tutorials/wordpress-tips/add-rich-text-editor-to-your-plugin/

This question has expired.





Current status of this question: Completed



Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

If the asker does not get an answer then they have 10 days to request a refund.