[英]show content based on logged in user=role in wordpress with PHP
I have this working ok: 我的工作正常:
<?php global $user_login; get_currentuserinfo();
if ($user_login) :?>
<li><a href="<?php echo get_site_url(); ?>/wp-admin/admin.php?page=download_report&download_report">Download Inventory of Mobile Apps</a></li>
<?php endif; ?>
But I am seeking to alter it to display this specific content based on logged in user ROLE. 但是我试图根据登录的用户ROLE更改它以显示此特定内容。 So basically something like if role is=administrator show, if not hide for all other logged in users.
因此,基本上,例如如果角色is = administrator显示,或者如果不是隐藏其他所有登录用户,则类似。
|||| |||| How can I alter my current code to write an if statement that checks for logged in user role then if specific role like admin, show content;
如何更改当前代码以编写if语句,以检查登录的用户角色,然后检查特定角色(例如admin)是否显示内容; and if not hide?
如果不躲起来?
Fail Log: Recent: 失败日志: 最近:
<?php global $user_login; get_currentuserinfo();
if( is_user_logged_in() ) {
if( !current_user_can( 'administrator' ) ) { :?>
<li><a href="<?php echo get_site_url(); ?>/wp-admin/admin.php?page=download_report&download_report">Download Inventory of Mobile Apps</a></li>
<?php endif; ?>
Most Recent: 最近:
<?php
global $user_login, $current_user;
get_currentuserinfo();
$user_info = get_userdata($current_user->ID);
if (in_array('administrator', $user_info->roles)) {
<li><a href="<?php echo get_site_url(); ?>/wp-admin/admin.php?page=download_report&download_report">Download Inventory of Mobile Apps</a></li>
}
?>
Perhaps something like: 也许像这样:
<?php
global $user_login, $current_user;
if (is_user_logged_in()) {
get_currentuserinfo();
$user_info = get_userdata($current_user->ID);
if (in_array('administrator', $user_info->roles)) {
// content
}
}
?>
Combined with your most recent code: 结合您最近的代码:
<?php
global $user_login, $current_user;
if (is_user_logged_in()) {
get_currentuserinfo();
$user_info = get_userdata($current_user->ID);
if (in_array('administrator', $user_info->roles)) {
?>
<li><a href="<?php echo get_site_url(); ?>/wp-admin/admin.php?page=download_report&download_report">Download Inventory of Mobile Apps</a></li>
<?php
}
}
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.