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.

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

报告相同问题?

悬赏问题

  • ¥15 MATLAB四叉树处理长方形tif文件
  • ¥15 java业务性能问题求解(sql,业务设计相关)
  • ¥15 52810 尾椎c三个a 写蓝牙地址
  • ¥15 elmos524.33 eeprom的读写问题
  • ¥15 使用Java milo连接Kepserver服务端报错?
  • ¥15 用ADS设计一款的射频功率放大器
  • ¥15 怎么求交点连线的理论解?
  • ¥20 软件开发方法学习来了
  • ¥15 微信小程序商城如何实现多商户收款 平台分润抽成
  • ¥15 HC32L176调试了一个通过TIMER5+DMA驱动WS2812B