[wp-hackers] Re: Plugin interference
Alexander Beutl
xel at netgra.de
Thu Apr 10 17:23:59 GMT 2008
jep sure this is nearly as I did it
function my_head() {
if( $_GET['page'] = 'mypage' {
// doit
}
}
but what I wanted to know is how to use the hooks which are especially
designed for not needing this:
admin_head-(page_hook) or admin_head-(plugin_page)
Runs in the HTML <head> section of the admin panel of a plugin-generated
page.
and
admin_print_scripts-(page_hook) or admin_print_scripts-(plugin_page)
Runs to print JavaScript scripts in the HTML head section of a specific
plugin-generated admin page.
(you will find them here:
http://codex.wordpress.org/Plugin_API/Action_Reference#Administrative_Actions)
This ones were my prefered way to do that - if I just could figure out, what
that stuff to add after the normal hookname is - everything I tried just
didn't do anything...
2008/4/10, gbellucci <gabellucci at gmail.com>:
>
>
> Here is a simple example that includes:
> 1. registering your scripts and dependencies
> 2. gets the requested URI and looks for the name of your registered
> plugin file
> 3. adds one of several actions that will add information before the
> </head> tag
>
> /* Register your scripts with WordPress via the wp script loader*/
> register_script(
> 'your-script-handle',
> 'path-to-script/script_name.js',
> array('jquery', 'depends-on-script-handle', ...), 'your-script-
> version-num');
>
> /* get the currently requested URL */
> $uri = $_SERVER['REQUEST_URI'];
>
> /* Looking for my plugin's php entry point */
> if( stristr($uri, '<your_plugin>.php') != false ) {
>
> // add action here for injecting scripts or css
> add_action('wp_print_scripts', array('classname',
> 'function_name'));
> // or
> add_action('wp_admin_head', array('classname', 'function_name'));
> // or
> wp_enqueue_script(...)
> // or
> admin_print_scripts(...);
> }
> else {
> ; /* not my page - so nothing to do */
> }
>
> I'm sure everyone does this a little bit differently, however, the
> most important aspect of this is to only inject java script on pages
> that you create for your plugin's backend options or on backend pages
> that your scripts interact with - not on backend pages that are used
> as administration/option pages created for use by other plugins.
>
> Other gotch's include NOT injecting jQuery.js before Prototype.js
>
> Maybe others have suggestions
>
>
>
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>
More information about the wp-hackers
mailing list