Make WordPress Core

Changeset 4881


Ignore:
Timestamp:
02/14/2007 06:15:05 AM (18 years ago)
Author:
markjaquith
Message:

Prevent plugins from taking down the install when plugin edits results in a fatal error. fixes #3254

File:
1 edited

Legend:

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

    r4495 r4881  
    3131        fwrite($f, $newcontent);
    3232        fclose($f);
     33
     34        // Deactivate so we can test it.
     35        $current = get_option('active_plugins');
     36        if ( in_array($file, $current) || isset($_POST['phperror']) ) {
     37            if ( in_array($file, $current) ) {
     38                array_splice($current, array_search( $file, $current), 1 ); // Array-fu!
     39                update_option('active_plugins', $current);
     40            }
     41            wp_redirect(add_query_arg('_wpnonce', wp_create_nonce('edit-plugin-test_' . $file), "plugin-editor.php?file=$file&liveupdate=1"));
     42            exit();
     43        }
    3344        wp_redirect("plugin-editor.php?file=$file&a=te");
    3445    } else {
     
    4455    if ( !current_user_can('edit_plugins') )
    4556        wp_die('<p>'.__('You do not have sufficient permissions to edit plugins for this blog.').'</p>');
     57
     58    if ( $_GET['liveupdate'] ) {
     59        check_admin_referer('edit-plugin-test_' . $file);
     60        $current = get_option('active_plugins');
     61        $plugin = $file;
     62        if ( validate_file($plugin) )
     63            wp_die(__('Invalid plugin.'));
     64        if ( ! file_exists(ABSPATH . PLUGINDIR . '/' . $plugin) )
     65            wp_die(__('Plugin file does not exist.'));
     66        if (!in_array($plugin, $current)) {
     67            wp_redirect("plugin-editor.php?file=$file&phperror=1"); // we'll override this later if the plugin can be included without fatal error
     68            @include(ABSPATH . PLUGINDIR . '/' . $plugin);
     69            $current[] = $plugin;
     70            sort($current);
     71            update_option('active_plugins', $current);
     72        }
     73        wp_redirect("plugin-editor.php?file=$file&a=te");
     74    }
    4675
    4776    require_once('admin-header.php');
     
    6190<?php if (isset($_GET['a'])) : ?>
    6291 <div id="message" class="updated fade"><p><?php _e('File edited successfully.') ?></p></div>
     92<?php elseif (isset($_GET['phperror'])) : ?>
     93 <div id="message" class="updated fade"><p><?php _e('This plugin has been deactivated because your changes resulted in a <strong>fatal error</strong>.') ?></p></div>
    6394<?php endif; ?>
    6495 <div class="wrap">
    6596    <?php
    66     if (is_writeable($real_file)) {
    67         echo '<h2>' . sprintf(__('Editing <strong>%s</strong>'), $file) . '</h2>';
     97    if ( in_array($file, (array) get_option('active_plugins')) ) {
     98        if (is_writeable($real_file)) {
     99            echo '<h2>' . sprintf(__('Editing <strong>%s</strong> (active)'), $file) . '</h2>';
     100        } else {
     101        echo '<h2>' . sprintf(__('Browsing <strong>%s</strong> (active)'), $file) . '</h2>';
     102        }
    68103    } else {
    69         echo '<h2>' . sprintf(__('Browsing <strong>%s</strong>'), $file) . '</h2>';
     104        if (is_writeable($real_file)) {
     105            echo '<h2>' . sprintf(__('Editing <strong>%s</strong> (inactive)'), $file) . '</h2>';
     106        } else {
     107        echo '<h2>' . sprintf(__('Browsing <strong>%s</strong> (inactive)'), $file) . '</h2>';
     108        }
    70109    }
    71110    ?>
     
    91130        </div>
    92131<?php if ( is_writeable($real_file) ) : ?>
     132    <?php if ( in_array($file, (array) get_option('active_plugins')) ) { ?>
     133        <p><?php _e('<strong>Warning:</strong> Making changes to active plugins is not recommended.  If your changes cause a fatal error, the plugin will be automatically deactivated.'); ?></p>
     134    <?php } ?>
    93135    <p class="submit">
    94136    <?php
    95         echo "<input type='submit' name='submit' value='    " . __('Update File &raquo;') . "' tabindex='2' />";
     137        if ( isset($_GET['phperror']) )
     138            echo "<input type='hidden' name='phperror' value='1' /><input type='submit' name='submit' value='" . __('Update File and Attempt to Reactivate &raquo;') . "' tabindex='2' />";
     139        else
     140            echo "<input type='submit' name='submit' value='" . __('Update File &raquo;') . "' tabindex='2' />";
    96141    ?>
    97142    </p>
Note: See TracChangeset for help on using the changeset viewer.