WordPress.org

Make WordPress Core

Ticket #12754: register_uninstall_hook.diff

File register_uninstall_hook.diff, 1.7 KB (added by scribu, 8 years ago)
  • wp-includes/plugin.php

     
    661661 * @param callback $callback The callback to run when the hook is called.
    662662 */
    663663function register_uninstall_hook($file, $callback) {
    664         // The option should not be autoloaded, because it is not needed in most
    665         // cases. Emphasis should be put on using the 'uninstall.php' way of
    666         // uninstalling the plugin.
     664        $file = plugin_basename($file);
     665
    667666        $uninstallable_plugins = (array) get_option('uninstall_plugins');
    668         $uninstallable_plugins[plugin_basename($file)] = $callback;
     667        $uninstallable_plugins[$file] = true;
    669668        update_option('uninstall_plugins', $uninstallable_plugins);
     669
     670        add_action('uninstall_' . $file, $callback);
    670671}
    671672
    672673/**
  • wp-admin/includes/plugin.php

     
    479479                        $output = ob_get_clean();
    480480                        return new WP_Error('unexpected_output', __('The plugin generated unexpected output.'), $output);
    481481                }
    482                 do_action( 'activate_plugin', trim( $plugin) );
    483482                if ( $network_wide ) {
    484483                        $current[$plugin] = time();
    485484                        update_site_option( 'active_sitewide_plugins', $current );
     
    776775        }
    777776
    778777        if ( isset( $uninstallable_plugins[$file] ) ) {
    779                 $callable = $uninstallable_plugins[$file];
    780778                unset($uninstallable_plugins[$file]);
    781779                update_option('uninstall_plugins', $uninstallable_plugins);
    782780                unset($uninstallable_plugins);
    783781
    784782                include WP_PLUGIN_DIR . '/' . $file;
    785783
    786                 add_action( 'uninstall_' . $file, $callable );
    787784                do_action( 'uninstall_' . $file );
    788785        }
    789786}