Topics

Users

In this article we are talking about visitor of your website (not the administrator) and how to implement login / registration. ImpressPages provides an interface to set / get data about currently logged in user (see code examples bellow). But it doesn't implement any exact implementation of user login / registration process. If you want these features to be enabled on your website, please install User plugin

You can build your own registration plugin. Just execute ipUser()->login($userId) function to inform ImpressPages and other plugins about the user being logged in. 

If you just need to get the status if user is logged in or not, use ipUser()->isLoggedIn() or ipUser()->getId(). This way you can write plugins that react to user status, but don't depend on actual plugin being installed. 

Get current user ID

<?php
echo ipUser()->userId();

Check user login status

<?php
if (ipUser()->isLoggedIn()) {
    echo "You are logged in";
} else {
    echo "Please log in";
}

Log in a user

<?php ipUser()->login($userId); ?>

Log out a user

<?php ipUser()->logout($userId); ?>

 Get user data

Get all data about the user as an associative array.

<?php ipUser()->data() ?> //user id can be passed as a first parameter

If your plugin knows some data about the user (eg. telephone number, address, etc.) that could be useful to other plugins, you can catch ipUserData filter and add that data to the array. There are no rules how you have to call those fields. It is just an interface to share data about the user across the plugins.

comments powered by Disqus