Forum Replies Created

Viewing 5 replies - 1 through 5 (of 5 total)
  • Forum: Plugins
    In reply to: Which Admin page am I on
    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.

    Thread Starter chrisdornan

    (@chrisdornan)

    See the follow up thread, Which Admin Page amd I on? for the full reolution, where, , as advised by apljdi, I find out how to ‘add a switch so that you are only loading this stuff on the pages you need it on’.

    Forum: Plugins
    In reply to: Which Admin page am I on
    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.

    Forum: Plugins
    In reply to: Which Admin page am I on
    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.

    Thread Starter chrisdornan

    (@chrisdornan)

    That has certainly got me going–thanks!

Viewing 5 replies - 1 through 5 (of 5 total)