Sometimes, one extension’s ability to function depends on the presence
of another extension. The
pm_Extension
class is used to collect information and perform basic operations on
extensions:
- Retrieve information on installed extensions,
- Check extensions version, state,
- Install/uninstall, enable/disable extensions.
Retrieving Extensions Data
Use the following methods to retrieve information on installed
extensions.
-
getExtensions()
- Retrieve the list of all installed extensions, -
getById($id)
- Get the extension by its identifier.
The following code retrieves all installed extensions, then fetches
their IDs and activity states.
$extensions = pm_Extension::getExtensions();
foreach ($extensions as $extension) {
$extension->getId();
$extension->isActive();
}
The following methods fetch the extension’s data:
-
getId()
- extension ID, -
getName()
- extension’s display name, -
getVersion()
- version number, -
getRelease()
- release number, -
isActive()
- extension’s activity state.
The following code retrieves the WP Toolkit extension (ID:
"wp-toolkit"
), then fetches its display name and activity state.
$extension = pm_Extension::getById("wp-toolkit");
$extension->getName();
$extension->isActive();
Controlling Extensions
The
pm_Extension
class also provides methods to enable and disable installed extensions,
and to install and uninstall extensions:
-
enable()
- change extension’s state to enabled, -
disable()
- change extension’s state to disabled, -
installById()
- install the extension specified by its ID, -
installByUrl()
- install the extension from the specified URL, -
installByFile()
- install the extension from the specified file, -
uninstall()
- uninstall the extension.