• websupporter

    (@websupporter)


    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 2 replies - 1 through 2 (of 2 total)
  • Thread Starter websupporter

    (@websupporter)

    So, the central question I’ve got is the following:

    /wp-admin/includes/plugin.php
    Line 983:
    $admin_page_hooks[$menu_slug] = sanitize_title( $menu_title );

    Why? Why not:
    $admin_page_hooks[$menu_slug] = sanitize_title( $menu_slug);

    I think this would solve my problem. Or does it need to be the internationalizable $menu_title for some reason?

    Thread Starter websupporter

    (@websupporter)

    For everyone, who might be interested, its a reported bug:
    https://core.trac.wordpress.org/ticket/18857

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘admin_enqueue_scripts hook & internationalization’ is closed to new replies.