Retrieving User and Domain Data
Plesk XML API (XML API, http://docs.plesk.com/current/api-rpc/) and Command-Line Interface enable you to retrieve information about Plesk objects and edit these objects. However, if you need to retrieve properties of Plesk users and domains, you can easily do this by means of the pm_Client and pm_Domain classes. We recommend that you use these classes for retrieving information about session objects as described below.
The pm_Client class represents a Plesk user account. This class supports retrieving information about a user either by their ID or by their username. It also lets you identify a user's account type: administrator, reseller, or customer. Finally, this class contains the getProperty method that lets you retrieve any user information from the table clients in the Plesk database psa. Examples of pm_Client usage are provided below.
1. Retrieving user information by their ID and identifying their username and account type:
2. Retrieving user ID by their username:
The pm_Domain class represents a domain hosted in Plesk. This class supports retrieving information about a domain by its ID. Additionally, this class contains the getProperty method that lets you retrieve any domain information from the table domains in the Plesk database psa.
An example of pm_Domain usage is provided below.
If your extension needs to retrieve information from the user that is currently logged in to Plesk, use the pm_Session class.
For restricting user access to the extension, retrieve the pm_Client object. The following code restricts access for all users except administrators:
If an administrator or a reseller is logged in the Control Panel as one of their customers, you can retrieve the customer's identifier the following way:
Additionally, if the session is open in the Control Panel, you can retrieve information about the domain that is currently being operated on:
$domain in this example is an instance of the pm_Domain class.
If Plesk is unable to retrieve the domain, a pm_Exception will be thrown.