Make WordPress Core

Ticket #12089: 12089.2.diff

File 12089.2.diff, 4.0 KB (added by miqrogroove, 14 years ago)

Don't override WP_DEBUG, props sivel. Also discard the error control operator.

  • includes/plugin.php

     
    358358                if ( !empty($redirect) )
    359359                        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
    360360                ob_start();
    361                 @include(WP_PLUGIN_DIR . '/' . $plugin);
     361                include(WP_PLUGIN_DIR . '/' . $plugin);
     362                if ( ob_get_length() > 0 ) {
     363                        $output = ob_get_clean();
     364                        return new WP_Error('unexpected_output', __('The plugin generated unexpected output.'), $output);
     365                }
    362366                do_action( 'activate_plugin', trim( $plugin) );
    363367                if ( $network_wide ) {
    364368                        $current[$plugin] = time();
  • plugins.php

     
    5050                        check_admin_referer('activate-plugin_' . $plugin);
    5151
    5252                        $result = activate_plugin($plugin, 'plugins.php?error=true&plugin=' . $plugin, $network_wide);
    53                         if ( is_wp_error( $result ) )
    54                                 wp_die($result);
     53                        if ( is_wp_error( $result ) ) {
     54                                if ('unexpected_output' == $result->get_error_code()) {
     55                                        $redirect = 'plugins.php?error=true&charsout=' . strlen($result->get_error_data()) . '&plugin=' . $plugin;
     56                                        wp_redirect(add_query_arg('_error_nonce', wp_create_nonce('plugin-activation-error_' . $plugin), $redirect));
     57                                        exit;
     58                                } else {
     59                                        wp_die($result);
     60                                }
     61                        }
    5562
    5663                        $recent = (array)get_option('recently_activated');
    5764                        if ( isset($recent[ $plugin ]) ) {
     
    140147                        if ( is_wp_error($valid) )
    141148                                wp_die($valid);
    142149
    143                         if ( defined('E_RECOVERABLE_ERROR') )
    144                                 error_reporting(E_ERROR | E_WARNING | E_PARSE | E_USER_ERROR | E_USER_WARNING | E_RECOVERABLE_ERROR);
    145                         else
    146                                 error_reporting(E_ERROR | E_WARNING | E_PARSE | E_USER_ERROR | E_USER_WARNING);
     150                        if ( ! WP_DEBUG ) {
     151                                if ( defined('E_RECOVERABLE_ERROR') )
     152                                        error_reporting(E_ERROR | E_WARNING | E_PARSE | E_USER_ERROR | E_USER_WARNING | E_RECOVERABLE_ERROR);
     153                                else
     154                                        error_reporting(E_ERROR | E_WARNING | E_PARSE | E_USER_ERROR | E_USER_WARNING);
     155                        }
    147156
    148157                        @ini_set('display_errors', true); //Ensure that Fatal errors are displayed.
    149158                        include(WP_PLUGIN_DIR . '/' . $plugin);
     
    157166                        check_admin_referer('deactivate-plugin_' . $plugin);
    158167                        deactivate_plugins($plugin);
    159168                        update_option('recently_activated', array($plugin => time()) + (array)get_option('recently_activated'));
    160                         wp_redirect("plugins.php?deactivate=true&plugin_status=$status&paged=$page");
     169                        if (headers_sent())
     170                                echo "<meta http-equiv='refresh' content='0;url=plugins.php?deactivate=true&plugin_status=$status&paged=$page' />";
     171                        else
     172                                wp_redirect("plugins.php?deactivate=true&plugin_status=$status&paged=$page");
    161173                        exit;
    162174                        break;
    163175                case 'deactivate-selected':
     
    302314                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>';
    303315?>
    304316
    305 <?php if ( isset($_GET['error']) ) : ?>
    306         <div id="message" class="updated"><p><?php _e('Plugin could not be activated because it triggered a <strong>fatal error</strong>.') ?></p>
     317<?php if ( isset($_GET['error']) ) :
     318
     319        if (isset($_GET['charsout']))
     320                $errmsg = sprintf(__('Plugin could not be activated because it generated %d bytes of <strong>unexpected output</strong>.'), $_GET['charsout']);
     321        else
     322                $errmsg = __('Plugin could not be activated because it triggered a <strong>fatal error</strong>.');
     323
     324        ?>
     325        <div id="message" class="updated"><p><?php echo $errmsg; ?></p>
    307326        <?php
    308327                if ( wp_verify_nonce($_GET['_error_nonce'], 'plugin-activation-error_' . $plugin) ) { ?>
    309328        <iframe style="border:0" width="100%" height="70px" src="<?php echo admin_url('plugins.php?action=error_scrape&amp;plugin=' . esc_attr($plugin) . '&amp;_wpnonce=' . esc_attr($_GET['_error_nonce'])); ?>"></iframe>