Opened 4 years ago

Closed 20 months ago

Last modified 20 months ago

#11007 closed enhancement (worksforme)

plugin_basename() should allow to strip file extension

Reported by: sirzooro Owned by: westi
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)

plugin.php.diff (1.0 KB) - added by sirzooro 4 years ago.

Download all attachments as: .zip

Change History (9)

comment:1   ryan3 years ago

  • Milestone changed from 2.9 to Future Release
  • Keywords reporter-feedback added

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.

comment:3 follow-up: ↓ 4   sirzooro20 months 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' ) );

comment:4 in reply to: ↑ 3   westi20 months 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' );

}}}

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.

  • Milestone Future Release deleted
Note: See TracTickets for help on using tickets.