Plugins ​
- Type
- Class
- Namespace
- craft\services
- Inherits
- craft\services\Plugins » yii\base\Component » yii\base\BaseObject
- Implements
- yii\base\Configurable
- Since
- 3.0.0
The Plugins service provides APIs for managing plugins.
An instance of the service is available via Craft::$app->plugins
.
Public Properties ​
Property | Description |
---|---|
allPluginInfo | array |
allPlugins | craft\base\PluginInterface[] |
behaviors | yii\base\Behavior – List of behaviors attached to this component. |
composerPluginInfo | array, null – The plugin info, or null if an unknown handle was passed. |
pluginConfigs | array[] – Custom plugin configurations. |
pluginLicenseKey | string – The plugin’s handle |
allPluginInfo
​
- Type
- array
- Default value
null
- Access
- Read-only
allPlugins
​
- Type
- craft\base\PluginInterface[]
- Default value
null
- Access
- Read-only
composerPluginInfo
​
The plugin info, or null if an unknown handle was passed.
pluginConfigs
​
- Type
- array[]
- Default value
null
- Since
- 3.4.0
Custom plugin configurations.
pluginLicenseKey
​
- Type
- string
- Default value
null
- Access
- Write-only
The plugin’s handle
Public Methods ​
Method | Description |
---|---|
__call() | Calls the named method which is not a class method. |
__clone() | This method is called after the object is created by cloning an existing one. |
__construct() | Constructor. |
__get() | Returns the value of a component property. |
__isset() | Checks if a property is set, i.e. defined and not null. |
__set() | Sets the value of a component property. |
__unset() | Sets a component property to be null. |
arePluginsLoaded() | Returns whether plugins have been loaded yet for this request. |
attachBehavior() | Attaches a behavior to this component. |
attachBehaviors() | Attaches a list of behaviors to the component. |
behaviors() | Returns a list of behaviors that this component should behave as. |
canGetProperty() | Returns a value indicating whether a property can be read. |
canSetProperty() | Returns a value indicating whether a property can be set. |
className() | Returns the fully qualified name of this class. |
createPlugin() | Creates and returns a new plugin instance based on its handle. |
detachBehavior() | Detaches a behavior from the component. |
detachBehaviors() | Detaches all behaviors from the component. |
disablePlugin() | Disables a plugin by its handle. |
enablePlugin() | Enables a plugin by its handle. |
ensureBehaviors() | Makes sure that the behaviors declared in behaviors() are attached to this component. |
getAllPluginInfo() | Returns info about all of the plugins we can find, whether they’re installed or not. |
getAllPlugins() | Returns all the enabled plugins. |
getBehavior() | Returns the named behavior object. |
getBehaviors() | Returns all behaviors attached to this component. |
getComposerPluginInfo() | Returns the Composer-supplied info |
getLicenseIssues() | Returns any issues with a plugin license. |
getPlugin() | Returns an enabled plugin by its handle. |
getPluginByPackageName() | Returns an enabled plugin by its package name. |
getPluginHandleByClass() | Returns the plugin handle that contains the given class, if any. |
getPluginIconSvg() | Returns a plugin’s SVG icon. |
getPluginInfo() | Returns info about a plugin, whether it's installed or not. |
getPluginLicenseKey() | Returns the license key stored for a given plugin, if it was purchased through the Store. |
getPluginLicenseKeyStatus() | Returns the license key status of a given plugin. |
getStoredPluginInfo() | Returns the stored info for a given plugin. |
hasEventHandlers() | Returns a value indicating whether there is any handler attached to the named event. |
hasIssues() | Returns whether a plugin has licensing issues. |
hasMethod() | Returns a value indicating whether a method is defined. |
hasPluginVersionNumberChanged() | Returns whether the given plugin’s version number has changed from what we have recorded in the database. |
hasProperty() | Returns a value indicating whether a property is defined for this component. |
init() | Initializes the object. |
installPlugin() | Installs a plugin by its handle. |
isPluginDisabled() | Returns whether a given plugin is installed but disabled. |
isPluginEnabled() | Returns whether a given plugin is installed and enabled. |
isPluginInstalled() | Returns whether a given plugin is installed (even if it's disabled). |
isPluginUpdatePending() | Returns whether the given plugin’s local schema version is greater than the record we have in the database. |
loadPlugins() | Loads the enabled plugins. |
normalizePluginLicenseKey() | Normalizes a plugin license key. |
off() | Detaches an existing event handler from this component. |
on() | Attaches an event handler to an event. |
savePluginSettings() | Saves a plugin’s settings. |
setPluginLicenseKey() | Sets a plugin’s license key. |
switchEdition() | Switches a plugin’s edition. |
trigger() | Triggers an event. |
uninstallPlugin() | Uninstalls a plugin by its handle. |
updatePluginVersionInfo() | Updates a plugin’s stored version & schema version to match what’s Composer-installed. |
arePluginsLoaded()
​
Returns whether plugins have been loaded yet for this request.
Returns ​
createPlugin()
​
Creates and returns a new plugin instance based on its handle.
Arguments ​
$handle
(string) – The plugin’s handle$info
(array, null) – The plugin’s stored info, if any
Returns ​
craft\base\PluginInterface, null
Throws ​
- craft\errors\InvalidPluginException
if $handle is invalid
disablePlugin()
​
Disables a plugin by its handle.
Arguments ​
$handle
(string) – The plugin’s handle
Returns ​
boolean – Whether the plugin was disabled successfully
Throws ​
- craft\errors\InvalidPluginException
if the plugin isn’t installed
enablePlugin()
​
Enables a plugin by its handle.
Arguments ​
$handle
(string) – The plugin’s handle
Returns ​
boolean – Whether the plugin was enabled successfully
Throws ​
- craft\errors\InvalidPluginException
if the plugin isn't installed
getAllPluginInfo()
​
Returns info about all of the plugins we can find, whether they’re installed or not.
Returns ​
getAllPlugins()
​
Returns all the enabled plugins.
Returns ​
getComposerPluginInfo()
​
Returns the Composer-supplied info
Arguments ​
$handle
(string, null) – The plugin handle. If null is passed, info for all Composer-installed plugins will be returned.
Returns ​
array, null – The plugin info, or null if an unknown handle was passed.
getLicenseIssues()
​
Returns any issues with a plugin license.
The response will be an array containing a combination of these strings:
wrong_edition
– if the current edition isn't the licensed one, and testing editions isn't allowedmismatched
– if the license key is tied to a different Craft licenseastray
– if the installed version is greater than the highest version the license is allowed to runrequired
– if no license key is present but one is requiredinvalid
– if a license key is present but it’s invalid
Arguments ​
$handle
(string)
Returns ​
string[]
getPlugin()
​
Returns an enabled plugin by its handle.
Arguments ​
$handle
(string) – The plugin’s handle
Returns ​
craft\base\PluginInterface, null – The plugin, or null if it doesn’t exist
getPluginByPackageName()
​
Returns an enabled plugin by its package name.
Arguments ​
$packageName
(string) – The plugin’s package name
Returns ​
craft\base\PluginInterface, null – The plugin, or null if it doesn’t exist
getPluginHandleByClass()
​
Returns the plugin handle that contains the given class, if any.
The plugin may not actually be installed.
Arguments ​
$class
(class-string
)
Returns ​
string, null – The plugin handle, or null if it can’t be determined
getPluginIconSvg()
​
Returns a plugin’s SVG icon.
Arguments ​
$handle
(string) – The plugin’s handle
Returns ​
string – The given plugin’s SVG icon
getPluginInfo()
​
Returns info about a plugin, whether it's installed or not.
Arguments ​
$handle
(string) – The plugin’s handle
Returns ​
Throws ​
- craft\errors\InvalidPluginException
if the plugin isn't Composer-installed
getPluginLicenseKey()
​
Returns the license key stored for a given plugin, if it was purchased through the Store.
Arguments ​
$handle
(string) – The plugin’s handle
Returns ​
string, null – The plugin’s license key, or null if it isn’t known
Throws ​
getPluginLicenseKeyStatus()
​
Returns the license key status of a given plugin.
Arguments ​
$handle
(string) – The plugin’s handle
Returns ​
\craft\enums\LicenseKeyStatus
getStoredPluginInfo()
​
Returns the stored info for a given plugin.
Arguments ​
$handle
(string) – The plugin handle
Returns ​
array, null – The stored info, if there is any
hasIssues()
​
Returns whether a plugin has licensing issues.
Arguments ​
$handle
(string)
Returns ​
hasPluginVersionNumberChanged()
​
Returns whether the given plugin’s version number has changed from what we have recorded in the database.
Arguments ​
$plugin
(craft\base\PluginInterface) – The plugin
Returns ​
boolean – Whether the plugin’s version number has changed from what we have recorded in the database
init()
​
Initializes the object.
This method is invoked at the end of the constructor after the object is initialized with the given configuration.
installPlugin()
​
Installs a plugin by its handle.
Arguments ​
Returns ​
boolean – Whether the plugin was installed successfully.
Throws ​
- craft\errors\InvalidPluginException
if the plugin doesn’t exist - Throwable
if reasons
isPluginDisabled()
​
Returns whether a given plugin is installed but disabled.
Arguments ​
$handle
(string) – The plugin handle
Returns ​
isPluginEnabled()
​
Returns whether a given plugin is installed and enabled.
Arguments ​
$handle
(string) – The plugin handle
Returns ​
isPluginInstalled()
​
Returns whether a given plugin is installed (even if it's disabled).
Arguments ​
$handle
(string) – The plugin handle
Returns ​
isPluginUpdatePending()
​
- Since
- 4.0.0
Returns whether the given plugin’s local schema version is greater than the record we have in the database.
Arguments ​
$plugin
(craft\base\PluginInterface) – The plugin
Returns ​
boolean – Whether the plugin’s local schema version is greater than the record we have in the database
loadPlugins()
​
Loads the enabled plugins.
normalizePluginLicenseKey()
​
Normalizes a plugin license key.
Arguments ​
Returns ​
Throws ​
savePluginSettings()
​
Saves a plugin’s settings.
Arguments ​
$plugin
(craft\base\PluginInterface) – The plugin$settings
(array) – The plugin’s new settings
Returns ​
boolean – Whether the plugin’s settings were saved successfully
setPluginLicenseKey()
​
Sets a plugin’s license key.
Note this should not be used to store license keys generated by third party stores.
Arguments ​
Returns ​
boolean – Whether the license key was updated successfully
Throws ​
- craft\errors\InvalidPluginException
if the plugin isn't installed - craft\errors\InvalidLicenseKeyException
if $licenseKey is invalid
switchEdition()
​
Switches a plugin’s edition.
Arguments ​
Throws ​
- craft\errors\InvalidPluginException
if the plugin doesn’t exist - yii\base\InvalidArgumentException
if $edition is invalid - Throwable
if reasons
uninstallPlugin()
​
Uninstalls a plugin by its handle.
Arguments ​
$handle
(string) – The plugin’s handle$force
(boolean) – Whether to force the plugin uninstallation, even if it is disabled, itsuninstall()
method returnsfalse
, or its files aren’t present
Returns ​
boolean – Whether the plugin was uninstalled successfully
Throws ​
- craft\errors\InvalidPluginException
if the plugin doesn’t exist - Throwable
if reasons
updatePluginVersionInfo()
​
- Since
- 3.7.13
Updates a plugin’s stored version & schema version to match what’s Composer-installed.
Arguments ​
$plugin
(craft\base\PluginInterface)
Events ​
EVENT_AFTER_DISABLE_PLUGIN ​
The event that is triggered after a plugin is disabled
EVENT_AFTER_ENABLE_PLUGIN ​
The event that is triggered after a plugin is enabled
EVENT_AFTER_INSTALL_PLUGIN ​
The event that is triggered after a plugin is installed
EVENT_AFTER_LOAD_PLUGINS ​
- Type
- yii\base\Event
The event that is triggered after all plugins have been loaded
EVENT_AFTER_SAVE_PLUGIN_SETTINGS ​
The event that is triggered after a plugin’s settings are saved
EVENT_AFTER_UNINSTALL_PLUGIN ​
The event that is triggered after a plugin is uninstalled
EVENT_BEFORE_DISABLE_PLUGIN ​
The event that is triggered before a plugin is disabled
EVENT_BEFORE_ENABLE_PLUGIN ​
The event that is triggered before a plugin is enabled
EVENT_BEFORE_INSTALL_PLUGIN ​
The event that is triggered before a plugin is installed
EVENT_BEFORE_LOAD_PLUGINS ​
- Type
- yii\base\Event
The event that is triggered before any plugins have been loaded
EVENT_BEFORE_SAVE_PLUGIN_SETTINGS ​
The event that is triggered before a plugin’s settings are saved
EVENT_BEFORE_UNINSTALL_PLUGIN ​
The event that is triggered before a plugin is uninstalled