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 wp_admin_css( 'theme-editor' );
11 $plugins = get_plugins();
12 $plugin_files = array_keys($plugins);
15 $file = $plugin_files[0];
17 $file = validate_file_to_edit($file, $plugin_files);
18 $real_file = WP_PLUGIN_DIR . '/' . $file;
24 check_admin_referer('edit-plugin_' . $file);
26 if ( !current_user_can('edit_plugins') )
27 wp_die('<p>'.__('You do not have sufficient permissions to edit templates for this blog.').'</p>');
29 $newcontent = stripslashes($_POST['newcontent']);
30 if ( is_writeable($real_file) ) {
31 $f = fopen($real_file, 'w+');
32 fwrite($f, $newcontent);
35 // Deactivate so we can test it.
36 if ( is_plugin_active($file) || isset($_POST['phperror']) ) {
37 if ( is_plugin_active($file) )
38 deactivate_plugins($file, true);
39 wp_redirect(add_query_arg('_wpnonce', wp_create_nonce('edit-plugin-test_' . $file), "plugin-editor.php?file=$file&liveupdate=1"));
42 wp_redirect("plugin-editor.php?file=$file&a=te");
44 wp_redirect("plugin-editor.php?file=$file");
52 if ( !current_user_can('edit_plugins') )
53 wp_die('<p>'.__('You do not have sufficient permissions to edit plugins for this blog.').'</p>');
55 if ( isset($_GET['liveupdate']) ) {
56 check_admin_referer('edit-plugin-test_' . $file);
58 $error = validate_plugin($file);
59 if( is_wp_error($error) )
62 if ( ! is_plugin_active($file) )
63 activate_plugin($file, "plugin-editor.php?file=$file&phperror=1");// we'll override this later if the plugin can be included without fatal error
65 wp_redirect("plugin-editor.php?file=$file&a=te");
69 require_once('admin-header.php');
71 update_recently_edited(WP_PLUGIN_DIR . '/' . $file);
73 if ( ! is_file($real_file) )
77 $content = htmlspecialchars(file_get_contents($real_file));
80 <?php if (isset($_GET['a'])) : ?>
81 <div id="message" class="updated fade"><p><?php _e('File edited successfully.') ?></p></div>
82 <?php elseif (isset($_GET['phperror'])) : ?>
83 <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>
85 if ( wp_verify_nonce($_GET['_error_nonce'], 'plugin-activation-error_' . $file) ) { ?>
86 <iframe style="border:0" width="100%" height="70px" src="<?php bloginfo('wpurl'); ?>/wp-admin/plugins.php?action=error_scrape&plugin=<?php echo attribute_escape($file); ?>&_wpnonce=<?php echo attribute_escape($_GET['_error_nonce']); ?>"></iframe>
91 <div class="bordertitle">
92 <h2><?php _e('Plugin Editor'); ?></h2>
94 <div class="tablenav">
95 <div class="alignleft">
97 if ( is_plugin_active($file) ) {
98 if ( is_writeable($real_file) )
99 echo sprintf(__('Editing <strong>%s</strong> (active)'), $file);
101 echo sprintf(__('Browsing <strong>%s</strong> (active)'), $file);
103 if ( is_writeable($real_file) )
104 echo sprintf(__('Editing <strong>%s</strong> (inactive)'), $file);
106 echo sprintf(__('Browsing <strong>%s</strong> (inactive)'), $file);
113 <div id="templateside">
114 <h3 id="bordertitle"><?php _e('Plugin Files'); ?></h3>
116 <h4><?php _e('Plugins'); ?></h4>
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>
123 <?php if ( ! $error ) { ?>
124 <form name="template" id="template" action="plugin-editor.php" method="post">
125 <?php wp_nonce_field('edit-plugin_' . $file) ?>
126 <div><textarea cols="70" rows="25" name="newcontent" id="newcontent" tabindex="1"><?php echo $content ?></textarea>
127 <input type="hidden" name="action" value="update" />
128 <input type="hidden" name="file" value="<?php echo $file ?>" />
130 <?php if ( is_writeable($real_file) ) : ?>
131 <?php if ( in_array($file, (array) get_option('active_plugins')) ) { ?>
132 <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>
136 if ( isset($_GET['phperror']) )
137 echo "<input type='hidden' name='phperror' value='1' /><input type='submit' name='submit' value='" . __('Update File and Attempt to Reactivate') . "' tabindex='2' />";
139 echo "<input type='submit' name='submit' value='" . __('Update File') . "' tabindex='2' />";
143 <p><em><?php _e('You need to make this file writable before you can save your changes. See <a href="http://codex.wordpress.org/Changing_File_Permissions">the Codex</a> for more information.'); ?></em></p>
148 echo '<div class="error"><p>' . __('Oops, no such file exists! Double check the name and try again, merci.') . '</p></div>';
151 <div class="clear"> </div>
156 include("admin-footer.php") ?>