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:
|
$result = activate_plugin( $plugin->file, '', $network_wide ); |
|
|
|
if ( is_wp_error( $result ) ) { |
|
$message = $result->get_error_message(); |
|
$message = preg_replace( '/<a\s[^>]+>.*<\/a>/im', '', $message ); |
|
$message = wp_strip_all_tags( $message ); |
|
$message = str_replace( 'Error: ', '', $message ); |
|
WP_CLI::warning( "Failed to activate plugin. {$message}" ); |
If a plugin generates output during activation,
activate_pluginwill return anWP_Errorobject configured like this: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:
extension-command/src/Plugin_Command.php
Lines 347 to 354 in 409b3f6