register_uninstall_hook

The timeline below displays how wordpress function register_uninstall_hook has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 5.8

/**
 * Sets the uninstallation hook for a plugin.
 *
 * Registers the uninstall hook that will be called when the user clicks on the
 * uninstall link that calls for the plugin to uninstall itself. The link won't
 * be active unless the plugin hooks into the action.
 *
 * The plugin should not run arbitrary code outside of functions, when
 * registering the uninstall hook. In order to run using the hook, the plugin
 * will have to be included, which means that any code laying outside of a
 * function will be run during the uninstallation process. The plugin should not
 * hinder the uninstallation process.
 *
 * If the plugin can not be written without running code within the plugin, then
 * the plugin should create a file named 'uninstall.php' in the base plugin
 * folder. This file will be called, if it exists, during the uninstallation process
 * bypassing the uninstall hook. The plugin, when using the 'uninstall.php'
 * should always check for the 'WP_UNINSTALL_PLUGIN' constant, before
 * executing.
 *
 * @since 2.7.0
 *
 * @param string   $file     Plugin file.
 * @param callable $callback The callback to run when the hook is called. Must be
 *                           a static method or function.
 */
function register_uninstall_hook($file, $callback)
{
    if (is_array($callback) && is_object($callback[0])) {
        _doing_it_wrong(__FUNCTION__, __('Only a static class method or function can be used in an uninstall hook.'), '3.1.0');
        return;
    }
    /*
     * The option should not be autoloaded, because it is not needed in most
     * cases. Emphasis should be put on using the 'uninstall.php' way of
     * uninstalling the plugin.
     */
    $uninstallable_plugins = (array) get_option('uninstall_plugins');
    $plugin_basename = plugin_basename($file);
    if (!isset($uninstallable_plugins[$plugin_basename]) || $uninstallable_plugins[$plugin_basename] !== $callback) {
        $uninstallable_plugins[$plugin_basename] = $callback;
        update_option('uninstall_plugins', $uninstallable_plugins);
    }
}

WordPress Version: 5.3

/**
 * Set the uninstallation hook for a plugin.
 *
 * Registers the uninstall hook that will be called when the user clicks on the
 * uninstall link that calls for the plugin to uninstall itself. The link won't
 * be active unless the plugin hooks into the action.
 *
 * The plugin should not run arbitrary code outside of functions, when
 * registering the uninstall hook. In order to run using the hook, the plugin
 * will have to be included, which means that any code laying outside of a
 * function will be run during the uninstallation process. The plugin should not
 * hinder the uninstallation process.
 *
 * If the plugin can not be written without running code within the plugin, then
 * the plugin should create a file named 'uninstall.php' in the base plugin
 * folder. This file will be called, if it exists, during the uninstallation process
 * bypassing the uninstall hook. The plugin, when using the 'uninstall.php'
 * should always check for the 'WP_UNINSTALL_PLUGIN' constant, before
 * executing.
 *
 * @since 2.7.0
 *
 * @param string   $file     Plugin file.
 * @param callable $callback The callback to run when the hook is called. Must be
 *                           a static method or function.
 */
function register_uninstall_hook($file, $callback)
{
    if (is_array($callback) && is_object($callback[0])) {
        _doing_it_wrong(__FUNCTION__, __('Only a static class method or function can be used in an uninstall hook.'), '3.1.0');
        return;
    }
    /*
     * The option should not be autoloaded, because it is not needed in most
     * cases. Emphasis should be put on using the 'uninstall.php' way of
     * uninstalling the plugin.
     */
    $uninstallable_plugins = (array) get_option('uninstall_plugins');
    $plugin_basename = plugin_basename($file);
    if (!isset($uninstallable_plugins[$plugin_basename]) || $uninstallable_plugins[$plugin_basename] !== $callback) {
        $uninstallable_plugins[$plugin_basename] = $callback;
        update_option('uninstall_plugins', $uninstallable_plugins);
    }
}

WordPress Version: 4.9

/**
 * Set the uninstallation hook for a plugin.
 *
 * Registers the uninstall hook that will be called when the user clicks on the
 * uninstall link that calls for the plugin to uninstall itself. The link won't
 * be active unless the plugin hooks into the action.
 *
 * The plugin should not run arbitrary code outside of functions, when
 * registering the uninstall hook. In order to run using the hook, the plugin
 * will have to be included, which means that any code laying outside of a
 * function will be run during the uninstallation process. The plugin should not
 * hinder the uninstallation process.
 *
 * If the plugin can not be written without running code within the plugin, then
 * the plugin should create a file named 'uninstall.php' in the base plugin
 * folder. This file will be called, if it exists, during the uninstallation process
 * bypassing the uninstall hook. The plugin, when using the 'uninstall.php'
 * should always check for the 'WP_UNINSTALL_PLUGIN' constant, before
 * executing.
 *
 * @since 2.7.0
 *
 * @param string   $file     Plugin file.
 * @param callable $callback The callback to run when the hook is called. Must be
 *                           a static method or function.
 */
