Ticket #3254: prevent_plugin_fatal_errors.002.diff
File prevent_plugin_fatal_errors.002.diff, 3.4 KB (added by , 18 years ago) |
---|
-
wp-admin/plugin-editor.php
30 30 $f = fopen($real_file, 'w+'); 31 31 fwrite($f, $newcontent); 32 32 fclose($f); 33 34 // Deactivate so we can test it. 35 $current = get_option('active_plugins'); 36 if ( in_array($file, $current) ) { 37 array_splice($current, array_search( $file, $current), 1 ); // Array-fu! 38 update_option('active_plugins', $current); 39 wp_redirect(add_query_arg('_wpnonce', wp_create_nonce('edit-plugin-test_' . $file), "plugin-editor.php?file=$file&liveupdate=1")); 40 exit(); 41 } 33 42 wp_redirect("plugin-editor.php?file=$file&a=te"); 34 43 } else { 35 44 wp_redirect("plugin-editor.php?file=$file"); … … 44 53 if ( !current_user_can('edit_plugins') ) 45 54 wp_die('<p>'.__('You do not have sufficient permissions to edit plugins for this blog.').'</p>'); 46 55 56 if ( $_GET['liveupdate'] ) { 57 check_admin_referer('edit-plugin-test_' . $file); 58 $current = get_option('active_plugins'); 59 $plugin = $file; 60 if ( validate_file($plugin) ) 61 wp_die(__('Invalid plugin.')); 62 if ( ! file_exists(ABSPATH . PLUGINDIR . '/' . $plugin) ) 63 wp_die(__('Plugin file does not exist.')); 64 if (!in_array($plugin, $current)) { 65 wp_redirect("plugin-editor.php?file=$file&phperror=1"); // we'll override this later if the plugin can be included without fatal error 66 @include(ABSPATH . PLUGINDIR . '/' . $plugin); 67 $current[] = $plugin; 68 sort($current); 69 update_option('active_plugins', $current); 70 } 71 wp_redirect("plugin-editor.php?file=$file&a=te"); 72 } 73 47 74 require_once('admin-header.php'); 48 75 49 76 update_recently_edited(PLUGINDIR . "/$file"); … … 60 87 ?> 61 88 <?php if (isset($_GET['a'])) : ?> 62 89 <div id="message" class="updated fade"><p><?php _e('File edited successfully.') ?></p></div> 90 <?php elseif (isset($_GET['phperror'])) : ?> 91 <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> 63 92 <?php endif; ?> 64 93 <div class="wrap"> 65 94 <?php 66 if (is_writeable($real_file)) { 67 echo '<h2>' . sprintf(__('Editing <strong>%s</strong>'), $file) . '</h2>'; 95 if ( in_array($file, (array) get_option('active_plugins')) ) { 96 if (is_writeable($real_file)) { 97 echo '<h2>' . sprintf(__('Editing <strong>%s</strong> (active)'), $file) . '</h2>'; 98 } else { 99 echo '<h2>' . sprintf(__('Browsing <strong>%s</strong> (active)'), $file) . '</h2>'; 100 } 68 101 } else { 69 echo '<h2>' . sprintf(__('Browsing <strong>%s</strong>'), $file) . '</h2>'; 102 if (is_writeable($real_file)) { 103 echo '<h2>' . sprintf(__('Editing <strong>%s</strong> (inactive)'), $file) . '</h2>'; 104 } else { 105 echo '<h2>' . sprintf(__('Browsing <strong>%s</strong> (inactive)'), $file) . '</h2>'; 106 } 70 107 } 71 108 ?> 72 109 <div id="templateside"> … … 90 127 <input type="hidden" name="file" value="<?php echo $file ?>" /> 91 128 </div> 92 129 <?php if ( is_writeable($real_file) ) : ?> 130 <?php if ( in_array($file, (array) get_option('active_plugins')) ) { ?> 131 <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> 132 <?php } ?> 93 133 <p class="submit"> 94 134 <?php 95 135 echo "<input type='submit' name='submit' value=' " . __('Update File »') . "' tabindex='2' />";