dsgoj7457 2015-10-23 14:53
浏览 39

Wordpress当前用户admin入队脚本

I'm having a problem to solve, I need to include a CSS file in my WordPress admin just when the user have a specific role.

I'm having a problem because I don't know how I can do this, follow my code from now!

    function RequireBootstrap($current_user){
    global $WP_User;
    if( in_array( $_GET['page'], array("abeta", "custom-user") , TRUE)):
        wp_register_style('Bootstap_CSS', RequireURL('Library/Bootstrap/css/bootstrap.css') );
        wp_enqueue_style( 'Bootstap_CSS');

        wp_register_script( 'Bootstap_JS', RequireURL('Library/Bootstrap/js/bootstrap.min.js'), '1.0.0', true );
        wp_enqueue_script( 'Bootstap_JS' );
    endif;

    $current_user = wp_get_current_user();
    if('associado' == $current_user->caps):
        wp_register_style( 'CSSPrincipal', RequireURL('Admin/CSS/Style.css'), '1.0.0', true );
        wp_enqueue_style( 'CSSPrincipal' );
    endif;
}
add_action('admin_enqueue_scripts',  'RequireBootstrap', 10, 3);

I hope you can help me!

Thanks!

  • 写回答

1条回答 默认 最新

  • dqrnskni67375 2015-10-23 15:15
    关注

    You should use the current_user_canfunction.

    Then pass in a parameter of the role you want.

    e.g:

    current_user_can('Administrator')
    
    评论

报告相同问题?

悬赏问题

  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 个人网站被恶意大量访问,怎么办
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制