WordPress.org

Support

Support » Plugins and Hacks » Hacks » How to get URL of admin menu item?

How to get URL of admin menu item?

  • Hi there,

    Is there a simple way to get the URL of admin menu items? I’ve grabbed the gobal $menu and $submenu arrays which contain quite a bit of info about each menu item, but digging into menu_header.php, it appears that there’s quite a bit of conditional logic going on behind the scenes to generate basic urls (e.g. /wp-admin/options-general.php?page=easy-custom-templates, or /wp-admin/admin.php?page=wpcf-import-export). Some of the logic, for example, looks like this:

    if ( ! empty( $menu_hook ) || ( ( 'index.php' != $sub_item[2] ) && file_exists( WP_PLUGIN_DIR . "/$sub_file" ) && ! file_exists( ABSPATH . "/wp-admin/$sub_file" ) ) ) {
    	// If admin.php is the current page or if the parent exists as a file in the plugins or admin dir
    	if ( ( ! $admin_is_parent && file_exists( WP_PLUGIN_DIR . "/$menu_file" ) && ! is_dir( WP_PLUGIN_DIR . "/{$item[2]}" ) ) || file_exists( $menu_file ) )
    		$sub_item_url = add_query_arg( array( 'page' => $sub_item[2] ), $item[2] );
    	else
    		$sub_item_url = add_query_arg( array( 'page' => $sub_item[2] ), 'admin.php' );
    
    	$sub_item_url = esc_url( $sub_item_url );
    	echo "<li$class><a href='$sub_item_url'$class>$title</a></li>";
    } else {
    	echo "<li$class><a href='{$sub_item[2]}'$class>$title</a></li>";
    }

    Does anyone know of a simple, reliable way to get admin menu item URLs for use in plugins? Thanks!

Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How to get URL of admin menu item?’ is closed to new replies.
Skip to toolbar