Make WordPress Core

Opened 11 years ago

Closed 11 years ago

Last modified 5 years ago

#8196 closed defect (bug) (worksforme)

add_options_page() doesn't return correct hookname with function omitted

Reported by: KingBYU Owned by:
Milestone: Priority: normal
Severity: normal Version: 2.6
Component: Plugins Keywords:
Focuses: Cc:
PR Number:



When calling add_options_page() without a function name, the hook name returned doesn't correspond to any hook name that will be called.

The codex docs say that the $function parameter of add_options_page() is optional, and if omitted, then the file specified with the $file parameter should instead be included.


I was following a howto at http://planetozh.com/blog/2008/04/how-to-load-javascript-with-your-wordpress-plugin/ . The howto worked perfectly, until I omitted the function name in favor of a file to be included. I started with the example reference plugin code that Ozh provided in his howto.

My code

I changed the example code that Ozh provided to look like the following:

$options_page = dirname(plugin_basename(__FILE__)).'/js_example_opts.php';
$mypage = add_options_page('Load JS Example', 'Load JS Example', 8, $options_page);
add_action( "admin_print_scripts-$mypage", 'ozh_loadjs_admin_head' );
error_log("added action: admin_print_scripts-$mypage");

In my error log, I found the message:

added action: admin_print_scripts-settings_page_load-js-example/js_example_opts

However, the action/hook that is actually being called when the page loads is:


The action tag created is different than the action tag that is called. (Again, if the function name method is used, the action tags correspond perfectly).

Recommended Action

Fix the get_plugin_page_hookname() function usage (perhaps in the caller) in source:/trunk/wp-admin/includes/plugin.php to return a correct hookname.


I will be attaching an example plugin (a derivative from Ozh's example) that illustrates this bug. When the bug is fixed, the plugin's option page should create a javascript alert (but only on that page).

Thank you very much.

Attachments (1)

load-js-example.zip (1.7 KB) - added by KingBYU 11 years ago.
Example plugin

Download all attachments as: .zip

Change History (3)

11 years ago

Example plugin

#1 @Denis-de-Bernardy
11 years ago

  • Resolution set to worksforme
  • Status changed from new to closed

it returns the correct hook on my end.

#2 @DrewAPicture
5 years ago

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