Ticket #4408 (closed enhancement: duplicate)

Opened 5 years ago

Last modified 5 years ago

plugin_basename() fix

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

Description

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

  • Version set to 2.2
  • Milestone set to 2.2.2

Dupe of #3002

Leaving open as has patch info.

comment:2   DD325 years ago

Patch added to #3002 using this code.

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

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

Note: See TracTickets for help on using tickets.