Class craft\services\Plugins
- Inheritance
- craft\services\Plugins » yii\base\Component » yii\base\BaseObject
- Implements
- yii\base\Configurable
- Available since version
- 3.0
- Source Code
- https://github.com/craftcms/cms/blob/master/src/services/Plugins.php
The Plugins service provides APIs for managing plugins.
An instance of the Plugins service is globally accessible in Craft via Craft::$app->plugins
.
Method | Description | Defined By |
---|---|---|
__call() |
Calls the named method which is not a class method. | yii\base\BaseObject |
__clone() |
This method is called after the object is created by cloning an existing one. | yii\base\Component |
__construct() |
Constructor. | yii\base\BaseObject |
__get() |
Returns the value of an object property. | yii\base\BaseObject |
__isset() |
Checks if a property is set, i.e. defined and not null. | yii\base\BaseObject |
__set() |
Sets value of an object property. | yii\base\BaseObject |
__unset() |
Sets an object property to null. | yii\base\BaseObject |
arePluginsLoaded() |
Returns whether plugins have been loaded yet for this request. | craft\services\Plugins |
attachBehavior() |
Attaches a behavior to this component. | yii\base\Component |
attachBehaviors() |
Attaches a list of behaviors to the component. | yii\base\Component |
behaviors() |
Returns a list of behaviors that this component should behave as. | yii\base\Component |
canGetProperty() |
Returns a value indicating whether a property can be read. | yii\base\BaseObject |
canSetProperty() |
Returns a value indicating whether a property can be set. | yii\base\BaseObject |
className() |
Returns the fully qualified name of this class. | yii\base\BaseObject |
createPlugin() |
Creates and returns a new plugin instance based on its handle. | craft\services\Plugins |
detachBehavior() |
Detaches a behavior from the component. | yii\base\Component |
detachBehaviors() |
Detaches all behaviors from the component. | yii\base\Component |
disablePlugin() |
Disables a plugin by its handle. | craft\services\Plugins |
doesPluginRequireDatabaseUpdate() |
Returns whether the given plugin’s local schema version is greater than the record we have in the database. | craft\services\Plugins |
enablePlugin() |
Enables a plugin by its handle. | craft\services\Plugins |
ensureBehaviors() |
Makes sure that the behaviors declared in behaviors() are attached to this component. | yii\base\Component |
getAllPluginInfo() |
Returns info about all of the plugins we can find, whether they’re installed or not. | craft\services\Plugins |
getAllPlugins() |
Returns all the enabled plugins. | craft\services\Plugins |
getBehavior() |
Returns the named behavior object. | yii\base\Component |
getBehaviors() |
Returns all behaviors attached to this component. | yii\base\Component |
getComposerPluginInfo() |
Returns the Composer-supplied info | craft\services\Plugins |
getPlugin() |
Returns an enabled plugin by its handle. | craft\services\Plugins |
getPluginByPackageName() |
Returns an enabled plugin by its package name. | craft\services\Plugins |
getPluginHandleByClass() |
Returns the plugin handle that contains the given class, if any. | craft\services\Plugins |
getPluginIconSvg() |
Returns a plugin’s SVG icon. | craft\services\Plugins |
getPluginLicenseKey() |
Returns the license key stored for a given plugin, if it was purchased through the Store. | craft\services\Plugins |
getPluginLicenseKeyStatus() |
Returns the license key status of a given plugin. | craft\services\Plugins |
getStoredPluginInfo() |
Returns the stored info for a given plugin. | craft\services\Plugins |
hasEventHandlers() |
Returns a value indicating whether there is any handler attached to the named event. | yii\base\Component |
hasMethod() |
Returns a value indicating whether a method is defined. | yii\base\BaseObject |
hasPluginVersionNumberChanged() |
Returns whether the given plugin’s version number has changed from what we have recorded in the database. | craft\services\Plugins |
hasProperty() |
Returns a value indicating whether a property is defined. | yii\base\BaseObject |
init() |
Initializes the object. | craft\services\Plugins |
installPlugin() |
Installs a plugin by its handle. | craft\services\Plugins |
isPluginDisabled() |
Returns whether a given plugin is installed but disabled. | craft\services\Plugins |
isPluginEnabled() |
Returns whether a given plugin is installed and enabled. | craft\services\Plugins |
isPluginInstalled() |
Returns whether a given plugin is installed (even if it's disabled). | craft\services\Plugins |
loadPlugins() |
Loads the enabled plugins. | craft\services\Plugins |
off() |
Detaches an existing event handler from this component. | yii\base\Component |
on() |
Attaches an event handler to an event. | yii\base\Component |
savePluginSettings() |
Saves a plugin's settings. | craft\services\Plugins |
setPluginLicenseKey() |
Sets a plugin’s license key. | craft\services\Plugins |
setPluginLicenseKeyStatus() |
Sets the license key status for a given plugin. | craft\services\Plugins |
trigger() |
Triggers an event. | yii\base\Component |
uninstallPlugin() |
Uninstalls a plugin by its handle. | craft\services\Plugins |
Method Details
arePluginsLoaded()
public method
#
Returns whether plugins have been loaded yet for this request.
public boolean arePluginsLoaded ( )
createPlugin()
public method
#
Creates and returns a new plugin instance based on its handle.
public craft\base\PluginInterface createPlugin ( \craft\services\string $handle, array $row = null )
$handle |
string | The plugin’s handle |
$row |
array, null | The plugin’s row in the plugins table, if any |
throws | craft\errors\InvalidPluginException | if $handle is invalid |
---|
disablePlugin()
public method
#
Disables a plugin by its handle.
public boolean disablePlugin ( \craft\services\string $handle )
$handle |
string | The plugin’s handle |
return | boolean | Whether the plugin was disabled successfully |
---|---|---|
throws | craft\errors\InvalidPluginException | if the plugin isn’t installed |
doesPluginRequireDatabaseUpdate()
public method
#
Returns whether the given plugin’s local schema version is greater than the record we have in the database.
public boolean doesPluginRequireDatabaseUpdate ( craft\base\PluginInterface $plugin )
$plugin |
craft\base\PluginInterface | The plugin |
return | boolean | Whether the plugin’s local schema version is greater than the record we have in the database |
---|
enablePlugin()
public method
#
Enables a plugin by its handle.
public boolean enablePlugin ( \craft\services\string $handle )
$handle |
string | The plugin’s handle |
return | boolean | Whether the plugin was enabled successfully |
---|---|---|
throws | craft\errors\InvalidPluginException | if the plugin isn't installed |
getAllPluginInfo()
public method
#
Returns info about all of the plugins we can find, whether they’re installed or not.
public array getAllPluginInfo ( )
getAllPlugins()
public method
#
Returns all the enabled plugins.
public craft\base\PluginInterface[] getAllPlugins ( )
getComposerPluginInfo()
public method
#
Returns the Composer-supplied info
public array, null getComposerPluginInfo ( \craft\services\string $handle = null )
$handle |
string, null | The plugin handle. If null is passed, info for all Composer-installed plugins will be returned. |
return | array, null | The plugin info, or null if an unknown handle was passed. |
---|
getPlugin()
public method
#
Returns an enabled plugin by its handle.
public craft\base\PluginInterface, null getPlugin ( \craft\services\string $handle )
$handle |
string | The plugin’s handle |
return | craft\base\PluginInterface, null | The plugin, or null if it doesn’t exist |
---|
getPluginByPackageName()
public method
#
Returns an enabled plugin by its package name.
public craft\base\PluginInterface, null getPluginByPackageName ( \craft\services\string $packageName )
$packageName |
string | The plugin’s package name |
return | craft\base\PluginInterface, null | The plugin, or null if it doesn’t exist |
---|
getPluginHandleByClass()
public method
#
Returns the plugin handle that contains the given class, if any.
The plugin may not actually be installed.
public string, null getPluginHandleByClass ( \craft\services\string $class )
$class |
string | |
return | string, null | The plugin handle, or null if it can’t be determined |
---|
getPluginIconSvg()
public method
#
Returns a plugin’s SVG icon.
public string getPluginIconSvg ( \craft\services\string $handle )
$handle |
string | The plugin’s handle |
return | string | The given plugin’s SVG icon |
---|
getPluginLicenseKey()
public method
#
Returns the license key stored for a given plugin, if it was purchased through the Store.
public string, null getPluginLicenseKey ( \craft\services\string $handle )
$handle |
string | The plugin’s handle |
return | string, null | The plugin’s license key, or null if it isn’t known |
---|
getPluginLicenseKeyStatus()
public method
#
Returns the license key status of a given plugin.
public string getPluginLicenseKeyStatus ( \craft\services\string $handle )
$handle |
string | The plugin’s handle |
getStoredPluginInfo()
public method
#
Returns the stored info for a given plugin.
public array, null getStoredPluginInfo ( \craft\services\string $handle )
$handle |
string | The plugin handle |
return | array, null | The stored info, if there is any |
---|
hasPluginVersionNumberChanged()
public method
#
Returns whether the given plugin’s version number has changed from what we have recorded in the database.
public boolean hasPluginVersionNumberChanged ( craft\base\PluginInterface $plugin )
$plugin |
craft\base\PluginInterface | The plugin |
return | boolean | Whether the plugin’s version number has changed from what we have recorded in the database |
---|
init()
public method
#
Initializes the object.
This method is invoked at the end of the constructor after the object is initialized with the given configuration.
public void init ( )
installPlugin()
public method
#
Installs a plugin by its handle.
public boolean installPlugin ( \craft\services\string $handle )
$handle |
string | The plugin’s handle |
return | boolean | Whether the plugin was installed successfully. |
---|---|---|
throws | craft\errors\InvalidPluginException | if the plugin doesn’t exist |
throws | Throwable | if reasons |
isPluginDisabled()
public method
#
Returns whether a given plugin is installed but disabled.
public boolean isPluginDisabled ( \craft\services\string $handle )
$handle |
string | The plugin handle |
isPluginEnabled()
public method
#
Returns whether a given plugin is installed and enabled.
public boolean isPluginEnabled ( \craft\services\string $handle )
$handle |
string | The plugin handle |
isPluginInstalled()
public method
#
Returns whether a given plugin is installed (even if it's disabled).
public boolean isPluginInstalled ( \craft\services\string $handle )
$handle |
string | The plugin handle |
loadPlugins()
public method
#
Loads the enabled plugins.
public void loadPlugins ( )
savePluginSettings()
public method
#
Saves a plugin's settings.
public boolean savePluginSettings ( craft\base\PluginInterface $plugin, array $settings )
$plugin |
craft\base\PluginInterface | The plugin |
$settings |
array | The plugin’s new settings |
return | boolean | Whether the plugin’s settings were saved successfully |
---|
setPluginLicenseKey()
public method
#
Sets a plugin’s license key.
Note this should not be used to store license keys generated by third party stores.
public boolean setPluginLicenseKey ( \craft\services\string $handle, \craft\services\string $licenseKey = null )
$handle |
string | The plugin’s handle |
$licenseKey |
string, null | The plugin’s license key |
return | boolean | Whether the license key was updated successfully |
---|---|---|
throws | craft\errors\InvalidPluginException | if the plugin isn't installed |
throws | craft\errors\InvalidLicenseKeyException | if $licenseKey is invalid |
setPluginLicenseKeyStatus()
public method
#
Sets the license key status for a given plugin.
public void setPluginLicenseKeyStatus ( \craft\services\string $handle, \craft\services\string $licenseKeyStatus = null )
$handle |
string | The plugin’s handle |
$licenseKeyStatus |
string, null | The plugin’s license key status |
throws | craft\errors\InvalidPluginException | if the plugin isn't installed |
---|
uninstallPlugin()
public method
#
Uninstalls a plugin by its handle.
public boolean uninstallPlugin ( \craft\services\string $handle )
$handle |
string | The plugin’s handle |
return | boolean | Whether the plugin was uninstalled successfully |
---|---|---|
throws | craft\errors\InvalidPluginException | if the plugin doesn’t exist |
throws | Throwable | if reasons |
Event Details
EVENT_AFTER_DISABLE_PLUGIN
event of type craft\events\PluginEvent
#
The event that is triggered before a plugin is disabled
EVENT_AFTER_ENABLE_PLUGIN
event of type craft\events\PluginEvent
#
The event that is triggered before a plugin is enabled
EVENT_AFTER_INSTALL_PLUGIN
event of type craft\events\PluginEvent
#
The event that is triggered before a plugin is installed
EVENT_AFTER_LOAD_PLUGINS
event of type yii\base\Event
#
The event that is triggered after all plugins have been loaded
EVENT_AFTER_SAVE_PLUGIN_SETTINGS
event of type craft\events\PluginEvent
#
The event that is triggered before a plugin's settings are saved
EVENT_AFTER_UNINSTALL_PLUGIN
event of type craft\events\PluginEvent
#
The event that is triggered before a plugin is uninstalled
EVENT_BEFORE_DISABLE_PLUGIN
event of type craft\events\PluginEvent
#
The event that is triggered before a plugin is disabled
EVENT_BEFORE_ENABLE_PLUGIN
event of type craft\events\PluginEvent
#
The event that is triggered before a plugin is enabled
EVENT_BEFORE_INSTALL_PLUGIN
event of type craft\events\PluginEvent
#
The event that is triggered before a plugin is installed
EVENT_BEFORE_LOAD_PLUGINS
event of type yii\base\Event
#
The event that is triggered before any plugins have been loaded
EVENT_BEFORE_SAVE_PLUGIN_SETTINGS
event of type craft\events\PluginEvent
#
The event that is triggered before a plugin's settings are saved
EVENT_BEFORE_UNINSTALL_PLUGIN
event of type craft\events\PluginEvent
#
The event that is triggered before a plugin is uninstalled