Make WordPress Core

Opened 15 years ago

Closed 13 years ago

Last modified 13 years ago

#11007 closed enhancement (worksforme)

plugin_basename() should allow to strip file extension

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

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

Download all attachments as: .zip

Change History (9)

@sirzooro
15 years ago

#1 @ryan
15 years ago

  • Milestone changed from 2.9 to Future Release

#2 @scribu
13 years ago

  • 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.

#3 follow-up: @sirzooro
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 @westi
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 @sirzooro
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 @scribu
13 years ago

It will be good to add some note about this to that page.

Feel free; it's a wiki. :)

#7 @sirzooro
13 years ago

  • 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.

#8 @SergeyBiryukov
13 years ago

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