PluginsService

Type
Class
Namespace
Craft
Inherits
Craft\PluginsService » Craft\BaseApplicationComponent » CApplicationComponent (opens new window) » CComponent (opens new window)
Implements
IApplicationComponent
Since
1.0

PluginsService provides APIs for managing plugins.

An instance of PluginsService is globally accessible in Craft via {@link WebApp::plugins craft()->plugins}.

See also http://craftcms.com

View source (opens new window)

# Public Properties

Property Description
$autoloadClasses array (opens new window)
$behaviors (opens new window) array (opens new window) – The behaviors that should be attached to this component.

# $autoloadClasses

Signature

public array $autoloadClasses = null

# Public Methods

Method Description
__call() (opens new window) Calls the named method which is not a class method.
__get() (opens new window) Returns a property value, an event handler list or a behavior based on its name.
__isset() (opens new window) Checks if a property value is null.
__set() (opens new window) Sets value of a component property.
__unset() (opens new window) Sets a component property to be null.
arePluginsLoaded() Returns whether plugins have been loaded yet for this request.
asa() (opens new window) Returns the named behavior object.
attachBehavior() (opens new window) Attaches a behavior to this component.
attachBehaviors() (opens new window) Attaches a list of behaviors to the component.
attachEventHandler() (opens new window) Attaches an event handler to an event.
call() Calls a method on all plugins that have it, and returns an array of the results, indexed by plugin handles.
callFirst() Calls a method on the first plugin that has it, and returns the result.
callHook() Calls a method on all plugins that have the method.
canGetProperty() (opens new window) Determines whether a property can be read.
canSetProperty() (opens new window) Determines whether a property can be set.
detachBehavior() (opens new window) Detaches a behavior from the component.
detachBehaviors() (opens new window) Detaches all behaviors from the component.
detachEventHandler() (opens new window) Detaches an existing event handler.
disableBehavior() (opens new window) Disables an attached behavior.
disableBehaviors() (opens new window) Disables all behaviors attached to this component.
disablePlugin() Disables a plugin by its handle.
doesPluginClassExist() Returns whether a plugin class exists.
doesPluginRequireDatabaseUpdate() Returns whether the given plugin’s local schema version is greater than the record we have in the database.
enableBehavior() (opens new window) Enables an attached behavior.
enableBehaviors() (opens new window) Enables all behaviors attached to this component.
enablePlugin() Enables a plugin by its handle.
evaluateExpression() (opens new window) Evaluates a PHP expression or callback under the context of this component.
getEventHandlers() (opens new window) Returns the list of attached event handlers for an event.
getIsInitialized() (opens new window) Checks if this application component has been initialized.
getPlugin() Returns a plugin by its handle.
getPluginClasses() Returns an array of class names found in a given plugin folder.
getPluginIconUrl() Returns a given plugin’s icon URL.
getPluginInfo() Returns the stored info for a given plugin.
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.
getPlugins() Returns all the plugins.
hasEvent() (opens new window) Determines whether an event is defined.
hasEventHandler() (opens new window) Checks whether the named event has attached handlers.
hasPluginVersionNumberChanged() Returns whether the given plugin’s version number has changed from what we have recorded in the database.
hasProperty() (opens new window) Determines whether a property is defined.
init() (opens new window) Initializes the application component.
installPlugin() Installs a plugin by its handle.
isInitialized() Checks if this application component has been initialized yet, or not.
loadPlugins() Loads the enabled plugins.
onLoadPlugins() Fires an 'onLoadPlugins' event.
raiseEvent() (opens new window) Raises an event.
savePluginSettings() Saves a plugin's settings.
setPluginLicenseKey() Sets a plugin’s license key.
setPluginLicenseKeyStatus() Sets the license key status for a given plugin.
uninstallPlugin() Uninstalls a plugin by its handle.

# arePluginsLoaded()

Returns whether plugins have been loaded yet for this request.

View source (opens new window)

Returns

boolean (opens new window) – Whether plugins have been loaded yet.

Signature

public boolean arePluginsLoaded ( )

# call()

Calls a method on all plugins that have it, and returns an array of the results, indexed by plugin handles.

View source (opens new window)

Arguments

Returns

array (opens new window) – An array of the plugins’ responses.

Signature

public array call ( $method, $args = [], $ignoreNull = false )

# callFirst()

Calls a method on the first plugin that has it, and returns the result.

View source (opens new window)

Arguments

Returns

mixed – The plugin’s response, or null.

Signature

public mixed callFirst ( $method, $args = [], $ignoreNull = false )

# callHook()

DEPRECATED

Deprecated Deprecated in 1.0. Use {@link call()} instead.

Calls a method on all plugins that have the method.

View source (opens new window)

Arguments

Returns

array (opens new window) – An array of the plugins’ responses.

Signature

public array callHook ( $method, $args = [] )

# disablePlugin()

Disables a plugin by its handle.

