Ticket #14915: 15671.diff

File 15671.diff, 3.4 KB (added by joelhardi, 3 years ago)

New patch that changes single upgrade mode to do "silent" reactivation (de/activation hooks not run)

  • wp-admin/includes/plugin.php

     
    463463 * @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. 
    464464 * @return WP_Error|null WP_Error on invalid file or null on success. 
    465465 */ 
    466 function activate_plugin( $plugin, $redirect = '', $network_wide = false) { 
     466function activate_plugin( $plugin, $redirect = '', $network_wide = false, $silent = false ) { 
    467467        $plugin  = plugin_basename( trim( $plugin ) ); 
    468468 
    469469        if ( is_multisite() && ( $network_wide || is_network_only_plugin($plugin) ) ) { 
     
    482482                        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 
    483483                ob_start(); 
    484484                include(WP_PLUGIN_DIR . '/' . $plugin); 
    485                 do_action( 'activate_plugin', trim( $plugin) ); 
     485                // Silent mode is used by plugin updater to safely de/reactivate  
     486                // an active plugin without rerunning activation hooks 
     487                if ( ! $silent ) 
     488                        do_action( 'activate_plugin', trim( $plugin) ); 
    486489                if ( $network_wide ) { 
    487490                        $current[$plugin] = time(); 
    488491                        update_site_option( 'active_sitewide_plugins', $current ); 
     
    491494                        sort($current); 
    492495                        update_option('active_plugins', $current); 
    493496                } 
    494                 do_action( 'activate_' . trim( $plugin ) ); 
    495                 do_action( 'activated_plugin', trim( $plugin) ); 
     497                if ( ! $silent ) { 
     498                        do_action( 'activate_' . trim( $plugin ) ); 
     499                        do_action( 'activated_plugin', trim( $plugin ) ); 
     500                } 
    496501                if ( ob_get_length() > 0 ) { 
    497502                        $output = ob_get_clean(); 
    498503                        return new WP_Error('unexpected_output', __('The plugin generated unexpected output.'), $output); 
     
    568573 * @param bool $network_wide Whether to enable the plugin for all sites in the network. 
    569574 * @return bool|WP_Error True when finished or WP_Error if there were errors during a plugin activation. 
    570575 */ 
    571 function activate_plugins($plugins, $redirect = '', $network_wide) { 
     576function activate_plugins( $plugins, $redirect = '', $network_wide, $silent = false ) { 
    572577        if ( !is_array($plugins) ) 
    573578                $plugins = array($plugins); 
    574579 
    575580        $errors = array(); 
    576         foreach ( (array) $plugins as $plugin ) { 
     581        foreach ( $plugins as $plugin ) { 
    577582                if ( !empty($redirect) ) 
    578583                        $redirect = add_query_arg('plugin', $plugin, $redirect); 
    579                 $result = activate_plugin($plugin, $redirect, $network_wide); 
     584                $result = activate_plugin($plugin, $redirect, $network_wide, $silent); 
    580585                if ( is_wp_error($result) ) 
    581586                        $errors[$plugin] = $result; 
    582587        } 
  • wp-admin/update.php

     
    6969                check_admin_referer('activate-plugin_' . $plugin); 
    7070                if ( ! isset($_GET['failure']) && ! isset($_GET['success']) ) { 
    7171                        wp_redirect( 'update.php?action=activate-plugin&failure=true&plugin=' . $plugin . '&_wpnonce=' . $_GET['_wpnonce'] ); 
    72                         activate_plugin( $plugin, '', ! empty( $_GET['networkwide'] ) ); 
     72                        activate_plugin( $plugin, '', ! empty( $_GET['networkwide'] ), true ); 
    7373                        wp_redirect( 'update.php?action=activate-plugin&success=true&plugin=' . $plugin . '&_wpnonce=' . $_GET['_wpnonce'] ); 
    7474                        die(); 
    7575                }