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
This commit is contained in:
Jake Spurlock 2019-09-26 22:07:05 +00:00
parent f2e9aa79f5
commit ea1d3b13cc
1 changed files with 6 additions and 4 deletions

View File

@ -840,10 +840,12 @@ function register_uninstall_hook( $file, $callback ) {
* cases. Emphasis should be put on using the 'uninstall.php' way of * cases. Emphasis should be put on using the 'uninstall.php' way of
* uninstalling the plugin. * uninstalling the plugin.
*/ */
$uninstallable_plugins = (array) get_option( 'uninstall_plugins' ); $uninstallable_plugins = (array) get_option( 'uninstall_plugins' );
$uninstallable_plugins[ plugin_basename( $file ) ] = $callback; $plugin_basename = plugin_basename( $file );
if ( ! isset( $uninstallable_plugins[ $plugin_basename ] ) || $uninstallable_plugins[ $plugin_basename ] !== $callback ) {
update_option( 'uninstall_plugins', $uninstallable_plugins ); $uninstallable_plugins[ $plugin_basename ] = $callback;
update_option( 'uninstall_plugins', $uninstallable_plugins );
}
} }
/** /**