View source (opens new window)

Arguments

Returns

boolean (opens new window) – Whether the plugin was disabled successfully.

Throws

Signature

public boolean disablePlugin ( $handle )

# doesPluginClassExist()

Returns whether a plugin class exists.

View source (opens new window)

Arguments

Returns

boolean (opens new window) – Whether the class exists.

Signature

public boolean doesPluginClassExist ( Craft\BasePlugin $plugin, $classSubfolder, $class, $autoload = true )

# doesPluginRequireDatabaseUpdate()

Returns whether the given plugin’s local schema version is greater than the record we have in the database.

View source (opens new window)

Arguments

Returns

boolean (opens new window) – Whether the plugin’s local schema version is greater than the record we have in the database.

Signature

public boolean doesPluginRequireDatabaseUpdate ( Craft\BasePlugin $plugin )

# enablePlugin()

Enables a plugin by its handle.

View source (opens new window)

Arguments

Returns

boolean (opens new window) – Whether the plugin was enabled successfully.

Throws

Signature

public boolean enablePlugin ( $handle )

# getPlugin()

Returns a plugin by its handle.

View source (opens new window)

Arguments

Returns

Craft\BasePlugin, null (opens new window) – The plugin.

Signature

public Craft\BasePlugin, null getPlugin ( $handle, $enabledOnly = true )

# getPluginClasses()

Returns an array of class names found in a given plugin folder.

View source (opens new window)

Arguments

Returns

array (opens new window) – The class names.

Signature

public array getPluginClasses ( Craft\BasePlugin $plugin, $classSubfolder, $classSuffix, $autoload = true )

# getPluginIconUrl()

Returns a given plugin’s icon URL.

View source (opens new window)

Arguments

Returns

string (opens new window)

Signature

public string getPluginIconUrl ( $pluginHandle, $size = 100 )

# getPluginInfo()

Returns the stored info for a given plugin.

View source (opens new window)

Arguments

Returns

array (opens new window), null (opens new window) – The stored info, if there is any.

Signature

public array, null getPluginInfo ( Craft\BasePlugin $plugin )

# getPluginLicenseKey()

Returns the license key stored for a given plugin, if it was purchased through the Store.

View source (opens new window)

Arguments

Returns

string (opens new window), null (opens new window) – The plugin’s license key, or null if it isn’t known

Signature

public string, null getPluginLicenseKey ( $pluginHandle )

# getPluginLicenseKeyStatus()

Returns the license key status of a given plugin.

View source (opens new window)

Arguments

Returns

string (opens new window), false (opens new window)

Signature

public string, false getPluginLicenseKeyStatus ( $pluginHandle )

# getPlugins()

Returns all the plugins.

View source (opens new window)

Arguments

Returns

Craft\BasePlugin[] – The plugins.

Signature

public Craft\BasePlugin[] getPlugins ( $enabledOnly = true )

# hasPluginVersionNumberChanged()

Returns whether the given plugin’s version number has changed from what we have recorded in the database.

View source (opens new window)

Arguments

Returns

boolean (opens new window) – Whether the plugin’s version number has changed from what we have recorded in the database

Signature

public boolean hasPluginVersionNumberChanged ( Craft\BasePlugin $plugin )

# installPlugin()

Installs a plugin by its handle.

View source (opens new window)

Arguments

Returns

boolean (opens new window) – Whether the plugin was installed successfully.

Throws

  • \Craft\Exception|\Exception

Signature

public boolean installPlugin ( $handle )

# loadPlugins()

Loads the enabled plugins.

View source (opens new window)

Returns

null (opens new window)

Signature

public null loadPlugins ( )

# onLoadPlugins()

Fires an 'onLoadPlugins' event.

View source (opens new window)

Arguments

Returns

null (opens new window)

Signature

public null onLoadPlugins ( Craft\Event $event )

# savePluginSettings()

Saves a plugin's settings.

View source (opens new window)

Arguments

Returns

boolean (opens new window) – Whether the plugin’s settings were saved successfully.

Signature

public boolean savePluginSettings ( Craft\BasePlugin $plugin, $settings )

# setPluginLicenseKey()

Sets a plugin’s license key. Note this should not be used to store license keys generated by third party stores.

View source (opens new window)

Arguments

Returns

void

Throws

Signature

public void setPluginLicenseKey ( $pluginHandle, $licenseKey )

# setPluginLicenseKeyStatus()

Sets the license key status for a given plugin.

View source (opens new window)

Arguments

Returns

void

Signature

public void setPluginLicenseKeyStatus ( $pluginHandle, $licenseKeyStatus )

# uninstallPlugin()

Uninstalls a plugin by its handle.

View source (opens new window)

Arguments

Returns

boolean (opens new window) – Whether the plugin was uninstalled successfully.

Throws

  • \Craft\Exception|\Exception

Signature

public boolean uninstallPlugin ( $handle )