繁体   English   中英

如何在wordpress中基于登录用户添加条件?

[英]How to add condition based on logged in user in wordpress?

我需要一些帮助来显示特定用户的特定内容。 期望类似于以下内容

if( is_username('john')
{
  $echo 'Welcome john. You are from india.';
} else {
  $echo 'You have no rights to access this page...';
}

它应该仅通过用户名(文本)而不是通过user_id或任何整数来检查条件。 可能??

使用get_currentuserinfo(),然后将$current_user->user_login与要检查的用户名进行比较。

例如:

get_currentuserinfo()
if($current_user->user_login == 'the_username') {
    echo 'woop';
} else {
    echo 'nope';
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM