1. 首页
  2. WordPress 函数手册

menu_page_url()

menu_page_url( string $menu_slug, bool $echo = true )

根据注册的slug获取访问特定菜单页的URL。
Get the URL to access a particular menu page based on the slug it was registered with.

目录锚点:#说明#参数#返回#源码


说明(Description)

如果slug没有正确注册,则不会返回URL。


参数(Parameters)

参数 类型 必填 说明
$menu_slug (string) 必需 用于引用此菜单的slug名称(对于此菜单应是唯一的)。
$echo (bool) 可选 是否回显URL。

返回(Return)

(string)菜单页URL。


源码(Source)

/**
 * 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
//
更新版本 源码位置 使用 被使用
3.0.0 wp-admin/includes/plugin.php:1783 0 3

menu_page_url() 为WP2原创文章,链接:https://www.wp2.cn/functions/menu_page_url/

发表评论

您的电子邮箱地址不会被公开。