3 * Edit plugin editor administration panel.
6 * @subpackage Administration
9 /** WordPress Administration Bootstrap */
10 require_once('admin.php');
12 $title = __("Edit Plugins");
13 $parent_file = 'plugins.php';
15 wp_reset_vars(array('action', 'redirect', 'profile', 'error', 'warning', 'a', 'file'));
17 wp_admin_css( 'theme-editor' );
19 $plugins = get_plugins();
20 $plugin_files = array_keys($plugins);
23 $file = $plugin_files[0];
25 $file = validate_file_to_edit($file, $plugin_files);
26 $real_file = WP_PLUGIN_DIR . '/' . $file;
32 check_admin_referer('edit-plugin_' . $file);
34 if ( !current_user_can('edit_plugins') )
35 wp_die('<p>'.__('You do not have sufficient permissions to edit templates for this blog.').'</p>');
37 $newcontent = stripslashes($_POST['newcontent']);
38 if ( is_writeable($real_file) ) {
39 $f = fopen($real_file, 'w+');
40 fwrite($f, $newcontent);
43 // Deactivate so we can test it.
44 if ( is_plugin_active($file) || isset($_POST['phperror']) ) {
45 if ( is_plugin_active($file) )
46 deactivate_plugins($file, true);
47 wp_redirect(add_query_arg('_wpnonce', wp_create_nonce('edit-plugin-test_' . $file), "plugin-editor.php?file=$file&liveupdate=1"));
50 wp_redirect("plugin-editor.php?file=$file&a=te");
52 wp_redirect("plugin-editor.php?file=$file");
60 if ( !current_user_can('edit_plugins') )
61 wp_die('<p>'.__('You do not have sufficient permissions to edit plugins for this blog.').'</p>');
63 if ( isset($_GET['liveupdate']) ) {
64 check_admin_referer('edit-plugin-test_' . $file);
66 $error = validate_plugin($file);
67 if( is_wp_error($error) )
70 if ( ! is_plugin_active($file) )
71 activate_plugin($file, "plugin-editor.php?file=$file&phperror=1");// we'll override this later if the plugin can be included without fatal error
73 wp_redirect("plugin-editor.php?file=$file&a=te");
77 require_once('admin-header.php');
79 update_recently_edited(WP_PLUGIN_DIR . '/' . $file);
81 if ( ! is_file($real_file) )
85 $content = htmlspecialchars(file_get_contents($real_file));
88 <?php if (isset($_GET['a'])) : ?>
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>
93 if ( wp_verify_nonce($_GET['_error_nonce'], 'plugin-activation-error_' . $file) ) { ?>
94 <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>
99 <?php screen_icon(); ?>
100 <h2><?php echo wp_specialchars( $title ); ?></h2>
102 <div class="tablenav">
103 <div class="alignleft">
105 if ( is_plugin_active($file) ) {
106 if ( is_writeable($real_file) )
107 echo sprintf(__('Editing <strong>%s</strong> (active)'), $file);
109 echo sprintf(__('Browsing <strong>%s</strong> (active)'), $file);
111 if ( is_writeable($real_file) )
112 echo sprintf(__('Editing <strong>%s</strong> (inactive)'), $file);
114 echo sprintf(__('Browsing <strong>%s</strong> (inactive)'), $file);
121 <div id="templateside">
122 <h3 id="bordertitle"><?php _e('Plugin Files'); ?></h3>
124 <h4><?php _e('Plugins'); ?></h4>
126 <?php foreach($plugin_files as $plugin_file) : ?>
127 <li><a href="plugin-editor.php?file=<?php echo $plugin_file; ?>"><?php echo $plugins[$plugin_file]['Name']; ?></a></li>
131 <?php if ( ! $error ) { ?>
132 <form name="template" id="template" action="plugin-editor.php" method="post">
133 <?php wp_nonce_field('edit-plugin_' . $file) ?>
134 <div><textarea cols="70" rows="25" name="newcontent" id="newcontent" tabindex="1"><?php echo $content ?></textarea>
135 <input type="hidden" name="action" value="update" />
136 <input type="hidden" name="file" value="<?php echo $file ?>" />
138 <?php if ( is_writeable($real_file) ) : ?>
139 <?php if ( in_array($file, (array) get_option('active_plugins')) ) { ?>
140 <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>
144 if ( isset($_GET['phperror']) )
145 echo "<input type='hidden' name='phperror' value='1' /><input type='submit' name='submit' class='button-primary' value='" . __('Update File and Attempt to Reactivate') . "' tabindex='2' />";
147 echo "<input type='submit' name='submit' class='button-primary' value='" . __('Update File') . "' tabindex='2' />";
151 <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>
156 echo '<div class="error"><p>' . __('Oops, no such file exists! Double check the name and try again, merci.') . '</p></div>';
159 <div class="clear"> </div>
164 include("admin-footer.php") ?>