From 6ad74f666eabcb96d704b4bd09fad2f241f0e24a Mon Sep 17 00:00:00 2001 From: Drew Jaynes Date: Wed, 18 Nov 2015 17:57:48 +0000 Subject: [PATCH] Plugins: Rename the `delete_plugin` action hook (introduced in [35094]) to `deleted_plugin` as it fires ''following'' a plugin deletion attempt. Further, introduce a new `delete_plugin` action hook, to be fired ''before'' a plugin deletion attempt. Both changes bring parity with other such transactional hooks in core that fire before and after certain actions, including on plugin activation/deactivation and install/uninstall, among others. Props johnjamesjacoby. Fixes #26904. git-svn-id: https://develop.svn.wordpress.org/trunk@35669 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/includes/plugin.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/wp-admin/includes/plugin.php b/src/wp-admin/includes/plugin.php index f2b2a9a65f..c6416ae2a6 100644 --- a/src/wp-admin/includes/plugin.php +++ b/src/wp-admin/includes/plugin.php @@ -816,7 +816,17 @@ function delete_plugins( $plugins, $deprecated = '' ) { uninstall_plugin($plugin_file); } + /** + * Fires immediately before a plugin deletion attempt. + * + * @since 4.4.0 + * + * @param string $plugin_file Plugin file name. + */ + do_action( 'delete_plugin', $plugin_file ); + $this_plugin_dir = trailingslashit( dirname( $plugins_dir . $plugin_file ) ); + // If plugin is in its own directory, recursively delete the directory. if ( strpos( $plugin_file, '/' ) && $this_plugin_dir != $plugins_dir ) { //base check on if plugin includes directory separator AND that it's not the root plugin folder $deleted = $wp_filesystem->delete( $this_plugin_dir, true ); @@ -832,7 +842,7 @@ function delete_plugins( $plugins, $deprecated = '' ) { * @param string $plugin_file Plugin file name. * @param bool $deleted Whether the plugin deletion was successful. */ - do_action( 'delete_plugin', $plugin_file, $deleted ); + do_action( 'deleted_plugin', $plugin_file, $deleted ); if ( ! $deleted ) { $errors[] = $plugin_file;