admin管理员组

文章数量:1391860

I created a sub page to "users.php" where I can add a user in a customized way. I used a lot of the code from "user-new.php". However, user-new.php seems to rely on some javascript file to display the password when clicking the button, and to display errors, and maybe more.

How do I know what script files "user-new.php" uses, where they are enqueued, and how I can enqueue it for my custom page?

I suppose I need to use "admin_enqueue_scripts" somehow?

I created a sub page to "users.php" where I can add a user in a customized way. I used a lot of the code from "user-new.php". However, user-new.php seems to rely on some javascript file to display the password when clicking the button, and to display errors, and maybe more.

How do I know what script files "user-new.php" uses, where they are enqueued, and how I can enqueue it for my custom page?

I suppose I need to use "admin_enqueue_scripts" somehow?

Share Improve this question asked Nov 25, 2015 at 14:05 GalivanGalivan 2535 silver badges18 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 2

You must have created submenu page using add_submenu_page() hook, so you can use wp_enqueue_script inside callback function of add_submenu_page hook. It will load script only on your submenu page.

add_submenu_page( $parent_slug, $page_title, $menu_title, $capability, $menu_slug,'callback');

function callback()
{
//enqueue script
}

Or if you want to enqueue script in dashboard(all pages) then you can enqueue script in admin_init hook

add_action( 'admin_init', 'function_name' );
function function_name()
{
//enqueue script
}

It turned out that there was more important code in "user-new.php" that I needed to copy, and the code for enqueuing the scripts were actually in that same file. So I needed these lines, particularly the second one:

wp_enqueue_script('wp-ajax-response');
wp_enqueue_script( 'user-profile' );

(plus some more of the code to display errors - I just copied it).

本文标签: Include script files for admin submenu page