2015-10-15 125 views
1

我正在嘗試獲取WordPress用戶的價值。我正在嘗試使用get_users()wp函數。我如何從這個數組對象中得到roles鍵的[用戶角色]值。 我的PHP代碼從WordPress對象數組中獲取數據?

echo '<pre>'; 
var_dump(get_users()); 
echo '</pre>'; 

什麼返回下面的代碼

array(4) { 
     [0]=> 
     object(WP_User)#510 (7) { 
     ["data"]=> 
     object(stdClass)#506 (10) { 
      ["ID"]=> 
      string(2) "12" 
      ["user_login"]=> 
      string(4) "demo" 
      ["user_pass"]=> 
      string(34) "$P$Bp7wAWdn9qAPehmbEVcGz7DGGjc.lm1" 
      ["user_nicename"]=> 
      string(4) "demo" 
      ["user_email"]=> 
      string(18) "[email protected]" 
      ["user_url"]=> 
      string(19) "http://demouser.com" 
      ["user_registered"]=> 
      string(19) "2015-10-14 12:34:02" 
      ["user_activation_key"]=> 
      string(45) "1444826043:$P$BT2rYlAjdNo5OqzG7U3CvZw/sdnFqE." 
      ["user_status"]=> 
      string(1) "0" 
      ["display_name"]=> 
      string(9) "demo user" 
     } 
     ["ID"]=> 
     int(12) 
     ["caps"]=> 
     array(1) { 
      ["new_contributor"]=> 
      bool(true) 
     } 
     ["cap_key"]=> 
     string(15) "wp_capabilities" 
     ["roles"]=> 
     array(1) { 
      [0]=> 
      string(15) "new_contributor" 
     } 
     ["allcaps"]=> 
     array(4) { 
      ["read"]=> 
      bool(true) 
      ["edit_posts"]=> 
      bool(true) 
      ["delete_posts"]=> 
      bool(false) 
      ["new_contributor"]=> 
      bool(true) 
     } 
     ["filter"]=> 
     NULL 
     } 
+1

https://codex.wordpress.org/Function_Reference/ get_users – vrajesh

+0

請不要大喊。注意你的舉止 –

回答