Wordpress login form script

时间:2013-01-14 作者:Kaneda

I am looking for something very simple but I\'m not quite sure how to achieve this. I have been researching for the past 2-3 hours and gathered a lot of useful information. However, my knowledge in both PHP and WordPress isn\'t enough to do this from scratch.

What I need is the following:

  • When the user is not logged in, this HTML code should be displayed:

    <a href="#">Login</a>
    
  • When the user is logged in, the previous HTML code should be replaced with:

    <span>Welcome, *username*</span>
    <a href="actual-link-for-logging-out-the-user">Logout</a>
    

Could anyone please help me out. I\'d really appreciate the help :)

Thanks

1 个回复
最合适的回答,由SO网友:Dan 整理而成

您将要使用is_user_logged_in() 处理此问题的条件标记。

global $current_user;
get_currentuserinfo();

if ( is_user_logged_in() ) {
  echo "<span>Welcome $current_user->user_login</span>".
       "<a href=\'".wp_logout_url()."\'>Logout</a>";
} else {
  echo \'<a href="#">Login</a>\';
}
引用的其他功能:wp_logout_url() &;get_currentuserinfo()

仅供参考,所有这些都可以在谷歌或WordPress Codex.

结束

相关推荐

更新USER_LOGIN以更改用户名

我正在尝试更新user_login 在wp_users 表,以强制在提交前端编辑配置文件表单时将用户的用户名更新到其电子邮件地址。我知道WordPress禁止通过wp_update_user 所以我尝试将SQL与wpdb函数一起使用。以下是我所拥有的,但它不起作用:(global $wpdb; $tablename = $wpdb->prefix . \"users\"; $sql = $wpdb->prepare( \"UPDATE \".$tablename.\" SET