2 require_once('admin.php');
4 $title = __("Edit Plugins");
5 $parent_file = 'plugins.php';
7 wp_reset_vars(array('action', 'redirect', 'profile', 'error', 'warning', 'a', 'file'));
9 $plugins = get_plugins();
10 $plugin_files = array_keys($plugins);
13 $file = $plugin_files[0];
16 $file = validate_file_to_edit($file, $plugin_files);
17 $real_file = get_real_file_to_edit( PLUGINDIR . "/$file");
23 check_admin_referer('edit-plugin_' . $file);
25 if ( !current_user_can('edit_plugins') )
26 wp_die('<p>'.__('You do not have sufficient permissions to edit templates for this blog.').'</p>');
28 $newcontent = stripslashes($_POST['newcontent']);
29 if (is_writeable($real_file)) {
30 $f = fopen($real_file, 'w+');
31 fwrite($f, $newcontent);
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);
41 wp_redirect(add_query_arg('_wpnonce', wp_create_nonce('edit-plugin-test_' . $file), "plugin-editor.php?file=$file&liveupdate=1"));
44 wp_redirect("plugin-editor.php?file=$file&a=te");
46 wp_redirect("plugin-editor.php?file=$file");
55 if ( !current_user_can('edit_plugins') )
56 wp_die('<p>'.__('You do not have sufficient permissions to edit plugins for this blog.').'</p>');
58 if ( $_GET['liveupdate'] ) {
59 check_admin_referer('edit-plugin-test_' . $file);
60 $current = get_option('active_plugins');
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);
71 update_option('active_plugins', $current);
73 wp_redirect("plugin-editor.php?file=$file&a=te");
76 require_once('admin-header.php');
78 update_recently_edited(PLUGINDIR . "/$file");
80 if (!is_file($real_file))
84 $f = fopen($real_file, 'r');
85 $content = fread($f, filesize($real_file));
86 $content = htmlspecialchars($content);
90 <?php if (isset($_GET['a'])) : ?>
91 <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>
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>';
101 echo '<h2>' . sprintf(__('Browsing <strong>%s</strong> (active)'), $file) . '</h2>';
104 if (is_writeable($real_file)) {
105 echo '<h2>' . sprintf(__('Editing <strong>%s</strong> (inactive)'), $file) . '</h2>';
107 echo '<h2>' . sprintf(__('Browsing <strong>%s</strong> (inactive)'), $file) . '</h2>';
111 <div id="templateside">
112 <h3><?php _e('Plugin files') ?></h3>
118 <?php foreach($plugin_files as $plugin_file) : ?>
119 <li><a href="plugin-editor.php?file=<?php echo "$plugin_file"; ?>"><?php echo $plugins[$plugin_file]['Name']; ?></a></li>
124 <?php if (!$error) { ?>
125 <form name="template" id="template" action="plugin-editor.php" method="post">
126 <?php wp_nonce_field('edit-plugin_' . $file) ?>
127 <div><textarea cols="70" rows="25" name="newcontent" id="newcontent" tabindex="1"><?php echo $content ?></textarea>
128 <input type="hidden" name="action" value="update" />
129 <input type="hidden" name="file" value="<?php echo $file ?>" />
131 <?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>
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 »') . "' tabindex='2' />";
140 echo "<input type='submit' name='submit' value='" . __('Update File »') . "' tabindex='2' />";
144 <p><em><?php _e('If this file were writable you could edit it.'); ?></em></p>
149 echo '<div class="error"><p>' . __('Oops, no such file exists! Double check the name and try again, merci.') . '</p></div>';
152 <div class="clear"> </div>
158 include("admin-footer.php") ?>