extension-command icon indicating copy to clipboard operation
extension-command copied to clipboard

`wp plugin activate` should show what unexpected output the plugin generated

Open Luc45 opened this issue 3 years ago • 2 comments

If a plugin generates output during activation, activate_plugin will return an WP_Error object configured like this:

$output = ob_get_clean();
return new WP_Error( 'unexpected_output', __( 'The plugin generated unexpected output.' ), $output );

As you can see, the output is passed as the third parameter, and the error has code "unexpected_output".

I have a use-case where I need the output that was generated for logging reasons.

Relevant code that should print the output:

https://github.com/wp-cli/extension-command/blob/409b3f6defa9d02f32b5f04bbf969a9906e1f6de/src/Plugin_Command.php#L347-L354

Luc45 avatar Oct 05 '22 04:10 Luc45

Hey @Luc45,

Thanks for the suggestion!

I have a use-case where I need the output that was generated for logging reasons.

I'm a little hesitant about changing the output solely for this use case.

What do you think about instead running the $result through an action, so your custom code can capture and report the output however you need?

danielbachhuber avatar Oct 06 '22 15:10 danielbachhuber