- $current = get_option('active_plugins');
- $plugin = $file;
- if ( validate_file($plugin) )
- wp_die(__('Invalid plugin.'));
- if ( ! file_exists(ABSPATH . PLUGINDIR . '/' . $plugin) )
- wp_die(__('Plugin file does not exist.'));
- if (!in_array($plugin, $current)) {
- wp_redirect("plugin-editor.php?file=$file&phperror=1"); // we'll override this later if the plugin can be included without fatal error
- @include(ABSPATH . PLUGINDIR . '/' . $plugin);
- $current[] = $plugin;
- sort($current);
- update_option('active_plugins', $current);
+
+ $error = validate_plugin($file);
+ if ( is_wp_error($error) )
+ wp_die( $error );
+
+ if ( ( ! empty( $_GET['networkwide'] ) && ! is_plugin_active_for_network($file) ) || ! is_plugin_active($file) )
+ 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
+
+ wp_redirect( self_admin_url("plugin-editor.php?file=$file&a=te&scrollto=$scrollto") );
+ exit;
+ }
+
+ // List of allowable extensions
+ $editable_extensions = array('php', 'txt', 'text', 'js', 'css', 'html', 'htm', 'xml', 'inc', 'include');
+
+ /**
+ * Filter file type extensions editable in the plugin editor.
+ *
+ * @since 2.8.0
+ *
+ * @param array $editable_extensions An array of editable plugin file extensions.
+ */
+ $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.')));