函数文档

get_clean_basedomain()

💡 云策文档标注

概述

get_clean_basedomain() 函数用于获取网络的基础域名,通过检查现有网络或从站点URL中提取。

关键要点

  • 函数返回字符串类型的基础域名
  • 优先使用 network_domain_check() 检查现有网络域名
  • 若无现有网络,则从 get_option('siteurl') 中提取并清理域名
  • 使用正则表达式移除协议前缀,并处理可能的路径部分

代码示例

function get_clean_basedomain() {
	$existing_domain = network_domain_check();
	if ( $existing_domain ) {
		return $existing_domain;
	}
	$domain = preg_replace( '|https?://|', '', get_option( 'siteurl' ) );
	$slash  = strpos( $domain, '/' );
	if ( $slash ) {
		$domain = substr( $domain, 0, $slash );
	}
	return $domain;
}

注意事项

  • 函数在 WordPress 3.0.0 版本引入
  • 相关函数包括 network_domain_check() 和 get_option()
  • 被 network_step1() 和 network_step2() 用于网络安装过程

📄 原文内容

Get base domain of network.

Return

string Base domain.

Source

function get_clean_basedomain() {
	$existing_domain = network_domain_check();
	if ( $existing_domain ) {
		return $existing_domain;
	}
	$domain = preg_replace( '|https?://|', '', get_option( 'siteurl' ) );
	$slash  = strpos( $domain, '/' );
	if ( $slash ) {
		$domain = substr( $domain, 0, $slash );
	}
	return $domain;
}

Changelog

Version Description
3.0.0 Introduced.