$current_user - Получить имя и фамилию текущего пользователя

750 views
Skip to first unread message

Cyrill KALITA

unread,
Jun 15, 2012, 12:40:45 PM6/15/12
to ru-wor...@googlegroups.com
У меня есть пользователь с указанными Именем и Фамилией

Я использую вот такой код:

global $current_user;
get_currentuserinfo();

if (($current_user->user_firstname + $current_user->user_lastname)<>'') { 
$display_user_name=$current_user->user_firstname + ' ' + $current_user->user_lastname;
} else {
$display_user_name=$current_user->display_name;
}

Дамп $current_user не показывает, что имя или фамилия вообще есть

WP_User Object ( 
[data] => stdClass Object ( 
[ID] => 1 
[user_login] => admin 
[user_pass] => XXXXXXXXXXXXXXXXX 
[user_nicename] => admin 
[user_email] => XXXXXXXXXXX 
[user_url] => 
[user_registered] => 2012-06-15 06:49:14 
[user_activation_key] => 
[user_status] => 0 
[display_name] => admin ) 
[ID] => 1 
[caps] => Array ( 
[administrator] => 1 ) 
[cap_key] => nga_capabilities 
[roles] => Array ( 
[0] => administrator )
[allcaps] => Array ( 
[switch_themes] => 1 
[edit_themes] => 1 
[activate_plugins] => 1 
[edit_plugins] => 1 
[edit_users] => 1 
[edit_files] => 1 
[manage_options] => 1 
[moderate_comments] => 1 
[manage_categories] => 1 
[manage_links] => 1 
[upload_files] => 1 
[import] => 1 
[unfiltered_html] => 1 
[edit_posts] => 1 
[edit_others_posts] => 1 
[edit_published_posts] => 1 
[publish_posts] => 1 
[edit_pages] => 1 
[read] => 1 
[level_10] => 1 
[level_9] => 1 
[level_8] => 1 
[level_7] => 1 
[level_6] => 1 
[level_5] => 1 
[level_4] => 1 
[level_3] => 1 
[level_2] => 1 
[level_1] => 1 
[level_0] => 1 
[edit_others_pages] => 1 
[edit_published_pages] => 1 
[publish_pages] => 1 
[delete_pages] => 1 
[delete_others_pages] => 1 
[delete_published_pages] => 1 
[delete_posts] => 1 
[delete_others_posts] => 1 
[delete_published_posts] => 1 
[delete_private_posts] => 1 
[edit_private_posts] => 1 
[read_private_posts] => 1 
[delete_private_pages] => 1 
[edit_private_pages] => 1 
[read_private_pages] => 1 
[delete_users] => 1 
[create_users] => 1 
[unfiltered_upload] => 1 
[edit_dashboard] => 1 
[update_plugins] => 1 
[delete_plugins] => 1 
[install_plugins] => 1 
[update_themes] => 1 
[install_themes] => 1 
[update_core] => 1 
[list_users] => 1 
[remove_users] => 1 
[add_users] => 1 
[promote_users] => 1 
[edit_theme_options] => 1 
[delete_themes] => 1 
[export] => 1 
[administrator] => 1 ) 
[filter] => )

Я схожу с ума

Cyrill KALITA

unread,
Jun 15, 2012, 12:49:56 PM6/15/12
to ru-wor...@googlegroups.com
Итить-колотить, вот что бывает от долгого сидения во фреймоворках и кофия.
Все не так, все не так как надо

global $current_user;
get_currentuserinfo();

if ($current_user->user_firstname.$current_user->user_lastname!='') {
$display_user_name=$current_user->user_firstname.' '.$current_user->user_lastname;
} else {
$display_user_name=$current_user->display_name;
}


И все работает
ЗЫ. Откуда я взяк такую бешенную конкатенацию?

Yantar

unread,
Jun 15, 2012, 12:53:27 PM6/15/12
to ru-wor...@googlegroups.com
из джаваскрипта? :) с пятницей!
--
С уважением,
Яна Таран



2012/6/15 Cyrill KALITA <cyrill...@gmail.com>

Cyrill KALITA

unread,
Jun 15, 2012, 12:58:36 PM6/15/12
to ru-wor...@googlegroups.com
Привет, Яна!

Оттуда, оттуда :)

К

2012/6/15 Yantar <nachb...@gmail.com>

Александр Павлов

unread,
Jun 16, 2012, 11:16:35 AM6/16/12
to ru-wor...@googlegroups.com
Подозреваю, что вызов get_currentuserinfo(); лишний на странице профиля в частности. В глобальной переменной $current_user уже на странице профиля будут данные содержаться.

Упрощаем код :)

Reply all
Reply to author
Forward
0 new messages