我正在写一个基本的插件。 这里是我的代码:
$new_user = get_userdata($user_id); //$user_id is passed as a parameter
$first_name1 = $new_user->user_firstname;
$last_name1 = $new_user->user_lastname;
echo "<" . $first_name1 . $last_name1 . ">";
//returns: <>
$first_name2 = $new_user-first_name;
$last_name2 = $new_user->last_name;
echo "<" . $first_name2 . $last_name2 . ">";
//returns: <>
根据食品法典委员会 ,这应该工作,但是当我回声$first_name
或$last_name
他们是空的。 奇怪的是, 这并不工作:
$id = $new_user->ID;
难道我做错了什么?
更新:
我var_dump
ED $new_user
和这些属性都没有在那里! 这是因为我从/亩-plugins目录插件里面调用它? 做这些特性得到后来又增加?
object(WP_User)#334 (7) { ["data"]=> object(stdClass)#330 (10) { ["ID"]=> string(3) "758" ["user_login"]=> string(7) "emerson" ["user_pass"]=> string(34) "$P$BB2PuvRbyGUSVZR1M8FLSujPvMO2MW0" ["user_nicename"]=> string(7) "emerson" ["user_email"]=> string(16) "123esl@gmail.com" ["user_url"]=> string(0) "" ["user_registered"]=> string(19) "2012-08-17 01:03:27" ["user_activation_key"]=> string(0) "" ["user_status"]=> string(1) "0" ["display_name"]=> string(7) "emerson" } ["ID"]=> int(758) ["caps"]=> array(1) { ["subscriber"]=> string(1) "1" } ["cap_key"]=> string(15) "wp_capabilities" ["roles"]=> array(1) { [0]=> string(10) "subscriber" } ["allcaps"]=> array(15) { ["read"]=> bool(true) ["level_0"]=> bool(true) ["read_questions"]=> bool(true) ["read_answers"]=> bool(true) ["publish_questions"]=> bool(true) ["immediately_publish_questions"]=> bool(true) ["publish_answers"]=> bool(true) ["read_private_forums"]=> bool(true) ["publish_topics"]=> bool(true) ["edit_topics"]=> bool(true) ["publish_replies"]=> bool(true) ["edit_replies"]=> bool(true) ["assign_topic_tags"]=> bool(true) ["access_s2member_level0"]=> bool(true) ["subscriber"]=> string(1) "1" } ["filter"]=> NULL }
UPDATE2:
我尝试这样做:
$user_meta = get_user_meta( $new_user->ID );
var_dump($user_meta);
我得到这个(姓氏和FIRST_NAME是空的,即使他们在用户的个人资料正在定义的):
array(11) { ["wp_user_level"]=> array(1) { [0]=> string(1) "0" } ["show_admin_bar_front"]=> array(1) { [0]=> string(4) "true" } ["wp_capabilities"]=> array(1) { [0]=> string(32) "a:1:{s:10:"subscriber";s:1:"1";}" } ["use_ssl"]=> array(1) { [0]=> string(1) "0" } ["admin_color"]=> array(1) { [0]=> string(5) "fresh" } ["comment_shortcuts"]=> array(1) { [0]=> string(5) "false" } ["rich_editing"]=> array(1) { [0]=> string(4) "true" } ["description"]=> array(1) { [0]=> string(0) "" } ["nickname"]=> array(1) { [0]=> string(7) "emerson" } ["last_name"]=> array(1) { [0]=> string(0) "" } ["first_name"]=> array(1) { [0]=> string(0) "" } }