• Resolved chrisdornan

    (@chrisdornan)


    In this post I asked about invoking TinyMCE and I my question was answered very well, but with the caveat that I probably wanted to enable the editor only on the pages I actually use it on, and indeed I do! My problem is how do I ascertain what page I am on from the header of an administration page (where the JavaScript gets enabled). I had a look at $_POST to see if i could pick out the page parameter but it had already been eaten. Presumably it is lying around in a template tag somewhere. Any help much appreciated.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter chrisdornan

    (@chrisdornan)

    I may not have expressed myself very well, and made a mistake at the crucial point–I will try again.

    I am using ‘wp_enqueue_script’ to insert javascrip into the head (to configure TinyMCE). I really don’t want to do this on every page as TinyMCE gets used in many configurations–I just want to configure TinyMCE on my own page. How can I determine that I am on one of my own administrative pages in some code on the ‘admin_menu’ hook?

    Normally code specific to your page gets placed in functions attached to the apropriate hooks (such as ‘add_options_page’). But once this code has been activated it is too late to be queueing up javascript, soo I have to find out whether my admin page is being displayed at an earlier point in the process (e.g., on the ‘admin_menu’ hook). Unfortunately the ‘page’ parameter in the $_POST arguments, used to select the admin page to display, seems to have been processed and removed by the time I come to insert (or not) the java script on the ‘admin_menu’ hook. None of my searches of the codex and source code have yet yielded the variable, function or class that I can use to find this information. I hope this is clearer. Sorry for the confusion.

    I think this discussion might help.

    Thread Starter chrisdornan

    (@chrisdornan)

    OK I have solved my problem. There is a mechanism for enabling admin scripts on specific options pages; see admin_print_scripts-(page_hook) or admin_print_scripts-(plugin_page). This code fragment is all you need:

    function myplugin_menu() {
      if ( function_exists('add_management_page') ) {
        $page = add_management_page( 'myplugin', 'myplugin', 9, __FILE__, 'myplugin_admin_page' );
        add_action( "admin_print_scripts-$page", 'myplugin_admin_head' );
      }
    }

    Thnk to Vladimir Prelovac for help. Check out his article Best practice for adding JavaScript code to WordPress plugins and his new book WordPress Plugin Development, pact with goodies for the aspiring WordPress hacker, ahem, programmer.

    Thread Starter chrisdornan

    (@chrisdornan)

    apljdi: Dead right; it was just what I was looking for, though I had got there by independent means. Thanks very much for your help.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Which Admin page am I on’ is closed to new replies.