domain_exists

函式
domain_exists ( $domain, $path, $network_id = 1 )
引數
  • (string) $domain The domain to be checked.
    Required:
  • (string) $path The path to be checked.
    Required:
  • (int) $network_id Optional. Network ID. Relevant only on multi-network installations.
    Required:
    Default: 1
返回值
  • (int|null) The site ID if the site name exists, null otherwise.
定義位置
相關方法
email_existscomment_existstag_existsterm_existspost_exists
引入
-
棄用
-

domain_exists: 這是一個WordPress函式,用來檢查資料庫中是否存在一個域: 這個函式可以用來檢查一個特定的域名是否已經在WordPress多站點網路中註冊。

檢查一個網站名稱是否已經被佔用。

該名稱是網站的子域或網站的子目錄路徑,取決於網路設定。

在新網站註冊過程中使用,以確保每個網站名稱是唯一的。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function domain_exists( $domain, $path, $network_id = 1 ) {
$path = trailingslashit( $path );
$args = array(
'network_id' => $network_id,
'domain' => $domain,
'path' => $path,
'fields' => 'ids',
'number' => 1,
'update_site_meta_cache' => false,
);
$result = get_sites( $args );
$result = array_shift( $result );
/**
* Filters whether a site name is taken.
*
* The name is the site's subdomain or the site's subdirectory
* path depending on the network settings.
*
* @since 3.5.0
*
* @param int|null $result The site ID if the site name exists, null otherwise.
* @param string $domain Domain to be checked.
* @param string $path Path to be checked.
* @param int $network_id Network ID. Relevant only on multi-network installations.
*/
return apply_filters( 'domain_exists', $result, $domain, $path, $network_id );
}
function domain_exists( $domain, $path, $network_id = 1 ) { $path = trailingslashit( $path ); $args = array( 'network_id' => $network_id, 'domain' => $domain, 'path' => $path, 'fields' => 'ids', 'number' => 1, 'update_site_meta_cache' => false, ); $result = get_sites( $args ); $result = array_shift( $result ); /** * Filters whether a site name is taken. * * The name is the site's subdomain or the site's subdirectory * path depending on the network settings. * * @since 3.5.0 * * @param int|null $result The site ID if the site name exists, null otherwise. * @param string $domain Domain to be checked. * @param string $path Path to be checked. * @param int $network_id Network ID. Relevant only on multi-network installations. */ return apply_filters( 'domain_exists', $result, $domain, $path, $network_id ); }
function domain_exists( $domain, $path, $network_id = 1 ) {
	$path   = trailingslashit( $path );
	$args   = array(
		'network_id'             => $network_id,
		'domain'                 => $domain,
		'path'                   => $path,
		'fields'                 => 'ids',
		'number'                 => 1,
		'update_site_meta_cache' => false,
	);
	$result = get_sites( $args );
	$result = array_shift( $result );

	/**
	 * Filters whether a site name is taken.
	 *
	 * The name is the site's subdomain or the site's subdirectory
	 * path depending on the network settings.
	 *
	 * @since 3.5.0
	 *
	 * @param int|null $result     The site ID if the site name exists, null otherwise.
	 * @param string   $domain     Domain to be checked.
	 * @param string   $path       Path to be checked.
	 * @param int      $network_id Network ID. Relevant only on multi-network installations.
	 */
	return apply_filters( 'domain_exists', $result, $domain, $path, $network_id );
}

常見問題

FAQs
檢視更多 >