wp_is_site_protected_by_basic_auth

函式
wp_is_site_protected_by_basic_auth ( $context = '' )
引數
  • (string) $context The context to check for protection. Accepts 'login', 'admin', and 'front'. Defaults to the current context.
    Required:
    Default: (empty)
返回值
  • (bool) Whether the site is protected by Basic Auth.
定義位置
相關方法
is_protected_ajax_actionwp_is_site_url_using_https_wp_die_process_inputis_protected_endpointis_protected_meta
引入
5.6.1
棄用
-

wp_is_site_protected_by_basic_auth: 這個函式用來檢查WordPress站點是否受到基本認證的保護。如果基本認證被啟用,則返回true,否則返回false。

檢查這個網站是否受到HTTP Basic Auth的保護。

目前,這只是檢查是否存在Basic Auth證書。因此,在與當前上下文不同的情況下呼叫這個函式可能會得到不準確的結果。在未來的版本中,這個評估可能會變得更加強大。

目前,這個功能只被應用密碼使用,以防止衝突,因為它也使用Basic Auth。

function wp_is_site_protected_by_basic_auth( $context = '' ) {
	global $pagenow;

	if ( ! $context ) {
		if ( 'wp-login.php' === $pagenow ) {
			$context = 'login';
		} elseif ( is_admin() ) {
			$context = 'admin';
		} else {
			$context = 'front';
		}
	}

	$is_protected = ! empty( $_SERVER['PHP_AUTH_USER'] ) || ! empty( $_SERVER['PHP_AUTH_PW'] );

	/**
	 * Filters whether a site is protected by HTTP Basic Auth.
	 *
	 * @since 5.6.1
	 *
	 * @param bool $is_protected Whether the site is protected by Basic Auth.
	 * @param string $context    The context to check for protection. One of 'login', 'admin', or 'front'.
	 */
	return apply_filters( 'wp_is_site_protected_by_basic_auth', $is_protected, $context );
}

常見問題

FAQs
檢視更多 >