WordPress.org

Make WordPress Core

Ticket #13786: uninstall_hook_solution_1.diff

File uninstall_hook_solution_1.diff, 2.5 KB (added by x3r0ss, 8 years ago)

Possible Solution 1

  • wp-includes/plugin.php

     
    659659 * @param callback $callback The callback to run when the hook is called.
    660660 */
    661661function register_uninstall_hook($file, $callback) {
    662         // The option should not be autoloaded, because it is not needed in most
    663         // cases. Emphasis should be put on using the 'uninstall.php' way of
    664         // uninstalling the plugin.
    665         $uninstallable_plugins = (array) get_option('uninstall_plugins');
    666         $uninstallable_plugins[plugin_basename($file)] = $callback;
    667         update_option('uninstall_plugins', $uninstallable_plugins);
     662        $file = plugin_basename($file);
     663        add_action('uninstall_' . $file, $callback);
    668664}
    669665
    670666/**
  • wp-admin/includes/plugin.php

     
    749749function is_uninstallable_plugin($plugin) {
    750750        $file = plugin_basename($plugin);
    751751
    752         $uninstallable_plugins = (array) get_option('uninstall_plugins');
    753         if ( isset( $uninstallable_plugins[$file] ) || file_exists( WP_PLUGIN_DIR . '/' . dirname($file) . '/uninstall.php' ) )
     752        if ( file_exists( WP_PLUGIN_DIR . '/' . dirname($file) . '/uninstall.php' ) )
    754753                return true;
    755754
    756         return false;
     755        require_once(WP_PLUGIN_DIR . '/' . $file);
     756        return has_action('uninstall_' . $file);
    757757}
    758758
    759759/**
     
    768768function uninstall_plugin($plugin) {
    769769        $file = plugin_basename($plugin);
    770770
    771         $uninstallable_plugins = (array) get_option('uninstall_plugins');
    772771        if ( file_exists( WP_PLUGIN_DIR . '/' . dirname($file) . '/uninstall.php' ) ) {
    773                 if ( isset( $uninstallable_plugins[$file] ) ) {
    774                         unset($uninstallable_plugins[$file]);
    775                         update_option('uninstall_plugins', $uninstallable_plugins);
    776                 }
    777                 unset($uninstallable_plugins);
    778772
    779773                define('WP_UNINSTALL_PLUGIN', $file);
    780774                include WP_PLUGIN_DIR . '/' . dirname($file) . '/uninstall.php';
     
    782776                return true;
    783777        }
    784778
    785         if ( isset( $uninstallable_plugins[$file] ) ) {
    786                 $callable = $uninstallable_plugins[$file];
    787                 unset($uninstallable_plugins[$file]);
    788                 update_option('uninstall_plugins', $uninstallable_plugins);
    789                 unset($uninstallable_plugins);
    790 
    791                 include WP_PLUGIN_DIR . '/' . $file;
    792 
    793                 add_action( 'uninstall_' . $file, $callable );
    794                 do_action( 'uninstall_' . $file );
    795         }
     779        if( has_action('uninstall_' . $file) )
     780        {
     781                do_action( 'uninstall_' . $file );
     782                return true;
     783        }
    796784}
    797785
    798786//