[英]Create a modal popup welcome message in WordPress dashboard
I have been trying to use this code to create a modal popup that welcomes user in the WordPress dashboard when one logins with the following snippet at the functions.php or a plugin but it doesn't seem to load anything / even the thickbox. 我一直在尝试使用此代码创建一个模式弹出窗口,当一个人使用functions.php或插件中的以下代码段登录时,它会在WordPress仪表板中欢迎用户,但它似乎并未加载任何内容,甚至没有加载thickbox。
Hope someone helps. 希望有人帮助。 Thanks.
谢谢。
add_action('admin_init', 'open_modal'); function open_modal(){ $id = get_current_user_id(); $user = get_userdata($id); if(in_array('administrator', $user->roles)){ ?> <script> function call_to_open_modal(){ //your code goes here... } call_to_open_modal(); </script> <?php } }
Are you getting any errors in console? 您在控制台中遇到任何错误吗? Try to echo your javascript inside the function :
尝试在函数内回显您的JavaScript:
add_action('admin_init', 'open_modal');
function open_modal(){
$id = get_current_user_id();
$user = get_userdata($id);
if(in_array('administrator', $user->roles)){
echo
"<script>
function call_to_open_modal(){
//your code goes here...
}
call_to_open_modal();
</script>";
} }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.