From dc1602f411d31ea05c67bf0af5b3c35b04a21872 Mon Sep 17 00:00:00 2001 From: ryan Date: Sun, 22 Feb 2009 20:05:11 +0000 Subject: [PATCH] Allow editing all of a plugin's files. see #6732 git-svn-id: http://svn.automattic.com/wordpress/trunk@10627 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/includes/plugin.php | 41 ++++++++++++++++++++++++++++++++++++ wp-admin/plugin-editor.php | 34 ++++++++++++++++++++++++------ 2 files changed, 69 insertions(+), 6 deletions(-) diff --git a/wp-admin/includes/plugin.php b/wp-admin/includes/plugin.php index 7930ba1525..b2d536f3a5 100644 --- a/wp-admin/includes/plugin.php +++ b/wp-admin/includes/plugin.php @@ -98,6 +98,7 @@ function get_plugin_data( $plugin_file, $markup = true, $translate = true ) { ); if ( $markup || $translate ) $plugin_data = _get_plugin_data_markup_translate($plugin_data, $markup, $translate); + return $plugin_data; } @@ -140,6 +141,46 @@ function _get_plugin_data_markup_translate($plugin_data, $markup = true, $transl return $plugin_data; } +/** + * Get a list of a plugin's files. + * + * @since 2.8.0 + * + * @param string $plugin Plugin ID + * @return array List of files relative to the plugin root. + */ +function get_plugin_files($plugin) { + $plugin_file = WP_PLUGIN_DIR . '/' . $plugin; + $dir = dirname($plugin_file); + $plugin_files = array($plugin); + if ( is_dir($dir) && $dir != WP_PLUGIN_DIR ) { + $plugins_dir = @ opendir( $dir ); + if ( $plugins_dir ) { + while (($file = readdir( $plugins_dir ) ) !== false ) { + if ( substr($file, 0, 1) == '.' ) + continue; + if ( is_dir( $dir . '/' . $file ) ) { + $plugins_subdir = @ opendir( $dir . '/' . $file ); + if ( $plugins_subdir ) { + while (($subfile = readdir( $plugins_subdir ) ) !== false ) { + if ( substr($subfile, 0, 1) == '.' ) + continue; + $plugin_files[] = plugin_basename("$dir/$file/$subfile"); + } + @closedir( $plugins_subdir ); + } + } else { + if ( plugin_basename("$dir/$file") != $plugin ) + $plugin_files[] = plugin_basename("$dir/$file"); + } + } + @closedir( $plugins_dir ); + } + } + + return $plugin_files; +} + /** * Check the plugins directory and retrieve all plugin files with plugin data. * diff --git a/wp-admin/plugin-editor.php b/wp-admin/plugin-editor.php index e6be2a56c8..e43d641f97 100644 --- a/wp-admin/plugin-editor.php +++ b/wp-admin/plugin-editor.php @@ -12,12 +12,18 @@ require_once('admin.php'); $title = __("Edit Plugins"); $parent_file = 'plugins.php'; -wp_reset_vars(array('action', 'redirect', 'profile', 'error', 'warning', 'a', 'file')); +wp_reset_vars(array('action', 'redirect', 'profile', 'error', 'warning', 'a', 'file', 'plugin')); wp_admin_css( 'theme-editor' ); $plugins = get_plugins(); -$plugin_files = array_keys($plugins); + +if ( empty($plugin) ) { + $plugin = array_keys($plugins); + $plugin = $plugin[0]; +} + +$plugin_files = get_plugin_files($plugin); if (empty($file)) $file = $plugin_files[0]; @@ -115,11 +121,27 @@ default:

- +
+
+ + + +
+
%s (active)'), $file); else @@ -138,10 +160,9 @@ default:

-

    - > + >
@@ -151,6 +172,7 @@ default:
+