Projects : mp-wp : mp-wp_genesis

mp-wp/wp-admin/plugin-editor.php

Dir - Raw

1<?php
2/**
3 * Edit plugin editor administration panel.
4 *
5 * @package WordPress
6 * @subpackage Administration
7 */
8
9/** WordPress Administration Bootstrap */
10require_once('admin.php');
11
12$title = __("Edit Plugins");
13$parent_file = 'plugins.php';
14
15wp_reset_vars(array('action', 'redirect', 'profile', 'error', 'warning', 'a', 'file'));
16
17wp_admin_css( 'theme-editor' );
18
19$plugins = get_plugins();
20$plugin_files = array_keys($plugins);
21
22if (empty($file))
23 $file = $plugin_files[0];
24
25$file = validate_file_to_edit($file, $plugin_files);
26$real_file = WP_PLUGIN_DIR . '/' . $file;
27
28switch($action) {
29
30case 'update':
31
32 check_admin_referer('edit-plugin_' . $file);
33
34 if ( !current_user_can('edit_plugins') )
35 wp_die('<p>'.__('You do not have sufficient permissions to edit templates for this blog.').'</p>');
36
37 $newcontent = stripslashes($_POST['newcontent']);
38 if ( is_writeable($real_file) ) {
39 $f = fopen($real_file, 'w+');
40 fwrite($f, $newcontent);
41 fclose($f);
42
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"));
48 exit;
49 }
50 wp_redirect("plugin-editor.php?file=$file&a=te");
51 } else {
52 wp_redirect("plugin-editor.php?file=$file");
53 }
54 exit;
55
56break;
57
58default:
59
60 if ( !current_user_can('edit_plugins') )
61 wp_die('<p>'.__('You do not have sufficient permissions to edit plugins for this blog.').'</p>');
62
63 if ( isset($_GET['liveupdate']) ) {
64 check_admin_referer('edit-plugin-test_' . $file);
65
66 $error = validate_plugin($file);
67 if( is_wp_error($error) )
68 wp_die( $error );
69
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
72
73 wp_redirect("plugin-editor.php?file=$file&a=te");
74 exit;
75 }
76
77 require_once('admin-header.php');
78
79 update_recently_edited(WP_PLUGIN_DIR . '/' . $file);
80
81 if ( ! is_file($real_file) )
82 $error = 1;
83
84 if ( ! $error )
85 $content = htmlspecialchars(file_get_contents($real_file));
86
87 ?>
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>
92 <?php
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&amp;plugin=<?php echo attribute_escape($file); ?>&amp;_wpnonce=<?php echo attribute_escape($_GET['_error_nonce']); ?>"></iframe>
95 <?php } ?>
96</div>
97<?php endif; ?>
98<div class="wrap">
99<?php screen_icon(); ?>
100<h2><?php echo wp_specialchars( $title ); ?></h2>
101
102<div class="tablenav">
103<div class="alignleft">
104<big><?php
105 if ( is_plugin_active($file) ) {
106 if ( is_writeable($real_file) )
107 echo sprintf(__('Editing <strong>%s</strong> (active)'), $file);
108 else
109 echo sprintf(__('Browsing <strong>%s</strong> (active)'), $file);
110 } else {
111 if ( is_writeable($real_file) )
112 echo sprintf(__('Editing <strong>%s</strong> (inactive)'), $file);
113 else
114 echo sprintf(__('Browsing <strong>%s</strong> (inactive)'), $file);
115 }
116 ?></big>
117</div>
118<br class="clear" />
119</div>
120<br class="clear" />
121 <div id="templateside">
122 <h3 id="bordertitle"><?php _e('Plugin Files'); ?></h3>
123
124 <h4><?php _e('Plugins'); ?></h4>
125 <ul>
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>
128<?php endforeach; ?>
129 </ul>
130 </div>
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 ?>" />
137 </div>
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>
141 <?php } ?>
142 <p class="submit">
143 <?php
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' />";
146 else
147 echo "<input type='submit' name='submit' class='button-primary' value='" . __('Update File') . "' tabindex='2' />";
148 ?>
149 </p>
150<?php else : ?>
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>
152<?php endif; ?>
153 </form>
154<?php
155 } else {
156 echo '<div class="error"><p>' . __('Oops, no such file exists! Double check the name and try again, merci.') . '</p></div>';
157 }
158?>
159<div class="clear"> &nbsp; </div>
160</div>
161<?php
162 break;
163}
164include("admin-footer.php") ?>