activate_plugin() – Attempts activation of plugin in a "sandbox" and redirects on success.

You appear to be a bot. Output may be restricted

Description

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

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.

Usage

$null|WP_Error = activate_plugin( $plugin, $redirect, $network_wide, $silent );

Parameters

$plugin
( string ) required – Path to the plugin file relative to the plugins directory.
$redirect
( string ) optional – Optional. URL to redirect to.
$network_wide
( bool ) optional – Optional. Whether to enable the plugin for all sites in the network or just the current site. Multisite only. Default false.
$silent
( bool ) optional – Optional. Whether to prevent calling activation hooks. Default false.

Returns

null|WP_Error Null on success, WP_Error on invalid file.

Source

File name: wordpress/wp-admin/includes/plugin.php
Lines:

101 to 102 of 102
  return null;
}
 

 View on GitHub View on Trac