#1641 closed defect (bug) (invalid)
Sort plugins by name instead of filename
Reported by: | Viper007Bond | Owned by: | |
---|---|---|---|
Milestone: | Priority: | low | |
Severity: | trivial | Version: | 1.5.2 |
Component: | Administration | Keywords: | bg|has-patch |
Focuses: | Cc: |
Description
First off, my apologies if I'm doing any of this wrong. This is my first ticket. ;)
Basically, I got tired of the "Manage Plugins" page being sorted by the plugin's filename instead of the plugin's name, so here's some code that sorts it by name.
Starting on line 1038 of "/wp-admin/admin-functions.php" is this:
$wp_plugins[plugin_basename($plugin_file)] = $plugin_data; } return $wp_plugins;
It gets replaced with this:
$plugin_data['Filename'] = plugin_basename($plugin_file); $wp_plugins[$plugin_data['Name']] = $plugin_data; } ksort($wp_plugins); return $wp_plugins;
Since we've now changed the key of the array from the filename to the plugin's name, we gotta change "/wp-admin/plugins.php" a bit.
On line 84 is this:
foreach($plugins as $plugin_file => $plugin_data) {
It gets replaced by this:
foreach($plugins as $plugin_name => $plugin_data) { $plugin_file = $plugin_data['Filename'];
And that should do it! :)
Attachments (4)
Change History (11)
#1
@
19 years ago
Oh crap, just realized "/wp-admin/plugin-editor.php" also calls the function in "admin-functions.php". However, since the array now has the names as the keys, there's no way to figure out the name of the plugin if you only have the filename.
Before, this was all that was needed:
$plugins[$plugin_file]['Name']
Not sure what to do now besides manually go and get the plugin's name again. If anyone can think of a better way than this...
Starting on line 23:
$plugins = get_plugins(); $plugin_files = array_keys($plugins); if (empty($file)) { $file = $plugin_files[0]; }
Replace with:
$plugins = get_plugins(); $plugin_files = array(); foreach($plugins as $plugin) { $plugin_files[] = $plugin['Filename']; }
On line 93:
<li><a href="plugin-editor.php?file=<?php echo "$plugin_file"; ?>"><?php echo $plugins[$plugin_file]['Name']; ?></a></li>
Replace with:
$plugin_data = implode('', file(ABSPATH . 'wp-content/plugins/' . $plugin_file)); preg_match("|Plugin Name:(.*)|i", $plugin_data, $plugin_name); ?> <li><a href="plugin-editor.php?file=<?php echo "$plugin_file"; ?>"><?php echo $plugin_name[1]; ?></a></li>
Not as efficient as the old way, but oh well. At least the plugins are now sorted properly here as well! :D
#2
@
19 years ago
Er, attached version of "plugin-editor.php" is corrent, but the above comment is not (forgot that the moved "?>" changes line 92 as well). It should be:
Starting on line 92:
<?php foreach($plugin_files as $plugin_file) : ?> <li><a href="plugin-editor.php?file=<?php echo "$plugin_file"; ?>"><?php echo $plugins[$plugin_file]['Name']; ?></a></li>
Which gets replaced by:
<?php foreach($plugin_files as $plugin_file) : $plugin_data = implode('', file(ABSPATH . 'wp-content/plugins/' . $plugin_file)); preg_match("|Plugin Name:(.*)|i", $plugin_data, $plugin_name); ?> <li><a href="plugin-editor.php?file=<?php echo "$plugin_file"; ?>"><?php echo $plugin_name[1]; ?></a></li>
#3
@
19 years ago
Ignore everything said above about "plugin-editor.php". I have a way better solution and some of what was said above was wrong.
Starting from a fresh copy of the file, on line 24 we have this:
$plugin_files = array_keys($plugins);
Replace it with this:
$plugin_files = array(); foreach($plugins as $plugin) { $plugin_files[] = $plugin['Filename']; }
Then on lines 92 and 93 is this:
<?php foreach($plugin_files as $plugin_file) : ?> <li><a href="plugin-editor.php?file=<?php echo "$plugin_file"; ?>"><?php echo $plugins[$plugin_file]['Name']; ?></a></li>
Replace it with this:
<?php foreach($plugins as $plugin) : ?> <li><a href="plugin-editor.php?file=<?php echo $plugin['Filename']; ?>"><?php echo $plugin['Name']; ?></a></li>
Works like a charm -- the list is sorted alphabetically, no need to re-read the file to get the plugin's name, and it's quick and simple. :D
I've attached a new copy of a complete "plugin-editor.php" as well.
#4
@
19 years ago
To me it makes perfect sense that they be sorted by filename. It may not look pretty - but IIRC, plugins are called in ascending order their file name. Keeping them sorted that way on the plugin management screen makes the best sense so that users see which order their plugins are being loaded.
#5
@
19 years ago
- Keywords bg|has-patch added
I'd say sorting by filename is better. Users aren't interested in what order their plugins are loaded in. If they are, they can just open up their wp-content directory and have a look.
Changed file in whole