5 * @package WordPress |
5 * @package WordPress |
6 * @subpackage Administration |
6 * @subpackage Administration |
7 */ |
7 */ |
8 |
8 |
9 /** WordPress Administration Bootstrap */ |
9 /** WordPress Administration Bootstrap */ |
10 require_once('admin.php'); |
10 require_once('./admin.php'); |
|
11 |
|
12 if ( is_multisite() && ! is_network_admin() ) { |
|
13 wp_redirect( network_admin_url( 'plugin-editor.php' ) ); |
|
14 exit(); |
|
15 } |
11 |
16 |
12 if ( !current_user_can('edit_plugins') ) |
17 if ( !current_user_can('edit_plugins') ) |
13 wp_die('<p>'.__('You do not have sufficient permissions to edit plugins for this blog.').'</p>'); |
18 wp_die( __('You do not have sufficient permissions to edit plugins for this site.') ); |
14 |
19 |
15 $title = __("Edit Plugins"); |
20 $title = __("Edit Plugins"); |
16 $parent_file = 'plugins.php'; |
21 $parent_file = 'plugins.php'; |
17 |
22 |
18 wp_reset_vars(array('action', 'redirect', 'profile', 'error', 'warning', 'a', 'file', 'plugin')); |
23 wp_reset_vars(array('action', 'redirect', 'profile', 'error', 'warning', 'a', 'file', 'plugin')); |
19 |
24 |
20 wp_admin_css( 'theme-editor' ); |
|
21 |
|
22 $plugins = get_plugins(); |
25 $plugins = get_plugins(); |
|
26 |
|
27 if ( empty($plugins) ) |
|
28 wp_die( __('There are no plugins installed on this site.') ); |
23 |
29 |
24 if ( isset($_REQUEST['file']) ) |
30 if ( isset($_REQUEST['file']) ) |
25 $plugin = stripslashes($_REQUEST['file']); |
31 $plugin = stripslashes($_REQUEST['file']); |
26 |
32 |
27 if ( empty($plugin) ) { |
33 if ( empty($plugin) ) { |
50 if ( is_writeable($real_file) ) { |
56 if ( is_writeable($real_file) ) { |
51 $f = fopen($real_file, 'w+'); |
57 $f = fopen($real_file, 'w+'); |
52 fwrite($f, $newcontent); |
58 fwrite($f, $newcontent); |
53 fclose($f); |
59 fclose($f); |
54 |
60 |
|
61 $network_wide = is_plugin_active_for_network( $file ); |
|
62 |
55 // Deactivate so we can test it. |
63 // Deactivate so we can test it. |
56 if ( is_plugin_active($file) || isset($_POST['phperror']) ) { |
64 if ( is_plugin_active($file) || isset($_POST['phperror']) ) { |
57 if ( is_plugin_active($file) ) |
65 if ( is_plugin_active($file) ) |
58 deactivate_plugins($file, true); |
66 deactivate_plugins($file, true); |
59 wp_redirect(add_query_arg('_wpnonce', wp_create_nonce('edit-plugin-test_' . $file), "plugin-editor.php?file=$file&liveupdate=1&scrollto=$scrollto")); |
67 |
|
68 if ( ! is_network_admin() ) |
|
69 update_option( 'recently_activated', array( $file => time() ) + (array) get_option( 'recently_activated' ) ); |
|
70 |
|
71 wp_redirect(add_query_arg('_wpnonce', wp_create_nonce('edit-plugin-test_' . $file), "plugin-editor.php?file=$file&liveupdate=1&scrollto=$scrollto&networkwide=" . $network_wide)); |
60 exit; |
72 exit; |
61 } |
73 } |
62 wp_redirect("plugin-editor.php?file=$file&a=te&scrollto=$scrollto"); |
74 wp_redirect( self_admin_url("plugin-editor.php?file=$file&a=te&scrollto=$scrollto") ); |
63 } else { |
75 } else { |
64 wp_redirect("plugin-editor.php?file=$file&scrollto=$scrollto"); |
76 wp_redirect( self_admin_url("plugin-editor.php?file=$file&scrollto=$scrollto") ); |
65 } |
77 } |
66 exit; |
78 exit; |
67 |
79 |
68 break; |
80 break; |
69 |
81 |
74 |
86 |
75 $error = validate_plugin($file); |
87 $error = validate_plugin($file); |
76 if ( is_wp_error($error) ) |
88 if ( is_wp_error($error) ) |
77 wp_die( $error ); |
89 wp_die( $error ); |
78 |
90 |
79 if ( ! is_plugin_active($file) ) |
91 if ( ( ! empty( $_GET['networkwide'] ) && ! is_plugin_active_for_network($file) ) || ! is_plugin_active($file) ) |
80 activate_plugin($file, "plugin-editor.php?file=$file&phperror=1"); // we'll override this later if the plugin can be included without fatal error |
92 activate_plugin($file, "plugin-editor.php?file=$file&phperror=1", ! empty( $_GET['networkwide'] ) ); // we'll override this later if the plugin can be included without fatal error |
81 |
93 |
82 wp_redirect("plugin-editor.php?file=$file&a=te&scrollto=$scrollto"); |
94 wp_redirect( self_admin_url("plugin-editor.php?file=$file&a=te&scrollto=$scrollto") ); |
83 exit; |
95 exit; |
84 } |
96 } |
85 |
97 |
86 // List of allowable extensions |
98 // List of allowable extensions |
87 $editable_extensions = array('php', 'txt', 'text', 'js', 'css', 'html', 'htm', 'xml', 'inc', 'include'); |
99 $editable_extensions = array('php', 'txt', 'text', 'js', 'css', 'html', 'htm', 'xml', 'inc', 'include'); |
97 if ( !in_array( $ext, $editable_extensions) ) |
109 if ( !in_array( $ext, $editable_extensions) ) |
98 wp_die(sprintf('<p>%s</p>', __('Files of this type are not editable.'))); |
110 wp_die(sprintf('<p>%s</p>', __('Files of this type are not editable.'))); |
99 } |
111 } |
100 } |
112 } |
101 |
113 |
102 require_once('admin-header.php'); |
114 get_current_screen()->add_help_tab( array( |
|
115 'id' => 'overview', |
|
116 'title' => __('Overview'), |
|
117 'content' => |
|
118 '<p>' . __('You can use the editor to make changes to any of your plugins’ individual PHP files. Be aware that if you make changes, plugins updates will overwrite your customizations.') . '</p>' . |
|
119 '<p>' . __('Choose a plugin to edit from the menu in the upper right and click the Select button. Click once on any file name to load it in the editor, and make your changes. Don’t forget to save your changes (Update File) when you’re finished.') . '</p>' . |
|
120 '<p>' . __('The Documentation menu below the editor lists the PHP functions recognized in the plugin file. Clicking Lookup takes you to a web page about that particular function.') . '</p>' . |
|
121 '<p>' . __('If you want to make changes but don’t want them to be overwritten when the plugin is updated, you may be ready to think about writing your own plugin. For information on how to edit plugins, write your own from scratch, or just better understand their anatomy, check out the links below.') . '</p>' . |
|
122 ( is_network_admin() ? '<p>' . __('Any edits to files from this screen will be reflected on all sites in the network.') . '</p>' : '' ) |
|
123 ) ); |
|
124 |
|
125 get_current_screen()->set_help_sidebar( |
|
126 '<p><strong>' . __('For more information:') . '</strong></p>' . |
|
127 '<p>' . __('<a href="http://codex.wordpress.org/Plugins_Editor_Screen" target="_blank">Documentation on Editing Plugins</a>') . '</p>' . |
|
128 '<p>' . __('<a href="http://codex.wordpress.org/Writing_a_Plugin" target="_blank">Documentation on Writing Plugins</a>') . '</p>' . |
|
129 '<p>' . __('<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>' |
|
130 ); |
|
131 |
|
132 require_once(ABSPATH . 'wp-admin/admin-header.php'); |
103 |
133 |
104 update_recently_edited(WP_PLUGIN_DIR . '/' . $file); |
134 update_recently_edited(WP_PLUGIN_DIR . '/' . $file); |
105 |
135 |
106 $content = file_get_contents( $real_file ); |
136 $content = file_get_contents( $real_file ); |
107 |
137 |
108 if ( '.php' == substr( $real_file, strrpos( $real_file, '.' ) ) ) { |
138 if ( '.php' == substr( $real_file, strrpos( $real_file, '.' ) ) ) { |
109 $functions = wp_doc_link_parse( $content ); |
139 $functions = wp_doc_link_parse( $content ); |
110 |
140 |
111 if ( !empty($functions) ) { |
141 if ( !empty($functions) ) { |
112 $docs_select = '<select name="docs-list" id="docs-list">'; |
142 $docs_select = '<select name="docs-list" id="docs-list">'; |
113 $docs_select .= '<option value="">' . __( 'Function Name...' ) . '</option>'; |
143 $docs_select .= '<option value="">' . __( 'Function Name…' ) . '</option>'; |
114 foreach ( $functions as $function) { |
144 foreach ( $functions as $function) { |
115 $docs_select .= '<option value="' . esc_attr( $function ) . '">' . htmlspecialchars( $function ) . '()</option>'; |
145 $docs_select .= '<option value="' . esc_attr( $function ) . '">' . esc_html( $function ) . '()</option>'; |
116 } |
146 } |
117 $docs_select .= '</select>'; |
147 $docs_select .= '</select>'; |
118 } |
148 } |
119 } |
149 } |
120 |
150 |
121 $content = htmlspecialchars( $content ); |
151 $content = esc_textarea( $content ); |
122 $codepress_lang = codepress_get_lang($real_file); |
|
123 |
|
124 ?> |
152 ?> |
125 <?php if (isset($_GET['a'])) : ?> |
153 <?php if (isset($_GET['a'])) : ?> |
126 <div id="message" class="updated fade"><p><?php _e('File edited successfully.') ?></p></div> |
154 <div id="message" class="updated"><p><?php _e('File edited successfully.') ?></p></div> |
127 <?php elseif (isset($_GET['phperror'])) : ?> |
155 <?php elseif (isset($_GET['phperror'])) : ?> |
128 <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> |
156 <div id="message" class="updated"><p><?php _e('This plugin has been deactivated because your changes resulted in a <strong>fatal error</strong>.') ?></p> |
129 <?php |
157 <?php |
130 if ( wp_verify_nonce($_GET['_error_nonce'], 'plugin-activation-error_' . $file) ) { ?> |
158 if ( wp_verify_nonce($_GET['_error_nonce'], 'plugin-activation-error_' . $file) ) { ?> |
131 <iframe style="border:0" width="100%" height="70px" src="<?php bloginfo('wpurl'); ?>/wp-admin/plugins.php?action=error_scrape&plugin=<?php echo esc_attr($file); ?>&_wpnonce=<?php echo esc_attr($_GET['_error_nonce']); ?>"></iframe> |
159 <iframe style="border:0" width="100%" height="70px" src="<?php bloginfo('wpurl'); ?>/wp-admin/plugins.php?action=error_scrape&plugin=<?php echo esc_attr($file); ?>&_wpnonce=<?php echo esc_attr($_GET['_error_nonce']); ?>"></iframe> |
132 <?php } ?> |
160 <?php } ?> |
133 </div> |
161 </div> |
190 } else { |
218 } else { |
191 // No extension found |
219 // No extension found |
192 continue; |
220 continue; |
193 } |
221 } |
194 ?> |
222 ?> |
195 <li<?php echo $file == $plugin_file ? ' class="highlight"' : ''; ?>><a href="plugin-editor.php?file=<?php echo $plugin_file; ?>&plugin=<?php echo $plugin; ?>"><?php echo $plugin_file ?></a></li> |
223 <li<?php echo $file == $plugin_file ? ' class="highlight"' : ''; ?>><a href="plugin-editor.php?file=<?php echo urlencode( $plugin_file ) ?>&plugin=<?php echo urlencode( $plugin ) ?>"><?php echo $plugin_file ?></a></li> |
196 <?php endforeach; ?> |
224 <?php endforeach; ?> |
197 </ul> |
225 </ul> |
198 </div> |
226 </div> |
199 <form name="template" id="template" action="plugin-editor.php" method="post"> |
227 <form name="template" id="template" action="plugin-editor.php" method="post"> |
200 <?php wp_nonce_field('edit-plugin_' . $file) ?> |
228 <?php wp_nonce_field('edit-plugin_' . $file) ?> |
201 <div><textarea cols="70" rows="25" name="newcontent" id="newcontent" tabindex="1" class="codepress <?php echo $codepress_lang ?>"><?php echo $content ?></textarea> |
229 <div><textarea cols="70" rows="25" name="newcontent" id="newcontent" tabindex="1"><?php echo $content ?></textarea> |
202 <input type="hidden" name="action" value="update" /> |
230 <input type="hidden" name="action" value="update" /> |
203 <input type="hidden" name="file" value="<?php echo esc_attr($file) ?>" /> |
231 <input type="hidden" name="file" value="<?php echo esc_attr($file) ?>" /> |
204 <input type="hidden" name="plugin" value="<?php echo esc_attr($plugin) ?>" /> |
232 <input type="hidden" name="plugin" value="<?php echo esc_attr($plugin) ?>" /> |
205 <input type="hidden" name="scrollto" id="scrollto" value="<?php echo $scrollto; ?>" /> |
233 <input type="hidden" name="scrollto" id="scrollto" value="<?php echo $scrollto; ?>" /> |
206 </div> |
234 </div> |
207 <?php if ( !empty( $docs_select ) ) : ?> |
235 <?php if ( !empty( $docs_select ) ) : ?> |
208 <div id="documentation"><label for="docs-list"><?php _e('Documentation:') ?></label> <?php echo $docs_select ?> <input type="button" class="button" value="<?php esc_attr_e( 'Lookup' ) ?> " onclick="if ( '' != jQuery('#docs-list').val() ) { window.open( 'http://api.wordpress.org/core/handbook/1.0/?function=' + escape( jQuery( '#docs-list' ).val() ) + '&locale=<?php echo urlencode( get_locale() ) ?>&version=<?php echo urlencode( $wp_version ) ?>&redirect=true'); }" /></div> |
236 <div id="documentation" class="hide-if-no-js"><label for="docs-list"><?php _e('Documentation:') ?></label> <?php echo $docs_select ?> <input type="button" class="button" value="<?php esc_attr_e( 'Lookup' ) ?> " onclick="if ( '' != jQuery('#docs-list').val() ) { window.open( 'http://api.wordpress.org/core/handbook/1.0/?function=' + escape( jQuery( '#docs-list' ).val() ) + '&locale=<?php echo urlencode( get_locale() ) ?>&version=<?php echo urlencode( $wp_version ) ?>&redirect=true'); }" /></div> |
209 <?php endif; ?> |
237 <?php endif; ?> |
210 <?php if ( is_writeable($real_file) ) : ?> |
238 <?php if ( is_writeable($real_file) ) : ?> |
211 <?php if ( in_array($file, (array) get_option('active_plugins')) ) { ?> |
239 <?php if ( in_array( $file, (array) get_option( 'active_plugins', array() ) ) ) { ?> |
212 <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> |
240 <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> |
213 <?php } ?> |
241 <?php } ?> |
214 <p class="submit"> |
242 <p class="submit"> |
215 <?php |
243 <?php |
216 if ( isset($_GET['phperror']) ) |
244 if ( isset($_GET['phperror']) ) { |
217 echo "<input type='hidden' name='phperror' value='1' /><input type='submit' name='submit' class='button-primary' value='" . esc_attr__('Update File and Attempt to Reactivate') . "' tabindex='2' />"; |
245 echo "<input type='hidden' name='phperror' value='1' />"; |
218 else |
246 submit_button( __( 'Update File and Attempt to Reactivate' ), 'primary', 'submit', false, array( 'tabindex' => '2' ) ); |
219 echo "<input type='submit' name='submit' class='button-primary' value='" . esc_attr__('Update File') . "' tabindex='2' />"; |
247 } else { |
|
248 submit_button( __( 'Update File' ), 'primary', 'submit', false, array( 'tabindex' => '2' ) ); |
|
249 } |
220 ?> |
250 ?> |
221 </p> |
251 </p> |
222 <?php else : ?> |
252 <?php else : ?> |
223 <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> |
253 <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> |
224 <?php endif; ?> |
254 <?php endif; ?> |