From 304c19dbac4bd55299adc2fe6707e66b385214c7 Mon Sep 17 00:00:00 2001 From: whyisjake Date: Thu, 26 Sep 2019 22:08:57 +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. Built from https://develop.svn.wordpress.org/trunk@46333 git-svn-id: http://core.svn.wordpress.org/trunk@46132 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/plugin.php | 10 ++++++---- wp-includes/version.php | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/wp-includes/plugin.php b/wp-includes/plugin.php index 22ead3632b..4dbab7412a 100644 --- a/wp-includes/plugin.php +++ b/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 ); + } } /** diff --git a/wp-includes/version.php b/wp-includes/version.php index d495481bf5..552e24e91e 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -13,7 +13,7 @@ * * @global string $wp_version */ -$wp_version = '5.3-beta1-46332'; +$wp_version = '5.3-beta1-46333'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.