douzhaocheng4533 2015-06-28 23:40
浏览 58

根据用户角色显示WordPress页面模板

I want to display page templates dependent on what user is currently logged in (user role).

WordPress has a built in page attributes dropdown selection for templates. Here's an example of the functionality I'm looking for.

Scenario #1: Editor is logged into the WordPress dashboard. They go to create a page. In the page UI they select the dropdown for templates. The drop down only contains templates: A, B, and C.

Scenario #2: Admin is logged into the WordPress dashboard. They go to create a page. In the page UI they select the dropdown for templates. The drop down shows templates: A, B, C, D, and E.

Basically I'm trying to figure out how to display a limited amount of templates based on the user's role and all templates if the user's role is an Admin.

  • 写回答

1条回答 默认 最新

  • dqmgjp5930 2015-06-29 05:02
    关注

    you can use somthing like this:

    function get_user_role() {
        global $current_user;
    
        $user_roles = $current_user->roles;
        $user_role = array_shift($user_roles);
    
        return $user_role;
    }
    

    then in your html theme you simply put <?php echo get_user_role(); ?>.

    it will give you that which user is logged in then u can do whatever you want.

    评论

报告相同问题?

悬赏问题

  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序