WordPress.org

Make WordPress Core

Changeset 13167


Ignore:
Timestamp:
02/16/2010 03:44:20 AM (8 years ago)
Author:
markjaquith
Message:

Detect plugin output on activation, as well as fatal errors. props miqrogroove. fixes #12089

Location:
trunk/wp-admin
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/plugin.php

    r13155 r13167  
    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 ) {
  • trunk/wp-admin/plugins.php

    r13155 r13167  
    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');
     
    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.
     
    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='" . esc_attr( "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;
     
    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 characters 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) ) { ?>
Note: See TracChangeset for help on using the changeset viewer.