donglie7268 2014-10-28 21:13 采纳率: 100%
浏览 18
已采纳

检测用户角色以及此特定用户角色是否显示唯一内容(Wordpress PHP)

I have tried everything and have been searching high and low; I am seeking to write a PHP solution that sniffs out what user role is logged; eg a custom user role named 'Site Manager' and if that user role is logged in.. show a unique hyper link.

Or even, all user types / roles EXCEPT 'Site Managers' hide link.

I have tried the below but it does not work.. Please note no special privileges has been defined for Site Managers and am seeking not to create filters or anything like that; I just want to use 'if user logged in as this role' then show.

<?php 
global $user_login, $current_user; 

if (is_user_logged_in()) {
    get_currentuserinfo();
    $user_info = get_userdata($current_user->ID);
    if (in_array('site managers', $user_info->roles)) { 
?>    
<li><a href="<?php echo get_site_url(); ?>/wpcsv-export.csv">Download Inventory of Mobile Apps</a></li>
<?php
    }
}
?> 

I tried the above but it won't work!

  • 写回答

1条回答 默认 最新

  • doukang8949 2014-10-28 21:18
    关注

    There is nothing explicitly wrong with the code you presented. Confirm that the name/slug for Site Managers is as you have in your code site managers. The name is most likely site_managers.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 三种调度算法报错 采用的你的方案
  • ¥15 关于#python#的问题,请各位专家解答!
  • ¥15 对于这个问题的解释说明
  • ¥200 询问:python实现大地主题正反算的程序设计,有偿
  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败