Make WordPress Core

Opened 14 years ago

Closed 14 years ago

#4408 closed enhancement (duplicate)

plugin_basename() fix

Reported by: Ozh Owned by:
Milestone: Priority: normal
Severity: normal Version: 2.2
Component: Administration Keywords: register_activation_hook plugin_basename
Focuses: Cc:


Actual function plugin_basename() is broken and does not sanitize filenames on Win32 install. Therefore function register_(de)activation_hook() is also broken.
Example : plugin_basename('c:\wordpress\wp-content\plugins\hello\hello.php') returns 'hello\hello.php'

Here is a fix for this function :

function plugin_basename($file) {
	$file = str_replace('\\','/',$file); // sanitize for Win32 installs
	$file = preg_replace('|/+|','/', $file); // remove any duplicate slash
	$file = preg_replace('|^.*/wp-content/plugins/|','',$file); // get relative path from plugins dir
	return $file;

Note that this will fix the problem of failed plugin activation hook, but will probably break some plugins relying on the broken function on win32 installs.

Change History (3)

#1 @westi
14 years ago

  • Milestone set to 2.2.2
  • Version set to 2.2

Dupe of #3002

Leaving open as has patch info.

#2 @DD32
14 years ago

Patch added to #3002 using this code.

#3 @Nazgul
14 years ago

  • Milestone 2.2.2 deleted
  • Resolution set to duplicate
  • Status changed from new to closed

Closing as dupe as the patch made it's way to #3002.

Note: See TracTickets for help on using tickets.