function register_uninstall_hook($file, $callback)
{
    if (is_array($callback) && is_object($callback[0])) {
        _doing_it_wrong(__FUNCTION__, __('Only a static class method or function can be used in an uninstall hook.'), '3.1.0');
        return;
    }
    /*
     * The option should not be autoloaded, because it is not needed in most
     * cases. Emphasis should be put on using the 'uninstall.php' way of
     * uninstalling the plugin.
     */
    $uninstallable_plugins = (array) get_option('uninstall_plugins');
    $uninstallable_plugins[plugin_basename($file)] = $callback;
    update_option('uninstall_plugins', $uninstallable_plugins);
}

WordPress Version: 4.6

/**
 * Set the uninstallation hook for a plugin.
 *
 * Registers the uninstall hook that will be called when the user clicks on the
 * uninstall link that calls for the plugin to uninstall itself. The link won't
 * be active unless the plugin hooks into the action.
 *
 * The plugin should not run arbitrary code outside of functions, when
 * registering the uninstall hook. In order to run using the hook, the plugin
 * will have to be included, which means that any code laying outside of a
 * function will be run during the uninstall process. The plugin should not
 * hinder the uninstall process.
 *
 * If the plugin can not be written without running code within the plugin, then
 * the plugin should create a file named 'uninstall.php' in the base plugin
 * folder. This file will be called, if it exists, during the uninstall process
 * bypassing the uninstall hook. The plugin, when using the 'uninstall.php'
 * should always check for the 'WP_UNINSTALL_PLUGIN' constant, before
 * executing.
 *
 * @since 2.7.0
 *
 * @param string   $file     Plugin file.
 * @param callable $callback The callback to run when the hook is called. Must be
 *                           a static method or function.
 */
function register_uninstall_hook($file, $callback)
{
    if (is_array($callback) && is_object($callback[0])) {
        _doing_it_wrong(__FUNCTION__, __('Only a static class method or function can be used in an uninstall hook.'), '3.1.0');
        return;
    }
    /*
     * The option should not be autoloaded, because it is not needed in most
     * cases. Emphasis should be put on using the 'uninstall.php' way of
     * uninstalling the plugin.
     */
    $uninstallable_plugins = (array) get_option('uninstall_plugins');
    $uninstallable_plugins[plugin_basename($file)] = $callback;
    update_option('uninstall_plugins', $uninstallable_plugins);
}

WordPress Version: 4.4

/**
 * Set the uninstallation hook for a plugin.
 *
 * Registers the uninstall hook that will be called when the user clicks on the
 * uninstall link that calls for the plugin to uninstall itself. The link won't
 * be active unless the plugin hooks into the action.
 *
 * The plugin should not run arbitrary code outside of functions, when
 * registering the uninstall hook. In order to run using the hook, the plugin
 * will have to be included, which means that any code laying outside of a
 * function will be run during the uninstall process. The plugin should not
 * hinder the uninstall process.
 *
 * If the plugin can not be written without running code within the plugin, then
 * the plugin should create a file named 'uninstall.php' in the base plugin
 * folder. This file will be called, if it exists, during the uninstall process
 * bypassing the uninstall hook. The plugin, when using the 'uninstall.php'
 * should always check for the 'WP_UNINSTALL_PLUGIN' constant, before
 * executing.
 *
 * @since 2.7.0
 *
 * @param string   $file     Plugin file.
 * @param callable $callback The callback to run when the hook is called. Must be
 *                           a static method or function.
 */
function register_uninstall_hook($file, $callback)
{
    if (is_array($callback) && is_object($callback[0])) {
        _doing_it_wrong(__FUNCTION__, __('Only a static class method or function can be used in an uninstall hook.'), '3.1');
        return;
    }
    /*
     * The option should not be autoloaded, because it is not needed in most
     * cases. Emphasis should be put on using the 'uninstall.php' way of
     * uninstalling the plugin.
     */
    $uninstallable_plugins = (array) get_option('uninstall_plugins');
    $uninstallable_plugins[plugin_basename($file)] = $callback;
    update_option('uninstall_plugins', $uninstallable_plugins);
}

WordPress Version: 4.0

