Make WordPress Core

Opened 10 years ago

Closed 10 years ago

Last modified 10 years ago

#6725 closed defect (bug) (wontfix)

$page_hook should not be translated in localized wordpress versions

Reported by: whoismanu Owned by:
Milestone: Priority: normal
Severity: normal Version: 2.5
Component: Administration Keywords: page_hook localization translation admin_print_scripts
Focuses: Cc:


localized version of wordpress like e.g. the french one that can be obtained at http://fr.wordpress.org/ translate page hooks. to me this is bad practice because non localized plugins which use page hooks will no longer work with these localized versions of wordpress (even though they work perfectly fine with the english one).


my plugin used the admin_print_scripts-page_hook hook like this:

add_action('admin_print_scripts-manage_page_whoismanu-photoq', array(&$this,'addHeaderCode'), 1);

this works perfectly fine on the english wp. on the french version however the same page hook is translated to gerer_page_whoismanu-photoq and to work the hook in my plugin would have to be

add_action('admin_print_scripts-gerer_page_whoismanu-photoq', array(&$this,'addHeaderCode'), 1);

this translation is done in fr_FR.po on lines 4642-4646:

#: wp-admin/menu.php:17
#: wp-admin/menu.php:19
#: wp-admin/menu.php:21
msgid "Manage"
msgstr "Gérer"

to see that this what happens, just install the french version of wp and

echo "page hook: " . $page_hook;

in admin-header.php.

now, i cannot account for all possible translations in my plugin so i guess the page hooks should not be translated but be unique. otherwise the admin_print_scripts-page_hook function seems to be quite useless as already stated here: http://trac.wordpress.org/ticket/4563 (this ticket was quite old and closed and seems to describe the same problem. so not sure whether it was never fixed or whether it just resurfaced. as it was closed and old, i.e., not recently opened and closed as the guidelines state, i didn't post there but made a new ticket. sorry if this wasn't the approach to take).

Change History (2)

#1 @whoismanu
10 years ago

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

ok, after a lot of searching and digging i finally found a proper way of doing this. apparently you should never hard code the page_hook part of the admin_print_scripts-page_hook hook. instead use return values that you get when adding menu pages. Example:

// Add a new menu under Manage
$manage = add_management_page(__('Manage PhotoQ', 'PhotoQ'), 'PhotoQ', 8, 'whoismanu-photoq.php', array(&$this, 'manage_page'));
//use the return value as page_hook
add_action('admin_print_scripts-' . $manage, array(&$this, 'addHeaderCode'), 1);

#2 @thee17
10 years ago

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