简体   繁体   English

WordPress-根据用户是否登录,在自定义模板上弹出注册表单

[英]Wordpress- Popup a registration form on a custom template based on whether user logged in or not

Basically I have a custom page template and when users visit that page I want to check whether he/she is logged in or not. 基本上,我有一个自定义页面模板,当用户访问该页面时,我想检查他/她是否已登录。 If logged in then fine else generate a popup form for registration. 如果登录,则可以,否则生成一个弹出表格进行注册。

<?php global $current_user;
  get_currentuserinfo();

  if($current_user->ID == '')
    //Generate a popup......
?>

I would be obliged if anybody can guide me how to do it. 如果有人可以指导我怎么做,我将有义务。

You can use is_user_logged_in() 您可以使用is_user_logged_in()

Docs 文件

One approach for the popup would be to print out some javascript that triggered the hidden popup if the user was logged in. 弹出窗口的一种方法是,如果用户登录,则打印出一些会触发隐藏弹出窗口的JavaScript。

This should do it, 这应该做到的

if ( is_user_logged_in() ) {
    //$current_user = wp_get_current_user();
    //echo 'Hi '.$current_user->user_firstname;
} else {
    //Code for Popup etc
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM