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

检测用户角色以及此特定用户角色是否显示唯一内容(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!

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.