#11007 closed enhancement (worksforme)
plugin_basename() should allow to strip file extension
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Priority: | normal | Milestone: | |
| Component: | Plugins | Version: | 2.8.4 |
| Severity: | normal | Keywords: | has-patch |
| 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)
- 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' ) );
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' );
}}}
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.
It will be good to add some note about this to that page.
Feel free; it's a wiki. :)
- Resolution set to worksforme
- Status changed from new to closed
I have added "Page Hook Suffix" section to the mentioned Codex page. This ticket is no longer needed.
comment:8
SergeyBiryukov — 20 months ago
- Milestone Future Release deleted

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.