Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
patch for WordPress plugin_basename() to correctly handle local files and symlinked files
EDIT: removed the first patch b/c it wasn't completely correct. Below is the complete patch that should be applied.
diff --git a/wp-includes/plugin.php b/wp-includes/plugin.php
index 5bc475d..5b5e693 100644
--- a/wp-includes/plugin.php
+++ b/wp-includes/plugin.php
@@ -568,10 +568,12 @@ function plugin_basename($file) {
$mu_plugin_dir = preg_replace('|/+|','/', $mu_plugin_dir); // remove any duplicate slash
$file = preg_replace('#^' . preg_quote($plugin_dir, '#') . '/|^' . preg_quote($mu_plugin_dir, '#') . '/#','',$file); // get relative path from plugins dir
- $file = trim($file, '/');
+
+ $dir = basename(dirname($file));
+ $filename = basename($file);
+ $filepath = ($dir == '.') ? $filename : $dir . '/' . $filename;
+
+ $file = trim($filepath, '/');
-
return $file;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment