Detect plugin output on activation, as well as fatal errors. props miqrogroove. fixes #12089
git-svn-id: https://develop.svn.wordpress.org/trunk@13167 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
37e62c69f5
commit
49d4b41207
|
@ -358,7 +358,11 @@ function activate_plugin( $plugin, $redirect = '', $network_wide = false) {
|
|||
if ( !empty($redirect) )
|
||||
wp_redirect(add_query_arg('_error_nonce', wp_create_nonce('plugin-activation-error_' . $plugin), $redirect)); // we'll override this later if the plugin can be included without fatal error
|
||||
ob_start();
|
||||
@include(WP_PLUGIN_DIR . '/' . $plugin);
|
||||
include(WP_PLUGIN_DIR . '/' . $plugin);
|
||||
if ( ob_get_length() > 0 ) {
|
||||
$output = ob_get_clean();
|
||||
return new WP_Error('unexpected_output', __('The plugin generated unexpected output.'), $output);
|
||||
}
|
||||
do_action( 'activate_plugin', trim( $plugin) );
|
||||
if ( $network_wide ) {
|
||||
$current[$plugin] = time();
|
||||
|
|
|
@ -50,8 +50,15 @@ if ( !empty($action) ) {
|
|||
check_admin_referer('activate-plugin_' . $plugin);
|
||||
|
||||
$result = activate_plugin($plugin, 'plugins.php?error=true&plugin=' . $plugin, $network_wide);
|
||||
if ( is_wp_error( $result ) )
|
||||
if ( is_wp_error( $result ) ) {
|
||||
if ('unexpected_output' == $result->get_error_code()) {
|
||||
$redirect = 'plugins.php?error=true&charsout=' . strlen($result->get_error_data()) . '&plugin=' . $plugin;
|
||||
wp_redirect(add_query_arg('_error_nonce', wp_create_nonce('plugin-activation-error_' . $plugin), $redirect));
|
||||
exit;
|
||||
} else {
|
||||
wp_die($result);
|
||||
}
|
||||
}
|
||||
|
||||
$recent = (array)get_option('recently_activated');
|
||||
if ( isset($recent[ $plugin ]) ) {
|
||||
|
@ -140,10 +147,12 @@ if ( !empty($action) ) {
|
|||
if ( is_wp_error($valid) )
|
||||
wp_die($valid);
|
||||
|
||||
if ( ! WP_DEBUG ) {
|
||||
if ( defined('E_RECOVERABLE_ERROR') )
|
||||
error_reporting(E_ERROR | E_WARNING | E_PARSE | E_USER_ERROR | E_USER_WARNING | E_RECOVERABLE_ERROR);
|
||||
else
|
||||
error_reporting(E_ERROR | E_WARNING | E_PARSE | E_USER_ERROR | E_USER_WARNING);
|
||||
}
|
||||
|
||||
@ini_set('display_errors', true); //Ensure that Fatal errors are displayed.
|
||||
include(WP_PLUGIN_DIR . '/' . $plugin);
|
||||
|
@ -157,6 +166,9 @@ if ( !empty($action) ) {
|
|||
check_admin_referer('deactivate-plugin_' . $plugin);
|
||||
deactivate_plugins($plugin);
|
||||
update_option('recently_activated', array($plugin => time()) + (array)get_option('recently_activated'));
|
||||
if (headers_sent())
|
||||
echo "<meta http-equiv='refresh' content='" . esc_attr( "0;url=plugins.php?deactivate=true&plugin_status=$status&paged=$page" ) . "' />";
|
||||
else
|
||||
wp_redirect("plugins.php?deactivate=true&plugin_status=$status&paged=$page");
|
||||
exit;
|
||||
break;
|
||||
|
@ -302,8 +314,15 @@ if ( !empty($invalid) )
|
|||
echo '<div id="message" class="error"><p>' . sprintf(__('The plugin <code>%s</code> has been <strong>deactivated</strong> due to an error: %s'), esc_html($plugin_file), $error->get_error_message()) . '</p></div>';
|
||||
?>
|
||||
|
||||
<?php if ( isset($_GET['error']) ) : ?>
|
||||
<div id="message" class="updated"><p><?php _e('Plugin could not be activated because it triggered a <strong>fatal error</strong>.') ?></p>
|
||||
<?php if ( isset($_GET['error']) ) :
|
||||
|
||||
if (isset($_GET['charsout']))
|
||||
$errmsg = sprintf(__('Plugin could not be activated because it generated %d characters of <strong>unexpected output</strong>.'), $_GET['charsout']);
|
||||
else
|
||||
$errmsg = __('Plugin could not be activated because it triggered a <strong>fatal error</strong>.');
|
||||
|
||||
?>
|
||||
<div id="message" class="updated"><p><?php echo $errmsg; ?></p>
|
||||
<?php
|
||||
if ( wp_verify_nonce($_GET['_error_nonce'], 'plugin-activation-error_' . $plugin) ) { ?>
|
||||
<iframe style="border:0" width="100%" height="70px" src="<?php echo admin_url('plugins.php?action=error_scrape&plugin=' . esc_attr($plugin) . '&_wpnonce=' . esc_attr($_GET['_error_nonce'])); ?>"></iframe>
|
||||
|
|
Loading…
Reference in New Issue