#11007 closed enhancement (worksforme)
plugin_basename() should allow to strip file extension
Reported by: | sirzooro | Owned by: | westi |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 2.8.4 |
Component: | Plugins | Keywords: | has-patch |
Focuses: | Cc: |
Description
Some WP hooks includes plugin basename as a part of their name, but there is an inconsistency - some of them uses it with extension (usually .php), some without it. Therefore it will be good to extend plugin_basename() to return name with or without extension. Attached path does this.
Attachments (1)
Change History (9)
#3
follow-up:
↓ 4
@
13 years ago
- Keywords reporter-feedback removed
I know about one case (wp-admin/admin.php:147):
do_action('load-' . $page_hook);
In order to use it for my plugin's setting page I had to use following code:
add_action( 'load-settings_page_'.substr( plugin_basename( __FILE__ ), 0, -4 ), array( &$this, 'load_settings_page' ) );
#4
in reply to:
↑ 3
@
13 years ago
Replying to sirzooro:
I know about one case (wp-admin/admin.php:147):
do_action('load-' . $page_hook);
In order to use it for my plugin's setting page I had to use following code:
add_action( 'load-settings_page_'.substr( plugin_basename( __FILE__ ), 0, -4 ), array( &$this, 'load_settings_page' ) );
Why can't you just do this:
$my_plugin_page_hook = add_options_page( ... ); add_action( 'load-' . $my_plugin_page_hook , 'my_load_function' );
}}}
#5
@
13 years ago
Good to know - I was not aware that add_options_page()
returns appropriate page hook.
As I checked now, this is documented in description of add_options_page()
in code and on Codex. However this is not mentioned on Administration Menus Codex page - as I recall, I used that page to learn how to write plugins. It will be good to add some note about this to that page.
#6
@
13 years ago
It will be good to add some note about this to that page.
Feel free; it's a wiki. :)
Could you point to those hooks that don't include the extension?
I'm asking because I don't see how adding a parameter to plugin_basename() would help fix this inconsistency.