Allow plugins to be loaded from subdirs of wp-content/plugins.

git-svn-id: http://svn.automattic.com/wordpress/trunk@1894 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
rboren 2004-11-28 00:33:04 +00:00
parent 75804fd8ab
commit bd4e71a7ba
3 changed files with 28 additions and 24 deletions

View File

@ -732,10 +732,14 @@ function get_admin_page_parent() {
return '';
}
function plugin_basename($file) {
return preg_replace('#^.*wp-content/plugins/#', '', $file);
}
function add_menu_page($page_title, $menu_title, $access_level, $file) {
global $menu;
$file = basename($file);
$file = plugin_basename($file);
$menu[] = array($menu_title, $access_level, $file, $page_title);
}
@ -743,7 +747,7 @@ function add_menu_page($page_title, $menu_title, $access_level, $file) {
function add_submenu_page($parent, $page_title, $menu_title, $access_level, $file) {
global $submenu;
$file = basename($file);
$file = plugin_basename($file);
$submenu[$parent][] = array($menu_title, $access_level, $file, $page_title);
}
@ -884,10 +888,24 @@ function get_plugins() {
$plugins_dir = @ dir($plugin_root);
if ($plugins_dir) {
while(($file = $plugins_dir->read()) !== false) {
if ( !preg_match('|^\.+$|', $file) && preg_match('|\.php$|', $file) )
if ( preg_match('|^\.+$|', $file) )
continue;
if (is_dir($plugin_root . '/' . $file)) {
$plugins_subdir = @ dir($plugin_root . '/' . $file);
if ($plugins_subdir) {
while(($subfile = $plugins_subdir->read()) !== false) {
if ( preg_match('|^\.+$|', $subfile) )
continue;
if ( preg_match('|\.php$|', $subfile) )
$plugin_files[] = "$file/$subfile";
}
}
} else {
if ( preg_match('|\.php$|', $file) )
$plugin_files[] = $file;
}
}
}
if (!$plugins_dir || !$plugin_files) {
return $wp_plugins;
@ -902,7 +920,7 @@ function get_plugins() {
continue;
}
$wp_plugins[basename($plugin_file)] = $plugin_data;
$wp_plugins[plugin_basename($plugin_file)] = $plugin_data;
}
return $wp_plugins;

View File

@ -54,7 +54,7 @@ require(ABSPATH . '/wp-admin/menu.php');
// Handle plugin admin pages.
if (isset($_GET['page'])) {
$plugin_page = basename($_GET['page']);
$plugin_page = plugin_basename($_GET['page']);
if (! file_exists(ABSPATH . "wp-content/plugins/$plugin_page")) {
die(sprintf(__('Cannot load %s.'), $plugin_page));
}

View File

@ -20,29 +20,15 @@ for ($i=0; $i<count($wpvarstoreset); $i += 1) {
}
}
$plugins_dir = @ dir(ABSPATH . 'wp-content/plugins');
if ($plugins_dir) {
while(($plug_file = $plugins_dir->read()) !== false) {
if ( !preg_match('|^\.+$|', $plug_file) && preg_match('|\.php$|', $plug_file) )
$plugin_files[] = "wp-content/plugins/$plug_file";
}
}
if (count($plugin_files)) {
natcasesort($plugin_files);
}
if (file_exists(ABSPATH . 'my-hacks.php')) {
$plugin_files[] = 'my-hacks.php';
}
$plugins = get_plugins();
$plugin_files = array_keys($plugins);
if (empty($file)) {
$file = $plugin_files[0];
}
$file = validate_file_to_edit($file, $plugin_files);
$real_file = get_real_file_to_edit($file);
$real_file = get_real_file_to_edit("wp-content/plugins/$file");
switch($action) {
@ -104,7 +90,7 @@ if ($plugin_files) :
?>
<ul>
<?php foreach($plugin_files as $plugin_file) : ?>
<li><a href="plugin-editor.php?file=<?php echo "$plugin_file"; ?>"><?php echo get_file_description(basename($plugin_file)); ?></a></li>
<li><a href="plugin-editor.php?file=<?php echo "$plugin_file"; ?>"><?php echo $plugins[$plugin_file]['Name']; ?></a></li>
<?php endforeach; ?>
</ul>
<?php endif; ?>