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.

$10
option page, media uploader not opened in a thickbox

No time to search the solution myself.

I have a function to create a page (options of theme).
This page contains an editor.
No problem.

Just one strange thing : when i click to add an image the media manager is opened in the same page, not in a lightbox.

Why ?

that's my code :


<?php
add_action('admin_menu', 'slh_panel_menu');

function slh_panel_menu() {
add_menu_page('Réglages du site', 'Option du site', 1, __FILE__, 'slh_panel');
}
function enqueue_editor() {
wp_enqueue_script('common');
wp_enqueue_script('jquery-color');
wp_admin_css('thickbox');
wp_print_scripts('post');
wp_print_scripts('media-upload');
wp_print_scripts('jquery');
wp_print_scripts('jquery-ui-core');
wp_print_scripts('jquery-ui-tabs');
wp_print_scripts('tiny_mce');
wp_print_scripts('editor');
wp_print_scripts('editor-functions');

/* Include the link dialog functions */
require_once ABSPATH . 'wp-admin/includes/internal-linking.php';
wp_print_scripts('wplink');
wp_print_styles('wplink');
add_action('tiny_mce_preload_dialogs', 'wp_link_dialog');

add_thickbox();
wp_tiny_mce();
wp_admin_css();
wp_enqueue_script('utils');
do_action("admin_print_styles-post-php");
do_action('admin_print_styles');
remove_all_filters('mce_external_plugins');
}



function slh_panel() { ?>

<div id="poststuff">
<div id="<?php echo user_can_richedit() ? 'postdivrich' : 'postdiv'; ?>" class="postarea">
<?php the_editor($slh_panel_options['content']); ?>
</div>
</div>
<?php add_action( 'admin_footer', 'wp_tiny_mce_preload_dialogs' );
} ?>


EDIT 1 :
Apparently, wp_tiny_mce_preload_dialogs() got removed and has changed into wp_preload_dialogs(). The tiny_mce_preload_dialogs hook just disappeared with this, breaking a lot of plugins.
-> http://core.trac.wordpress.org/ticket/18001

Maybe this can help : http://dannyvankooten.com/450/tinymce-wysiwyg-editor-in-wordpress-plugin/

EDIT 2 :
the problem seems known : http://wordpress.stackexchange.com/questions/22599/wordpress-3-2-has-broken-my-tinymce-code

EDIT 3 :

My original code is :

<?php
add_action('admin_menu', 'slh_panel_menu');
function slh_panel_menu() {
add_menu_page('Réglages du site', 'Option du site', 1, __FILE__, 'slh_panel');
}
function enqueue_editor() {
wp_enqueue_script('common');
wp_enqueue_script('jquery-color');
wp_admin_css('thickbox');
wp_print_scripts('post');
wp_print_scripts('media-upload');
wp_print_scripts('jquery');
wp_print_scripts('jquery-ui-core');
wp_print_scripts('jquery-ui-tabs');
wp_print_scripts('tiny_mce');
wp_print_scripts('editor');
wp_print_scripts('editor-functions');
/* Include the link dialog functions */
require_once ABSPATH . 'wp-admin/includes/internal-linking.php';
wp_print_scripts('wplink');
wp_print_styles('wplink');
add_action('tiny_mce_preload_dialogs', 'wp_link_dialog');
add_thickbox();
wp_tiny_mce();
wp_admin_css();
wp_enqueue_script('utils');
do_action("admin_print_styles-post-php");
do_action('admin_print_styles');
remove_all_filters('mce_external_plugins');
}
function slh_panel() {
$template_uri = get_template_directory_uri();
if( $_POST ) {
$slh_panel_options_old = get_option( 'slh_panel_options' );
$slh_panel_options = $_POST;
//$slh_panel_options['content'] = stripslashes( $_POST['content'] );
update_option('slh_panel_options', $slh_panel_options);

?>

<div class="updated"><center> <b>Les réglages sont enregistrés !</b></center></div>
<?php
}
$slh_panel_options = get_option('slh_panel_options');
?>
<form name="slh_form" id="slh_form" action="" method="post" enctype="multipart/form-data">
<div id="poststuff"><? echo $slh_panel_options['content']; ?>
<div id="<?php echo user_can_richedit() ? 'postdivrich' : 'postdiv'; ?>" class="postarea">
<?php the_editor($slh_panel_options['content']); ?>
</div>
</div>
<?php /* Insert the dialog box that's used by the "link" button */
//add_action( 'admin_footer', 'wp_tiny_mce_preload_dialogs' );
?>
<div id="heading">
<fieldset>
<input value="" class="save" type="submit">
</fieldset>
</div><!-- heading ends -->
</form>
<?php
} ?>

