“我应该使用哪个属性”的简短回答:Use first_name and last_name.
详细回答:
属性
first_name,
user_firstname,
last_name 和
user_lastname 定义在
WP_User class, 尽管名称不同(即
user_ 另一个没有前缀):
两者first_name 和user_firstname 使用first_name 元两者last_name 和user_lastname 使用last_name 元但是user_firstname 和user_lastname WordPress中是否使用了2.0.0版之前的属性名称(14年前…)-看见get_the_author_firstname() 和get_the_author_lastname() here 和here, 这些属性是still supported for backward compatibility, 但是我们应该只使用那些没有user_ 前缀(例如。first_name 而不是user_firstname).
// Both of these return the same value - the value of the meta named first_name.
var_dump(
get_the_author_meta( \'user_firstname\' ), // works
get_the_author_meta( \'first_name\' ) // but better
);
// Both of these return the same value - the value of the meta named first_name.
$current_user = wp_get_current_user();
var_dump(
$current_user->user_firstname, // works
$current_user->first_name // but better/shorter...
);