1

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?

2 Answers 2

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
}
1
  • Yes, I did that actually, and I keep the code in the callback function. I noticed that I just needed to copy more code from users-new.php to make it work..
    – Galivan
    Commented Nov 25, 2015 at 15:15
0

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).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.