/**
 * Set the uninstallation hook for a plugin.
 *
 * Registers the uninstall hook that will be called when the user clicks on the
 * uninstall link that calls for the plugin to uninstall itself. The link won't
 * be active unless the plugin hooks into the action.
 *
 * The plugin should not run arbitrary code outside of functions, when
 * registering the uninstall hook. In order to run using the hook, the plugin
 * will have to be included, which means that any code laying outside of a
 * function will be run during the uninstall process. The plugin should not
 * hinder the uninstall process.
 *
 * If the plugin can not be written without running code within the plugin, then
 * the plugin should create a file named 'uninstall.php' in the base plugin
 * folder. This file will be called, if it exists, during the uninstall process
 * bypassing the uninstall hook. The plugin, when using the 'uninstall.php'
 * should always check for the 'WP_UNINSTALL_PLUGIN' constant, before
 * executing.
 *
 * @since 2.7.0
 *
 * @param string   $file     Plugin file.
 * @param callback $callback The callback to run when the hook is called. Must be
 *                           a static method or function.
 */
function register_uninstall_hook($file, $callback)
{
    if (is_array($callback) && is_object($callback[0])) {
        _doing_it_wrong(__FUNCTION__, __('Only a static class method or function can be used in an uninstall hook.'), '3.1');
        return;
    }
    /*
     * The option should not be autoloaded, because it is not needed in most
     * cases. Emphasis should be put on using the 'uninstall.php' way of
     * uninstalling the plugin.
     */
    $uninstallable_plugins = (array) get_option('uninstall_plugins');
    $uninstallable_plugins[plugin_basename($file)] = $callback;
    update_option('uninstall_plugins', $uninstallable_plugins);
}

WordPress Version: 3.9

/**
 * Set the uninstallation hook for a plugin.
 *
 * Registers the uninstall hook that will be called when the user clicks on the
 * uninstall link that calls for the plugin to uninstall itself. The link won't
 * be active unless the plugin hooks into the action.
 *
 * The plugin should not run arbitrary code outside of functions, when
 * registering the uninstall hook. In order to run using the hook, the plugin
 * will have to be included, which means that any code laying outside of a
 * function will be run during the uninstall process. The plugin should not
 * hinder the uninstall process.
 *
 * If the plugin can not be written without running code within the plugin, then
 * the plugin should create a file named 'uninstall.php' in the base plugin
 * folder. This file will be called, if it exists, during the uninstall process
 * bypassing the uninstall hook. The plugin, when using the 'uninstall.php'
 * should always check for the 'WP_UNINSTALL_PLUGIN' constant, before
 * executing.
 *
 * @since 2.7.0
 *
 * @param string $file
 * @param callback $callback The callback to run when the hook is called. Must be a static method or function.
 */
function register_uninstall_hook($file, $callback)
{
    if (is_array($callback) && is_object($callback[0])) {
        _doing_it_wrong(__FUNCTION__, __('Only a static class method or function can be used in an uninstall hook.'), '3.1');
        return;
    }
    // The option should not be autoloaded, because it is not needed in most
    // cases. Emphasis should be put on using the 'uninstall.php' way of
    // uninstalling the plugin.
    $uninstallable_plugins = (array) get_option('uninstall_plugins');
    $uninstallable_plugins[plugin_basename($file)] = $callback;
    update_option('uninstall_plugins', $uninstallable_plugins);
}

WordPress Version: 3.7

/**
 * Set the uninstallation hook for a plugin.
 *
 * Registers the uninstall hook that will be called when the user clicks on the
 * uninstall link that calls for the plugin to uninstall itself. The link won't
 * be active unless the plugin hooks into the action.
 *
 * The plugin should not run arbitrary code outside of functions, when
 * registering the uninstall hook. In order to run using the hook, the plugin
 * will have to be included, which means that any code laying outside of a
 * function will be run during the uninstall process. The plugin should not
 * hinder the uninstall process.
 *
 * If the plugin can not be written without running code within the plugin, then
 * the plugin should create a file named 'uninstall.php' in the base plugin
 * folder. This file will be called, if it exists, during the uninstall process
 * bypassing the uninstall hook. The plugin, when using the 'uninstall.php'
 * should always check for the 'WP_UNINSTALL_PLUGIN' constant, before
 * executing.
 *
 * @since 2.7
 *
 * @param string $file
 * @param callback $callback The callback to run when the hook is called. Must be a static method or function.
 */
function register_uninstall_hook($file, $callback)
{
    if (is_array($callback) && is_object($callback[0])) {
        _doing_it_wrong(__FUNCTION__, __('Only a static class method or function can be used in an uninstall hook.'), '3.1');
        return;
    }
    // The option should not be autoloaded, because it is not needed in most
    // cases. Emphasis should be put on using the 'uninstall.php' way of
    // uninstalling the plugin.
    $uninstallable_plugins = (array) get_option('uninstall_plugins');
    $uninstallable_plugins[plugin_basename($file)] = $callback;
    update_option('uninstall_plugins', $uninstallable_plugins);
}