2014-05-10 41 views
0

我需要一些幫助來顯示特定用戶的特定內容。期望類似於下面的內容如何在wordpress中添加基於登錄用戶的條件?

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

它應該僅通過用戶名(文本)而不是通過user_id或任何整數來檢查條件。可能??

+1

使用[get_currentuserinfo()](http://codex.wordpress.org/Function_Reference/get_currentuserinfo)然後比較'$ current_user-> user_login'的用戶名要檢查對於。 – Last1Here

+0

@ Last1Here感謝:) – Umar

+0

我發現這從那裏,它的工作:)'<?php if($ current_user-> user_login =='the_username'){?> <! - 歡迎用戶或顯示頁面內容 - >

歡迎 user_firstname>

< - ????!讓訪問者知道訪問被拒絕 - >

走開!

' – Umar

回答

1

使用get_currentuserinfo()然後將$current_user->user_login與您要檢查的用戶名進行比較。

例如:

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