[wp-trac] [WordPress Trac] #8196: add_options_page() doesn't return correct hookname with function omitted

WordPress Trac wp-trac at lists.automattic.com
Thu Nov 13 17:23:43 GMT 2008


#8196: add_options_page() doesn't return correct hookname with function omitted
---------------------+------------------------------------------------------
 Reporter:  KingBYU  |       Owner:     
     Type:  defect   |      Status:  new
 Priority:  normal   |   Milestone:  2.8
Component:  Plugins  |     Version:  2.6
 Severity:  normal   |    Keywords:     
---------------------+------------------------------------------------------
 === Description ===
 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.

 === Reference ===
 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
 [http://planetozh.com/blog/go.php?http://planetozh.com/blog/wp-
 content/uploads/2008/06/load-js-example.zip 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:
 {{{
 admin_print_scripts-load-js-example/js_example_opts.php
 }}}

 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.

 === Attachment ===
 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. '''

-- 
Ticket URL: <http://trac.wordpress.org/ticket/8196>
WordPress Trac <http://trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list