Search

activate_plugin( string $plugin, string $redirect = '', bool $network_wide = false, bool $silent = false )

Attempts activation of plugin in a “sandbox” and redirects on success.

Description Description

A plugin that is already activated will not attempt to be activated again.

The way it works is by setting the redirection to the error before trying to include the plugin file. If the plugin fails, then the redirection will not be overwritten with the success message. Also, the options will not be updated and the activation hook will not be called on plugin error.

It should be noted that in no way the below code will actually prevent errors within the file. The code should not be used elsewhere to replicate the "sandbox", which uses redirection to work. {@source 13 1}

If any errors are found or text is outputted, then it will be captured to ensure that the success redirection will update the error redirection.


Parameters Parameters

$plugin

(string) (Required) Path to the plugin file relative to the plugins directory.

$redirect

(string) (Optional) URL to redirect to.

Default value: ''

$network_wide

(bool) (Optional) Whether to enable the plugin for all sites in the network or just the current site. Multisite only.

Default value: false

$silent

(bool) (Optional) Whether to prevent calling activation hooks.

Default value: false


Top ↑

Return Return

(WP_Error|null) WP_Error on invalid file or null on success.


The files of WordPress characterize many helpful PHP functions. A portion of the functions, known as Template Tags, are characterized particularly for use in WordPress Themes. There are likewise a few functions identified with actions and filters (the Plugin API), which are in this way utilized principally for creating Plugins. The rest are utilized to make the core WordPress functionality. Huge numbers of the core WordPress functions are helpful to Plugin and Theme developers.