@@ -254,7 +254,11 @@ public function install( $args, $assoc_args ) {
254254 } else {
255255 // $result is WP_Error here
256256 WP_CLI ::warning ( $ result ->get_error_message () );
257- if ( 'already_installed ' !== $ result ->get_error_code () ) {
257+ if ( 'already_installed ' === $ result ->get_error_code () ) {
258+ if ( $ result ->get_error_data ( 'slug ' ) ) {
259+ $ slug = $ result ->get_error_data ( 'slug ' );
260+ }
261+ } else {
258262 ++$ errors ;
259263 }
260264 }
@@ -338,6 +342,11 @@ public function install( $args, $assoc_args ) {
338342 }
339343 }
340344
345+ // Only plugins cache really exists.
346+ if ( 'plugin ' === $ this ->item_type ) {
347+ wp_cache_delete ( 'plugins ' , 'plugins ' );
348+ }
349+
341350 // Check extension is available or not.
342351 $ extension = $ this ->fetcher ->get_many ( array ( $ slug ) );
343352
@@ -411,7 +420,10 @@ protected function install_from_php_file( $url, $assoc_args ) {
411420
412421 // Check if plugin is already installed before downloading.
413422 if ( file_exists ( $ dest_path ) && ! Utils \get_flag_value ( $ assoc_args , 'force ' ) ) {
414- return new WP_Error ( 'already_installed ' , 'Plugin already installed. ' );
423+ $ error = new WP_Error ( 'already_installed ' , 'Plugin already installed. ' );
424+ // An easy way to provide the slug of the installed plugin.
425+ $ error ->add_data ( $ dest_filename , 'slug ' );
426+ return $ error ;
415427 }
416428
417429 // Ensure plugin directory exists.
0 commit comments