Skip to content

Instantly share code, notes, and snippets.

@grafikchaos
Created July 28, 2011 15:49
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save grafikchaos/1111795 to your computer and use it in GitHub Desktop.
Save grafikchaos/1111795 to your computer and use it in GitHub Desktop.
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