@@ -1098,9 +1098,12 @@ public function uninstall( $args, $assoc_args = array() ) {
1098
1098
return ;
1099
1099
}
1100
1100
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 );
1104
1107
if ( count ( $ plugins ) < count ( $ args ) ) {
1105
1108
$ errors = count ( $ args ) - count ( $ plugins );
1106
1109
}
@@ -1140,6 +1143,7 @@ public function uninstall( $args, $assoc_args = array() ) {
1140
1143
foreach ( $ translations as $ translation => $ data ) {
1141
1144
$ wp_filesystem ->delete ( WP_LANG_DIR . '/plugins/ ' . $ plugin_slug . '- ' . $ translation . '.po ' );
1142
1145
$ wp_filesystem ->delete ( WP_LANG_DIR . '/plugins/ ' . $ plugin_slug . '- ' . $ translation . '.mo ' );
1146
+ $ wp_filesystem ->delete ( WP_LANG_DIR . '/plugins/ ' . $ plugin_slug . '- ' . $ translation . '.l10n.php ' );
1143
1147
1144
1148
$ json_translation_files = glob ( WP_LANG_DIR . '/plugins/ ' . $ plugin_slug . '- ' . $ translation . '-*.json ' );
1145
1149
if ( $ json_translation_files ) {
@@ -1148,13 +1152,35 @@ public function uninstall( $args, $assoc_args = array() ) {
1148
1152
}
1149
1153
}
1150
1154
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
+ }
1153
1165
} else {
1154
1166
WP_CLI ::log ( "Ran uninstall procedure for ' $ plugin ->name ' plugin without deleting. " );
1155
1167
}
1156
1168
++$ successes ;
1157
1169
}
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
+
1158
1184
if ( ! $ this ->chained_command ) {
1159
1185
Utils \report_batch_operation_results ( 'plugin ' , 'uninstall ' , count ( $ args ), $ successes , $ errors );
1160
1186
}
@@ -1474,7 +1500,15 @@ private function get_details( $file ) {
1474
1500
return $ plugin_folder [ $ plugin_file ];
1475
1501
}
1476
1502
1503
+ /**
1504
+ * Performs deletion of plugin files
1505
+ *
1506
+ * @param $plugin - Plugin fetcher object (name, file)
1507
+ * @return bool - If plugin was deleted
1508
+ */
1477
1509
private function delete_plugin ( $ plugin ) {
1510
+ do_action ( 'delete_plugin ' , $ plugin ->file );
1511
+
1478
1512
$ plugin_dir = dirname ( $ plugin ->file );
1479
1513
if ( '. ' === $ plugin_dir ) {
1480
1514
$ plugin_dir = $ plugin ->file ;
@@ -1495,6 +1529,10 @@ private function delete_plugin( $plugin ) {
1495
1529
$ command = 'rm -rf ' ;
1496
1530
}
1497
1531
1498
- return ! WP_CLI ::launch ( $ command . escapeshellarg ( $ path ), false );
1532
+ $ result = ! WP_CLI ::launch ( $ command . escapeshellarg ( $ path ), false );
1533
+
1534
+ do_action ( 'deleted_plugin ' , $ plugin ->file , $ result );
1535
+
1536
+ return $ result ;
1499
1537
}
1500
1538
}
0 commit comments