I propose to define an API for user account plugins, such as Memberpages and Register_XH (and others which may be developed in the future). There are already some plugins which (are able to) work in combination with the mentioned plugins, for instance, Forum_XH and Schedule_XH. Currently this is done by accessing the username that is stored in the session; however, I consider this to be a very brittle solution, because it ties to an implementation detail (the name of the session variable might change, and the user name might not even be stored in the session at all). I had presented a quick idea for Register_XH a while ago, but this is probably too closely tied to this very plugin and its way to manage the user permissions. Basically a single function to get the current user name would suffice.
However, there is another issue. Multiple times it has been requested to display the full user name for Forum_XH and Schedule_XH. This might be solved by adding another API which returns the full user name, but this would raise problems when the full user name is changed later, what is easily possible in the control panels of Memberpages and Register_XH. So it seems reasonable to have a single function which returns the current user as an object, which has an immutable ID and offers methods to retrieve the user name resp. the full name. Any plugin which uses the login information of a conforming user account plugin could store the ID when needed, and access the other information for display purposes.
The user objects might implement the following interface:
Code: Select all
interface User
{
/**
* Returns the immutable ID of this user.
*
* If the username will never change, it may be the username.
* Otherwise a uniqid() or the value of an autoincrement field could be
* returned.
*
* @return mixed
*/
public function getId();
/**
* Returns the username of this user.
*
* @return string
*/
public function getUsername();
/**
* Returns the full name of this user.
*
* @return string
*/
public function getFullName();
}
Anyhow, there is still the need to retrieve the user object. Two simple functions in $pth['plugin_classes'] would seem to be sufficient:
Code: Select all
function getCurrentUser() {
// ...
};
function getUserById($id) {
// ...
};
Any thoughts?
Christoph