network_home_url

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

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

检索当前网络的主页URL。

返回带有适当协议的主页URL,’https’是_ssl(),否则是’http’。如果`$scheme`是’http’或’https’,`is_ssl()’将被重写。

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

	$current_network = get_network();
	$orig_scheme     = $scheme;

	if ( ! in_array( $scheme, array( 'http', 'https', 'relative' ), true ) ) {
		$scheme = is_ssl() ? 'https' : 'http';
	}

	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 home URL.
	 *
	 * @since 3.0.0
	 *
	 * @param string      $url         The complete network home URL including scheme and path.
	 * @param string      $path        Path relative to the network home URL. Blank string
	 *                                 if no path is specified.
	 * @param string|null $orig_scheme Scheme to give the URL context. Accepts 'http', 'https',
	 *                                 'relative' or null.
	 */
	return apply_filters( 'network_home_url', $url, $path, $orig_scheme );
}

常见问题

FAQs
查看更多 >