network_site_url

函数
network_site_url ( $path = '', $scheme = null )
参数
  • (string) $path Optional. Path relative to the site URL. Default empty.
    Required:
    Default: (empty)
  • (string|null) $scheme Optional. Scheme to give the site URL context. Accepts 'http', 'https', or 'relative'. Default null.
    Required:
    Default: null
返回值
  • (string) Site URL link with optional path appended.
相关
  • set_url_scheme()
定义位置
相关方法
network_home_urlget_site_urlnetwork_admin_urlnetwork_step1network_step2
引入
3.0.0
弃用
-

network_site_url: 这个函数返回网络的网站URL。它需要一个可选的参数,用于将路径附加到网站的URL上。

检索当前网络的网站URL。

返回带有适当协议的网站URL,如果is_ssl()则为’https’,否则为’http’。如果$scheme是’http’或’https’,is_ssl()被覆盖。

function network_site_url( $path = '', $scheme = null ) {
	if ( ! is_multisite() ) {
		return site_url( $path, $scheme );
	}

	$current_network = get_network();

	if ( 'relative' === $scheme ) {
		$url = $current_network->path;
	} else {
		$url = set_url_scheme( 'http://' . $current_network->domain . $current_network->path, $scheme );
	}

	if ( $path && is_string( $path ) ) {
		$url .= ltrim( $path, '/' );
	}

	/**
	 * Filters the network site URL.
	 *
	 * @since 3.0.0
	 *
	 * @param string      $url    The complete network site URL including scheme and path.
	 * @param string      $path   Path relative to the network site URL. Blank string if
	 *                            no path is specified.
	 * @param string|null $scheme Scheme to give the URL context. Accepts 'http', 'https',
	 *                            'relative' or null.
	 */
	return apply_filters( 'network_site_url', $url, $path, $scheme );
}

常见问题

FAQs
查看更多 >