Skip to content

Commit 90eefd1

Browse files
Copilotswissspidy
andcommitted
Add support for displaying unexpected plugin output during activation
Co-authored-by: swissspidy <[email protected]>
1 parent 5463bd2 commit 90eefd1

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

features/plugin-activate.feature

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,3 +154,26 @@ Feature: Activate WordPress plugins
154154
Success:
155155
"""
156156
And the return code should be 0
157+
158+
Scenario: Activating a plugin that generates unexpected output shows the output in debug mode
159+
Given a wp-content/plugins/output-plugin.php file:
160+
"""
161+
<?php
162+
/**
163+
* Plugin Name: Output Plugin
164+
* Description: This plugin generates unexpected output during activation
165+
* Author: WP-CLI tests
166+
*/
167+
echo "Unexpected output from plugin activation";
168+
"""
169+
170+
When I try `wp plugin activate output-plugin --debug`
171+
Then STDERR should contain:
172+
"""
173+
Warning: Failed to activate plugin. The plugin generated unexpected output.
174+
"""
175+
And STDERR should contain:
176+
"""
177+
Debug (plugin): Unexpected output: Unexpected output from plugin activation
178+
"""
179+
And the return code should be 1

src/Plugin_Command.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,14 @@ public function activate( $args, $assoc_args = [] ) {
401401
$message = wp_strip_all_tags( $message );
402402
$message = str_replace( 'Error: ', '', $message );
403403
WP_CLI::warning( "Failed to activate plugin. {$message}" );
404+
405+
// If the error is due to unexpected output, display it for debugging
406+
if ( 'unexpected_output' === $result->get_error_code() ) {
407+
$output = $result->get_error_data();
408+
if ( ! empty( $output ) ) {
409+
WP_CLI::debug( "Unexpected output: {$output}", 'plugin' );
410+
}
411+
}
404412
++$errors;
405413
} else {
406414
$this->active_output( $plugin->name, $plugin->file, $network_wide, 'activate' );

0 commit comments

Comments
 (0)