@@ -1098,9 +1098,12 @@ public function uninstall( $args, $assoc_args = array() ) {
10981098 return ;
10991099 }
11001100
1101- $ successes = 0 ;
1102- $ errors = 0 ;
1103- $ plugins = $ this ->fetcher ->get_many ( $ args );
1101+ $ successes = 0 ;
1102+ $ errors = 0 ;
1103+ $ delete_errors = array ();
1104+ $ deleted_plugin_files = array ();
1105+
1106+ $ plugins = $ this ->fetcher ->get_many ( $ args );
11041107 if ( count ( $ plugins ) < count ( $ args ) ) {
11051108 $ errors = count ( $ args ) - count ( $ plugins );
11061109 }
@@ -1140,6 +1143,7 @@ public function uninstall( $args, $assoc_args = array() ) {
11401143 foreach ( $ translations as $ translation => $ data ) {
11411144 $ wp_filesystem ->delete ( WP_LANG_DIR . '/plugins/ ' . $ plugin_slug . '- ' . $ translation . '.po ' );
11421145 $ wp_filesystem ->delete ( WP_LANG_DIR . '/plugins/ ' . $ plugin_slug . '- ' . $ translation . '.mo ' );
1146+ $ wp_filesystem ->delete ( WP_LANG_DIR . '/plugins/ ' . $ plugin_slug . '- ' . $ translation . '.l10n.php ' );
11431147
11441148 $ json_translation_files = glob ( WP_LANG_DIR . '/plugins/ ' . $ plugin_slug . '- ' . $ translation . '-*.json ' );
11451149 if ( $ json_translation_files ) {
@@ -1148,13 +1152,35 @@ public function uninstall( $args, $assoc_args = array() ) {
11481152 }
11491153 }
11501154
1151- if ( ! Utils \get_flag_value ( $ assoc_args , 'skip-delete ' ) && $ this ->delete_plugin ( $ plugin ) ) {
1152- WP_CLI ::log ( "Uninstalled and deleted ' $ plugin ->name ' plugin. " );
1155+ if ( ! Utils \get_flag_value ( $ assoc_args , 'skip-delete ' ) ) {
1156+ if ( $ this ->delete_plugin ( $ plugin ) ) {
1157+ $ deleted_plugin_files [] = $ plugin ->file ;
1158+ WP_CLI ::log ( "Uninstalled and deleted ' $ plugin ->name ' plugin. " );
1159+ } else {
1160+ $ delete_errors [] = $ plugin ->file ;
1161+ WP_CLI ::log ( "Ran uninstall procedure for ' $ plugin ->name ' plugin. Deletion failed " );
1162+ ++$ errors ;
1163+ continue ;
1164+ }
11531165 } else {
11541166 WP_CLI ::log ( "Ran uninstall procedure for ' $ plugin ->name ' plugin without deleting. " );
11551167 }
11561168 ++$ successes ;
11571169 }
1170+
1171+ // Remove deleted plugins from the plugin updates list.
1172+ $ current = get_site_transient ( 'update_plugins ' );
1173+ if ( $ current ) {
1174+ // Don't remove the plugins that weren't deleted.
1175+ $ deleted = array_diff ( $ deleted_plugin_files , $ delete_errors );
1176+
1177+ foreach ( $ deleted as $ plugin_file ) {
1178+ unset( $ current ->response [ $ plugin_file ] );
1179+ }
1180+
1181+ set_site_transient ( 'update_plugins ' , $ current );
1182+ }
1183+
11581184 if ( ! $ this ->chained_command ) {
11591185 Utils \report_batch_operation_results ( 'plugin ' , 'uninstall ' , count ( $ args ), $ successes , $ errors );
11601186 }
@@ -1474,7 +1500,16 @@ private function get_details( $file ) {
14741500 return $ plugin_folder [ $ plugin_file ];
14751501 }
14761502
1503+ /**
1504+ * Performs deletion of plugin files
1505+ *
1506+ * @param $plugin - Plugin fetcher object (name, file)
1507+ * @return bool - If plugin was deleted
1508+ */
14771509 private function delete_plugin ( $ plugin ) {
1510+ // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound
1511+ do_action ( 'delete_plugin ' , $ plugin ->file );
1512+
14781513 $ plugin_dir = dirname ( $ plugin ->file );
14791514 if ( '. ' === $ plugin_dir ) {
14801515 $ plugin_dir = $ plugin ->file ;
@@ -1495,6 +1530,11 @@ private function delete_plugin( $plugin ) {
14951530 $ command = 'rm -rf ' ;
14961531 }
14971532
1498- return ! WP_CLI ::launch ( $ command . escapeshellarg ( $ path ), false );
1533+ $ result = ! WP_CLI ::launch ( $ command . escapeshellarg ( $ path ), false );
1534+
1535+ // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound
1536+ do_action ( 'deleted_plugin ' , $ plugin ->file , $ result );
1537+
1538+ return $ result ;
14991539 }
15001540}
0 commit comments