From ea1d3b13cc3fe52f3818fffd6e3ea09d996f6438 Mon Sep 17 00:00:00 2001 From: Jake Spurlock Date: Thu, 26 Sep 2019 22:07:05 +0000 Subject: [PATCH] Options: `register_uninstall_hook()` causes large amounts of unnecessary option updates. Prevent extra database read/writes from the the hook. Props jeichorn, MikeHansenMe, DrewAPicture, Rahe, tha_sun, mikeschroder. Fixes #31792. git-svn-id: https://develop.svn.wordpress.org/trunk@46333 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/plugin.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/wp-includes/plugin.php b/src/wp-includes/plugin.php index 22ead3632b..4dbab7412a 100644 --- a/src/wp-includes/plugin.php +++ b/src/wp-includes/plugin.php @@ -840,10 +840,12 @@ function register_uninstall_hook( $file, $callback ) { * 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 ); + $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 ); + } } /**