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 badges2 Answers
Reset to default 2You 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
版权声明:本文标题:Include script files for admin submenu page 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744771501a2624367.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论