with this code i can saved the content of my editor, no problem.
But i can't use the media uploader because the thickbox doesn't work.
So i need a code to use correctly the media uploader with my editor.

If i add this code at the top :
add_action("admin_head","myplugin_load_tiny_mce");
function myplugin_load_tiny_mce() {
wp_tiny_mce( false ); // true gives you a stripped down version of the editor
}

no problem, the content is yet saved... but the problem with the media uploader isn't resolved

If i add at the top of my first code, this lines :
add_action('admin_head', 'enqueue_editor');

the content isn't saved

This question has been answered.

Sébastien | French WordpressDesigner | 12/03/11 at 8:54am Edit

Previous versions of this question: 12/03/11 at 11:13am | 12/03/11 at 11:20am | 12/04/11 at 9:11am

(5) 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:
    12/03/11
    9:48am

    This answer was downvoted by the top experts.

  • avatar
    Last edited:
    12/03/11
    10:16am
    Jurre Hanema says:

    Well, first of all, the function wp_tiny_mce_preload_dialogs and the action tiny_mce_preload_dialogs don't even exist.

    I'm not really sure how to make this work though.

    • 12/03/11 10:49am

      Sébastien | French WordpressDesigner says:

      that could be the response... I have find this :
      http://wordpress.org/support/topic/tinymce-32-and-wp_tiny_mce_preload_dialogs

  • avatar
    Last edited:
    12/03/11
    10:47am
    Kannan C says:

    i think the problem is because of thickbox.css may not loaded in your options.page
    verify generated code and check thickbox.css is there

    • 12/03/11 10:51am

      Sébastien | French WordpressDesigner says:

      no thickbox.css in my source !

    • 12/03/11 10:52am

      Sébastien | French WordpressDesigner says:

      Is "source" an english word ? Do you understand this word ?

    • 12/03/11 11:06am

      Kannan C says:

      actually you didn't included your scripts and styles to admin
      add this line


      add_action('admin_head', 'enqueue_editor');

    • 12/03/11 11:11am

      Sébastien | French WordpressDesigner says:

      i add this line but thickbox.css is not in the source

    • 12/03/11 11:31am

      Kannan C says:

      Sebastien,
      i pasted your code in my theme's function.php and after adding the above mentioned line, i can now open the media boxes in the thickbox. Are you using/adding any other scripts? that may be conflict with this?

    • 12/03/11 11:35am

      Sébastien | French WordpressDesigner says:

      paste your code here, i try it

    • 12/03/11 11:44am

      Kannan C says:


      add_action('admin_menu', 'slh_panel_menu');

      function slh_panel_menu() {
      add_menu_page('Réglages du site', 'Option du site', 1, __FILE__, 'slh_panel');
      }

      add_action('admin_head', 'enqueue_editor');
      function enqueue_editor() {
      wp_enqueue_script('common');
      wp_enqueue_script('jquery-color');
      wp_admin_css('thickbox');
      wp_print_scripts('post');
      wp_print_scripts('media-upload');
      wp_print_scripts('jquery');
      wp_print_scripts('jquery-ui-core');
      wp_print_scripts('jquery-ui-tabs');
      wp_print_scripts('tiny_mce');
      wp_print_scripts('editor');
      wp_print_scripts('editor-functions');

      /* Include the link dialog functions */
      require_once ABSPATH . 'wp-admin/includes/internal-linking.php';
      wp_print_scripts('wplink');
      wp_print_styles('wplink');
      add_action('tiny_mce_preload_dialogs', 'wp_link_dialog');
      add_thickbox();
      wp_tiny_mce();
      wp_admin_css();
      wp_enqueue_script('utils');
      do_action("admin_print_styles-post-php");
      do_action('admin_print_styles');
      remove_all_filters('mce_external_plugins');
      }

      function slh_panel() { ?>

      <div id="poststuff">

      <div id="<?php echo user_can_richedit() ? 'postdivrich' : 'postdiv'; ?>" class="postarea">
      <?php the_editor($slh_panel_options['content']); ?>
      </div>
      </div>

      <?php
      }


      And if you are using the_editor(), then there is no need to use wp_preload_dialogs()

    • 12/03/11 12:21pm

      Sébastien | French WordpressDesigner says:

      so i use your code
      i have delete the line : add_action('tiny_mce_preload_dialogs', 'wp_link_dialog');

      now the media-uploader is in a thickbox, that's cool. But when i save the content, the content become empty...

    • 12/03/11 12:50pm

      Sébastien | French WordpressDesigner says:

      i use wp 3.2

      http://core.trac.wordpress.org/ticket/18001
      this link seems to say that wp3.2 need another method.

      "wp_tiny_mce_preload_dialogs() got removed and has changed into wp_preload_dialogs(). The tiny_mce_preload_dialogs hook just disappeared with this, breaking a lot of plugins."

      Could you write the code for wp3.2 please ?

    • 12/04/11 7:32am

      Kannan C says:

      what method you are using to save the data? update_option()?
      can you post that data saving part?

    • 12/04/11 8:09am

      Kannan C says:

      i just saw you posted the data saving part. i can see the saved content in the editor using your code exactly. Why not you upgrade the wp version to 3.2.1 and try again? i am using wp3.2.1

    • 12/04/11 8:32am

      Sébastien | French WordpressDesigner says:

      Done : i have upgrade to 3.2.1 but the content of the editor isn't saved.

  • avatar
    Last edited:
    12/03/11
    11:36am
    Luis Abarca says:

    I got this error

    Warning: call_user_func_array() [function.call-user-func-array]: First argument is expected to be a valid callback, 'wp_tiny_mce_preload_dialogs' was given in /home/blanco/public_html/wp-includes/plugin.php on line 405


    And also found this about the tiny_mce_preload_dialogs hook

    http://core.trac.wordpress.org/ticket/18001

    Previous versions of this answer: 12/03/11 at 11:36am

    • 12/03/11 11:36am

      Sébastien | French WordpressDesigner says:

      hum... and ? :-)

    • 12/03/11 11:38am

      Sébastien | French WordpressDesigner says:

      this link is in my question :-)

    • 12/03/11 11:40am

      Luis Abarca says:

      I add the line as Kannan Said.


      add_action('admin_head', 'enqueue_editor');


      And shows the thickbox, but i still getting the warning:
      Warning: call_user_func_array() [function.call-user-func-array]: First argument is expected to be a valid callback, 'wp_tiny_mce_preload_dialogs'

    • 12/03/11 12:50pm

      Sébastien | French WordpressDesigner says:

      i use wp 3.2

      http://core.trac.wordpress.org/ticket/18001
      this link seems to say that wp3.2 need another method.

      "wp_tiny_mce_preload_dialogs() got removed and has changed into wp_preload_dialogs(). The tiny_mce_preload_dialogs hook just disappeared with this, breaking a lot of plugins."

      Could you write the code for wp3.2 please ?

  • avatar
    Last edited:
    12/04/11
    9:47am
    jevusi says:

    Sebastien, the code you need is very simple :

    <?php

    wp_enqueue_script(array('jquery', 'editor', 'thickbox', 'media-upload'));
    wp_enqueue_style('thickbox');

    add_action("admin_head","myplugin_load_tiny_mce");

    function myplugin_load_tiny_mce() {
    wp_tiny_mce( false );
    }



    and your original code :


    add_action('admin_menu', 'slh_panel_menu');
    function slh_panel_menu() {
    add_menu_page('Réglages du site', 'Option du site', 1, __FILE__, 'slh_panel');
    }

    function slh_panel() {
    $template_uri = get_template_directory_uri();
    if( $_POST ) {
    $slh_panel_options_old = get_option( 'slh_panel_options' );
    $slh_panel_options = $_POST;
    $slh_panel_options['content'] = stripslashes( $_POST['content'] );
    update_option('slh_panel_options', $slh_panel_options);

    ?>

    <div class="updated"><center> <b>Les réglages sont enregistrés !</b></center></div>
    <?php
    }
    $slh_panel_options = get_option('slh_panel_options');
    ?>
    <form name="slh_form" id="slh_form" action="" method="post" enctype="multipart/form-data">
    <div id="poststuff"><? echo $slh_panel_options['content']; ?>
    <div id="<?php echo user_can_richedit() ? 'postdivrich' : 'postdiv'; ?>" class="postarea">
    <?php the_editor($slh_panel_options['content']); ?>
    </div>
    </div>


    <div id="heading">
    <fieldset>
    <input value="" class="save" type="submit">
    </fieldset>
    </div><!-- heading ends -->
    </form>
    <?php
    } ?>

    • 12/04/11 10:25am

      jevusi says:

      yeh Jevusi ! Awesome ! It's totally perfect ! Thanks ! That's excatly the response i need !

    • 12/04/11 10:26am

      jevusi says:

      Is it not what you want to say to me ? ^^

This question has expired.



Sébastien | French WordpressDesigner, Julio Potier, Luis Abarca voted on this question.



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.