diff --git a/wp-admin/includes/plugin.php b/wp-admin/includes/plugin.php index d6d83a20ef..9fe8ec402e 100644 --- a/wp-admin/includes/plugin.php +++ b/wp-admin/includes/plugin.php @@ -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(); diff --git a/wp-admin/plugins.php b/wp-admin/plugins.php index bf03dd535f..d273275fb6 100644 --- a/wp-admin/plugins.php +++ b/wp-admin/plugins.php @@ -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 ) ) - wp_die($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 ( 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); + 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,7 +166,10 @@ if ( !empty($action) ) { check_admin_referer('deactivate-plugin_' . $plugin); deactivate_plugins($plugin); update_option('recently_activated', array($plugin => time()) + (array)get_option('recently_activated')); - wp_redirect("plugins.php?deactivate=true&plugin_status=$status&paged=$page"); + if (headers_sent()) + echo ""; + else + wp_redirect("plugins.php?deactivate=true&plugin_status=$status&paged=$page"); exit; break; case 'deactivate-selected': @@ -302,8 +314,15 @@ if ( !empty($invalid) ) echo '
' . sprintf(__('The plugin %s
has been deactivated due to an error: %s'), esc_html($plugin_file), $error->get_error_message()) . '
fatal error.') ?>
+unexpected output.'), $_GET['charsout']); + else + $errmsg = __('Plugin could not be activated because it triggered a fatal error.'); + + ?> +