menu_page_url()获取后台管理菜单网址

目录

描述

Get the url to access a particular menu page based on the slug it was registered with.

If the slug hasn't been registered properly no url will be returned

menu_page_url() 描述

用法

<?php menu_page_url$menu_slug$echo ); ?>

menu_page_url() 用法

参数

$menu_slug

(string) (必填) The slug name to refer to this menu by (should be unique for this menu)

默认值: None

$echo

(boolean) (可选) Whether or not to echo the url - default is true

默认值: 1

menu_page_url() 参数

返回值

(string

the url

menu_page_url() 返回值

历史

添加于 版本: 3.0

menu_page_url() 历史

源文件

menu_page_url() 函数的代码位于 wp-admin/includes/plugin.php

/* ----------------------------------
 * wordpress之魂 © http://wphun.com
 * ---------------------------------- */
/**
 * Get the url to access a particular menu page based on the slug it was registered with.
 *
 * If the slug hasn't been registered properly no url will be returned
 *
 * @since 3.0.0
 *
 * @global array $_parent_pages
 *
 * @param string $menu_slug The slug name to refer to this menu by (should be unique for this menu)
 * @param bool $echo Whether or not to echo the url - default is true
 * @return string the url
 */
function 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 = admin_url( add_query_arg( 'page', $menu_slug, $parent_slug ) );
		} else {
			$url = admin_url( 'admin.php?page=' . $menu_slug );
		}
	} else {
		$url = '';
	}

	$url = esc_url($url);

	if ( $echo )
		echo $url;

	return $url;
}

//
// Pluggable Menu Support -- Private
//

menu_page_url() 源文件

相关