Don't call activation hooks when upgrading. Props joelhardi for initial patch. See #14915
git-svn-id: http://svn.automattic.com/wordpress/trunk@16012 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
1482db4c2d
commit
80ce121521
|
@ -460,10 +460,12 @@ function is_network_only_plugin( $plugin ) {
|
||||||
*
|
*
|
||||||
* @param string $plugin Plugin path to main plugin file with plugin data.
|
* @param string $plugin Plugin path to main plugin file with plugin data.
|
||||||
* @param string $redirect Optional. URL to redirect to.
|
* @param string $redirect Optional. URL to redirect to.
|
||||||
* @param bool $network_wide Whether to enable the plugin for all sites in the network or just the current site. Multisite only. Default is false.
|
* @param bool $network_wide Whether to enable the plugin for all sites in the
|
||||||
|
* network or just the current site. Multisite only. Default is false.
|
||||||
|
* @param bool $silent Prevent calling activation hooks. Optional, default is false.
|
||||||
* @return WP_Error|null WP_Error on invalid file or null on success.
|
* @return WP_Error|null WP_Error on invalid file or null on success.
|
||||||
*/
|
*/
|
||||||
function activate_plugin( $plugin, $redirect = '', $network_wide = false) {
|
function activate_plugin( $plugin, $redirect = '', $network_wide = false, $silent = false ) {
|
||||||
$plugin = plugin_basename( trim( $plugin ) );
|
$plugin = plugin_basename( trim( $plugin ) );
|
||||||
|
|
||||||
if ( is_multisite() && ( $network_wide || is_network_only_plugin($plugin) ) ) {
|
if ( is_multisite() && ( $network_wide || is_network_only_plugin($plugin) ) ) {
|
||||||
|
@ -482,8 +484,12 @@ function activate_plugin( $plugin, $redirect = '', $network_wide = false) {
|
||||||
wp_redirect(add_query_arg('_error_nonce', wp_create_nonce('plugin-activation-error_' . $plugin), $redirect)); // we'll override this later if the plugin can be included without fatal error
|
wp_redirect(add_query_arg('_error_nonce', wp_create_nonce('plugin-activation-error_' . $plugin), $redirect)); // we'll override this later if the plugin can be included without fatal error
|
||||||
ob_start();
|
ob_start();
|
||||||
include(WP_PLUGIN_DIR . '/' . $plugin);
|
include(WP_PLUGIN_DIR . '/' . $plugin);
|
||||||
do_action( 'activate_plugin', $plugin, $network_wide );
|
|
||||||
do_action( 'activate_' . $plugin, $network_wide );
|
if ( ! $silent ) {
|
||||||
|
do_action( 'activate_plugin', $plugin, $network_wide );
|
||||||
|
do_action( 'activate_' . $plugin, $network_wide );
|
||||||
|
}
|
||||||
|
|
||||||
if ( $network_wide ) {
|
if ( $network_wide ) {
|
||||||
$current[$plugin] = time();
|
$current[$plugin] = time();
|
||||||
update_site_option( 'active_sitewide_plugins', $current );
|
update_site_option( 'active_sitewide_plugins', $current );
|
||||||
|
@ -492,7 +498,11 @@ function activate_plugin( $plugin, $redirect = '', $network_wide = false) {
|
||||||
sort($current);
|
sort($current);
|
||||||
update_option('active_plugins', $current);
|
update_option('active_plugins', $current);
|
||||||
}
|
}
|
||||||
do_action( 'activated_plugin', $plugin, $network_wide );
|
|
||||||
|
if ( ! $silent ) {
|
||||||
|
do_action( 'activated_plugin', $plugin, $network_wide );
|
||||||
|
}
|
||||||
|
|
||||||
if ( ob_get_length() > 0 ) {
|
if ( ob_get_length() > 0 ) {
|
||||||
$output = ob_get_clean();
|
$output = ob_get_clean();
|
||||||
return new WP_Error('unexpected_output', __('The plugin generated unexpected output.'), $output);
|
return new WP_Error('unexpected_output', __('The plugin generated unexpected output.'), $output);
|
||||||
|
@ -512,7 +522,7 @@ function activate_plugin( $plugin, $redirect = '', $network_wide = false) {
|
||||||
* @since unknown
|
* @since unknown
|
||||||
*
|
*
|
||||||
* @param string|array $plugins Single plugin or list of plugins to deactivate.
|
* @param string|array $plugins Single plugin or list of plugins to deactivate.
|
||||||
* @param bool $silent Optional, default is false. Prevent calling deactivate hook.
|
* @param bool $silent Prevent calling deactivation hooks. Default is false.
|
||||||
*/
|
*/
|
||||||
function deactivate_plugins( $plugins, $silent = false ) {
|
function deactivate_plugins( $plugins, $silent = false ) {
|
||||||
if ( is_multisite() )
|
if ( is_multisite() )
|
||||||
|
@ -566,17 +576,18 @@ function deactivate_plugins( $plugins, $silent = false ) {
|
||||||
* @param string|array $plugins
|
* @param string|array $plugins
|
||||||
* @param string $redirect Redirect to page after successful activation.
|
* @param string $redirect Redirect to page after successful activation.
|
||||||
* @param bool $network_wide Whether to enable the plugin for all sites in the network.
|
* @param bool $network_wide Whether to enable the plugin for all sites in the network.
|
||||||
|
* @param bool $silent Prevent calling activation hooks. Default is false.
|
||||||
* @return bool|WP_Error True when finished or WP_Error if there were errors during a plugin activation.
|
* @return bool|WP_Error True when finished or WP_Error if there were errors during a plugin activation.
|
||||||
*/
|
*/
|
||||||
function activate_plugins($plugins, $redirect = '', $network_wide) {
|
function activate_plugins( $plugins, $redirect = '', $network_wide = false, $silent = false ) {
|
||||||
if ( !is_array($plugins) )
|
if ( !is_array($plugins) )
|
||||||
$plugins = array($plugins);
|
$plugins = array($plugins);
|
||||||
|
|
||||||
$errors = array();
|
$errors = array();
|
||||||
foreach ( (array) $plugins as $plugin ) {
|
foreach ( $plugins as $plugin ) {
|
||||||
if ( !empty($redirect) )
|
if ( !empty($redirect) )
|
||||||
$redirect = add_query_arg('plugin', $plugin, $redirect);
|
$redirect = add_query_arg('plugin', $plugin, $redirect);
|
||||||
$result = activate_plugin($plugin, $redirect, $network_wide);
|
$result = activate_plugin($plugin, $redirect, $network_wide, $silent);
|
||||||
if ( is_wp_error($result) )
|
if ( is_wp_error($result) )
|
||||||
$errors[$plugin] = $result;
|
$errors[$plugin] = $result;
|
||||||
}
|
}
|
||||||
|
|
|
@ -71,7 +71,7 @@ if ( isset($_GET['action']) ) {
|
||||||
check_admin_referer('activate-plugin_' . $plugin);
|
check_admin_referer('activate-plugin_' . $plugin);
|
||||||
if ( ! isset($_GET['failure']) && ! isset($_GET['success']) ) {
|
if ( ! isset($_GET['failure']) && ! isset($_GET['success']) ) {
|
||||||
wp_redirect( admin_url('update.php?action=activate-plugin&failure=true&plugin=' . $plugin . '&_wpnonce=' . $_GET['_wpnonce']) );
|
wp_redirect( admin_url('update.php?action=activate-plugin&failure=true&plugin=' . $plugin . '&_wpnonce=' . $_GET['_wpnonce']) );
|
||||||
activate_plugin( $plugin, '', ! empty( $_GET['networkwide'] ) );
|
activate_plugin( $plugin, '', ! empty( $_GET['networkwide'] ), true );
|
||||||
wp_redirect( admin_url('update.php?action=activate-plugin&success=true&plugin=' . $plugin . '&_wpnonce=' . $_GET['_wpnonce']) );
|
wp_redirect( admin_url('update.php?action=activate-plugin&success=true&plugin=' . $plugin . '&_wpnonce=' . $_GET['_wpnonce']) );
|
||||||
die();
|
die();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue