- die('<p>'.__('You have do not have sufficient permissions to edit plugins for this blog.').'</p>');
-
- update_recently_edited("wp-content/plugins/$file");
-
- if (!is_file($real_file))
- $error = 1;
-
- if (!$error) {
- $f = fopen($real_file, 'r');
- $content = fread($f, filesize($real_file));
- $content = htmlspecialchars($content);
+ wp_die('<p>'.__('You do not have sufficient permissions to edit plugins for this blog.').'</p>');
+
+ if ( isset($_GET['liveupdate']) ) {
+ check_admin_referer('edit-plugin-test_' . $file);
+
+ $error = validate_plugin($file);
+ if ( is_wp_error($error) )
+ wp_die( $error );
+
+ if ( ! is_plugin_active($file) )
+ activate_plugin($file, "plugin-editor.php?file=$file&phperror=1"); // we'll override this later if the plugin can be included without fatal error
+
+ wp_redirect("plugin-editor.php?file=$file&a=te");
+ exit;
+ }
+
+ // List of allowable extensions
+ $editable_extensions = array('php', 'txt', 'text', 'js', 'css', 'html', 'htm', 'xml', 'inc', 'include');
+ $editable_extensions = (array) apply_filters('editable_extensions', $editable_extensions);
+
+ if ( ! is_file($real_file) ) {
+ wp_die(sprintf('<p>%s</p>', __('No such file exists! Double check the name and try again.')));
+ } else {
+ // Get the extension of the file
+ if ( preg_match('/\.([^.]+)$/', $real_file, $matches) ) {
+ $ext = strtolower($matches[1]);
+ // If extension is not in the acceptable list, skip it
+ if ( !in_array( $ext, $editable_extensions) )
+ wp_die(sprintf('<p>%s</p>', __('Files of this type are not editable.')));
+ }
+ }
+
+ require_once('admin-header.php');
+
+ update_recently_edited(WP_PLUGIN_DIR . '/' . $file);
+
+ $content = file_get_contents( $real_file );
+
+ if ( '.php' == substr( $real_file, strrpos( $real_file, '.' ) ) ) {
+ $functions = wp_doc_link_parse( $content );
+
+ if ( !empty($functions) ) {
+ $docs_select = '<select name="docs-list" id="docs-list">';
+ $docs_select .= '<option value="">' . __( 'Function Name...' ) . '</option>';
+ foreach ( $functions as $function) {
+ $docs_select .= '<option value="' . esc_attr( $function ) . '">' . htmlspecialchars( $function ) . '()</option>';
+ }
+ $docs_select .= '</select>';
+ }