简体   繁体   中英

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()

Docs

One approach for the popup would be to print out some javascript that triggered the hidden popup if the user was logged in.

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
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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