WordPress.org

Make WordPress Core

Opened 4 years ago

Closed 3 years ago

Last modified 3 years ago

#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)

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

Download all attachments as: .zip

Change History (9)

sirzooro4 years ago

comment:1 ryan4 years ago

  • Milestone changed from 2.9 to Future Release

comment:2 scribu3 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.

comment:3 follow-up: sirzooro3 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' ) );

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

}}}

comment:5 sirzooro3 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.

comment:6 scribu3 years ago

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

Feel free; it's a wiki. :)

comment:7 sirzooro3 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.

comment:8 SergeyBiryukov3 years ago

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