Domain
To retrieve information about a domain, use the pm_Domain class.
The pm_Domain class represents a domain hosted in Plesk. This class supports retrieving information about a domain by its ID.
Retrieving domain information
To retrieve the various data about a domain, use these methods:
- getName() - returns the domain name.
- getProperty() - returns various properties from the domains table in the Plesk database.
- getGuid() - returns the domain GUID.
- getDisplayName() - returns the domain display name.
- getIpAddresses() - returns the domain IP addresses (IPv4 or IPv6 or both). By default, public IP addresses are returned. If the $public argument is set to “false”, the internal IP addresses are returned instead.
- isActive() - returns “true” if the domain is active, “false” otherwise.
- isSuspended() - returns “true” if the domain is suspended, “false” otherwise.
- isDisabled() - returns “true” if the domain is disabled, “false” otherwise.
- hasHosting() - returns “true” if the domain has web hosing type; “false” otherwise.
- getHomePath() - returns the webspace home path.
- getSysUserLogin() - returns login of the webspace system user.
- getDocumentRoot() - returns the domain document root directory. Available only for domains with web hosting. By default, an absolute path is returned. If the $relative argument is set to “true”, the root directory relative to the home path is returned.
- getVhostSystemPath() - returns the domain vhost system directory. Available only for domains with web hosting.
Also, there following static methods can be used for retrieving domains:
- getByDomainId() - retrieves the domain by domain id.
- getByGuid() - retrieves the domain by domain GUID.
- getByName() - retrieves the domain by domain display name.
-
getAllDomains()
- retrieves all domains, including additional domains and subdomains.
If the
$mainDomainsOnly
argument is set to “true”, only main domains are returned. -
getDomainsByClient()
- retrieves all domains, including additional domains and subdomains
owned by
$client
. If the$mainDomainsOnly
argument is set to “true”, only main domains are returned.
You can also use the pm_View_Helper_DomainOverviewUrl class to help you build the URL to the Domain Overview page.
Storing and Retrieving Domain-specific Data
It is possible to store and retrieve arbitrary data for a specific domain. The following methods add new data records, retrieve existing data and remove records that are no longer needed:
Note: These serve as a key-value storage for a specific domain.
Examples
To retrieve the name and creation date of a domain, use the following code:
$domain = new pm_Domain($domainId);
echo "Domain name: {$domain->getName()}";
echo "Created at {$domain->getProperty('cr_date')}";