#2299 closed defect (bug) (wontfix)
plugin_basename doesn't return plugin_name within a fold in a correct way.
| Reported by: | nielshackius | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | |
| Component: | Administration | Version: | 2.0 |
| Severity: | normal | Keywords: | plugin_basename, plugin, __FILE__, register_activation_hook |
| Cc: | Focuses: |
Description
to add an activation action for your plugin, internally add_action('activate_{pluginname}',$function) is used.
If your plugin is within a folder its name should be: "plugin/starthere.php" so it would be add_action('activate_plugin/starthere.php',$function). Currently, however not a slash, but a backslash is returned by plugin_basename, which breaks register_activation_hook.
Fix could be:
$file= preg_replace('!\\\\+|/+!', '/', $file); //replaces even multiple backlslashes or multiple slashes by a single slash
$file= preg_replace('!^.*wp-content/plugins/!', '', $file); //removes anything before the file name
See also attaced example skript.
Attachments (1)
Change History (2)
Note:
See TracTickets
for help on using tickets.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
ExampleSkript, with different kind of paths-names (even with errors)