WordPress.org

Make WordPress Core

Opened 5 years ago

Closed 5 years ago

#31805 closed defect (bug) (duplicate)

network menu page url

Reported by: dll1024 Owned by:
Milestone: Priority: normal
Severity: normal Version: 4.1.1
Component: Networks and Sites Keywords:
Focuses: administration, multisite Cc:

Description

i registered menu in network admin by:

add_action( 'network_admin_menu',...

and now i want to get url of that menu by using

menu_page_url(...

but this function will return blog admin url (invalid url) because in this line:
https://core.trac.wordpress.org/browser/tags/4.1.1/src/wp-admin/includes/plugin.php#L1476
only called admin_url function

i searched for another function, but i found nothing :|

Change History (3)

#1 @needle
5 years ago

I agree - there's definitely a case for updating that function. In the meantime, you can roll your own or use the following which works for me:

function network_menu_page_url($menu_slug, $echo = true) {
	global $_parent_pages;

	if ( isset( $_parent_pages[$menu_slug] ) ) {
		$parent_slug = $_parent_pages[$menu_slug];
		if ( $parent_slug && ! isset( $_parent_pages[$parent_slug] ) ) {
			$url = network_admin_url( add_query_arg( 'page', $menu_slug, $parent_slug ) );
		} else {
			$url = network_admin_url( 'admin.php?page=' . $menu_slug );
		}
	} else {
		$url = '';
	}

	$url = esc_url($url);

	if ( $echo ) echo $url;

	// --<
	return $url;

}

#2 @SergeyBiryukov
5 years ago

  • Component changed from Menus to Networks and Sites

#3 @SergeyBiryukov
5 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed

Duplicate of #28226.

Note: See TracTickets for help on using tickets.