您可以使用wp_get_current_user()
这应该可以做到:
$current_user = wp_get_current_user();
if ( is_user_logged_in() ) {
wp_redirect( \'http://www.domain.com/author/\'.$current_user->user_login.\'/achievements/\');
exit;
} else {
echo \'You have no business being here\';
}
另请参见
wp_get_current_user()
文档
如果您在以下环境中运行:Warning: Cannot modify header information - headers already sent by
将此添加到functions.php
:
add_action(\'init\', \'do_output_buffer\');
function do_output_buffer() {
ob_start();
}