Quantcast
Channel: WordPress › Support » Forum: Hacks - Recent Topics
Viewing all articles
Browse latest Browse all 8245

websupporter on "admin_enqueue_scripts hook & internationalization"

$
0
0

Hi everyone,
I am currently struggeling with a small problem. Well, I've coded a workaround, but I am not very happy about it and I would appreciate your thoughts on this.

I am programming a plugin, which supports internationalization. This plugin adds also menus on the Adminpage. For the dashboard I run the following functions:

  • add_menu_page()
  • The action hook "admin_enqueue_scripts"

So, this is what happens:
add_menu_page( __( 'Menu Title', 'textdomain' ), __( 'Menu Title', 'textdomain' ), 'edit_posts', 'slug', 'admin_output_index', SF_URL . 'icon.png', 81 );

I add a menupage with the translateable Title 'Menu Title'. And I add some submenupages.

In order to load my styles and Javascripts only on my menupage und subpages I use the action hook "admin_enqueue_scripts":

add_action( 'admin_enqueue_scripts', 'adminscripts' );
function adminscripts( $hook ){
	if( !in_array( $hook, array( 'toplevel_page_menu-title' ) ) )
		return;
	/* Register Scripts and Styles */
}

The $hook tells me, wether I am on one of my adminpages or not. My hooks are placed in an array. If the hook is not found in this array, my scripts and styles won't load.

I've expected this hook to be stable, but it isn't when it comes to internationalization, because part of the hook derives from the second "add_menu_page"-Parameter:
_( 'Menu Title', 'textdomain' )

So, in the moment, I run this script on another language, the hook changes and my scripts doesn't load. For now, my "workaround" is simply not to translate the second parameter, but this is a rather poor solution.

I am not quite sure, wether I shall call this a "bug" in WordPress or if I do not quite understand the whole "hook"-idea. But, before I now start to open a ticket or report to the core developers, I think its better to discuss this here.

I am quite interested, what you guys think :)

All the best


Viewing all articles
Browse latest Browse all 8245

Trending Articles