Ticket #12089: 12089.diff

File 12089.diff, 3.3 KB (added by miqrogroove, 3 years ago)

Full solution with new "sandbox" error for unexpected output.

Line 
1Index: includes/plugin.php
2===================================================================
3--- includes/plugin.php (revision 13165)
4+++ includes/plugin.php (working copy)
5@@ -359,6 +359,10 @@
6                        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
7                ob_start();
8                @include(WP_PLUGIN_DIR . '/' . $plugin);
9+               if ( ob_get_length() > 0 ) {
10+                       $output = ob_get_clean();
11+                       return new WP_Error('unexpected_output', __('The plugin generated unexpected output.'), $output);
12+               }
13                do_action( 'activate_plugin', trim( $plugin) );
14                if ( $network_wide ) {
15                        $current[$plugin] = time();
16Index: plugins.php
17===================================================================
18--- plugins.php (revision 13165)
19+++ plugins.php (working copy)
20@@ -50,8 +50,15 @@
21                        check_admin_referer('activate-plugin_' . $plugin);
22 
23                        $result = activate_plugin($plugin, 'plugins.php?error=true&plugin=' . $plugin, $network_wide);
24-                       if ( is_wp_error( $result ) )
25-                               wp_die($result);
26+                       if ( is_wp_error( $result ) ) {
27+                               if ('unexpected_output' == $result->get_error_code()) {
28+                                       $redirect = 'plugins.php?error=true&charsout=' . strlen($result->get_error_data()) . '&plugin=' . $plugin;
29+                                       wp_redirect(add_query_arg('_error_nonce', wp_create_nonce('plugin-activation-error_' . $plugin), $redirect));
30+                                       exit;
31+                               } else {
32+                                       wp_die($result);
33+                               }
34+                       }
35 
36                        $recent = (array)get_option('recently_activated');
37                        if ( isset($recent[ $plugin ]) ) {
38@@ -157,7 +164,10 @@
39                        check_admin_referer('deactivate-plugin_' . $plugin);
40                        deactivate_plugins($plugin);
41                        update_option('recently_activated', array($plugin => time()) + (array)get_option('recently_activated'));
42-                       wp_redirect("plugins.php?deactivate=true&plugin_status=$status&paged=$page");
43+                       if (headers_sent())
44+                               echo "<meta http-equiv='refresh' content='0;url=plugins.php?deactivate=true&plugin_status=$status&paged=$page' />";
45+                       else
46+                               wp_redirect("plugins.php?deactivate=true&plugin_status=$status&paged=$page");
47                        exit;
48                        break;
49                case 'deactivate-selected':
50@@ -302,8 +312,15 @@
51                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>';
52 ?>
53 
54-<?php if ( isset($_GET['error']) ) : ?>
55-       <div id="message" class="updated"><p><?php _e('Plugin could not be activated because it triggered a <strong>fatal error</strong>.') ?></p>
56+<?php if ( isset($_GET['error']) ) :
57+
58+       if (isset($_GET['charsout']))
59+               $errmsg = sprintf(__('Plugin could not be activated because it generated %d bytes of <strong>unexpected output</strong>.'), $_GET['charsout']);
60+       else
61+               $errmsg = __('Plugin could not be activated because it triggered a <strong>fatal error</strong>.');
62+
63+       ?>
64+       <div id="message" class="updated"><p><?php echo $errmsg; ?></p>
65        <?php
66                if ( wp_verify_nonce($_GET['_error_nonce'], 'plugin-activation-error_' . $plugin) ) { ?>
67        <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>