From 0462e6f4cae1257b4c463a9e318b2bd40d1f584f Mon Sep 17 00:00:00 2001 From: markjaquith Date: Wed, 14 Feb 2007 06:15:05 +0000 Subject: [PATCH] Prevent plugins from taking down the install when plugin edits results in a fatal error. fixes #3254 git-svn-id: http://svn.automattic.com/wordpress/trunk@4881 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/plugin-editor.php | 53 +++++++++++++++++++++++++++++++++++--- 1 file changed, 49 insertions(+), 4 deletions(-) diff --git a/wp-admin/plugin-editor.php b/wp-admin/plugin-editor.php index 2f6ace2f45..b25b3d45b7 100644 --- a/wp-admin/plugin-editor.php +++ b/wp-admin/plugin-editor.php @@ -30,6 +30,17 @@ case 'update': $f = fopen($real_file, 'w+'); fwrite($f, $newcontent); fclose($f); + + // Deactivate so we can test it. + $current = get_option('active_plugins'); + if ( in_array($file, $current) || isset($_POST['phperror']) ) { + if ( in_array($file, $current) ) { + array_splice($current, array_search( $file, $current), 1 ); // Array-fu! + update_option('active_plugins', $current); + } + wp_redirect(add_query_arg('_wpnonce', wp_create_nonce('edit-plugin-test_' . $file), "plugin-editor.php?file=$file&liveupdate=1")); + exit(); + } wp_redirect("plugin-editor.php?file=$file&a=te"); } else { wp_redirect("plugin-editor.php?file=$file"); @@ -44,6 +55,24 @@ default: if ( !current_user_can('edit_plugins') ) wp_die('

'.__('You do not have sufficient permissions to edit plugins for this blog.').'

'); + if ( $_GET['liveupdate'] ) { + check_admin_referer('edit-plugin-test_' . $file); + $current = get_option('active_plugins'); + $plugin = $file; + if ( validate_file($plugin) ) + wp_die(__('Invalid plugin.')); + if ( ! file_exists(ABSPATH . PLUGINDIR . '/' . $plugin) ) + wp_die(__('Plugin file does not exist.')); + if (!in_array($plugin, $current)) { + wp_redirect("plugin-editor.php?file=$file&phperror=1"); // we'll override this later if the plugin can be included without fatal error + @include(ABSPATH . PLUGINDIR . '/' . $plugin); + $current[] = $plugin; + sort($current); + update_option('active_plugins', $current); + } + wp_redirect("plugin-editor.php?file=$file&a=te"); + } + require_once('admin-header.php'); update_recently_edited(PLUGINDIR . "/$file"); @@ -60,13 +89,23 @@ default: ?>

+ +

fatal error.') ?>

' . sprintf(__('Editing %s'), $file) . ''; + if ( in_array($file, (array) get_option('active_plugins')) ) { + if (is_writeable($real_file)) { + echo '

' . sprintf(__('Editing %s (active)'), $file) . '

'; + } else { + echo '

' . sprintf(__('Browsing %s (active)'), $file) . '

'; + } } else { - echo '

' . sprintf(__('Browsing %s'), $file) . '

'; + if (is_writeable($real_file)) { + echo '

' . sprintf(__('Editing %s (inactive)'), $file) . '

'; + } else { + echo '

' . sprintf(__('Browsing %s (inactive)'), $file) . '

'; + } } ?>
@@ -90,9 +129,15 @@ if ($plugin_files) :
+ +

Warning: Making changes to active plugins is not recommended. If your changes cause a fatal error, the plugin will be automatically deactivated.'); ?>

+

"; + if ( isset($_GET['phperror']) ) + echo ""; + else + echo ""; ?>