wp_is_site_protected_by_basic_auth() WordPress Function

The wp_is_site_protected_by_basic_auth() function is used to check whether a WordPress site is protected by Basic Authentication. This function returns a Boolean value (true or false).

wp_is_site_protected_by_basic_auth( string $context = '' ) #

Checks if this site is protected by HTTP Basic Auth.


Description

At the moment, this merely checks for the present of Basic Auth credentials. Therefore, calling this function with a context different from the current context may give inaccurate results. In a future release, this evaluation may be made more robust.

Currently, this is only used by Application Passwords to prevent a conflict since it also utilizes Basic Auth.


Top ↑

Parameters

$context

(string)(Optional)The context to check for protection. Accepts 'login', 'admin', and 'front'. Defaults to the current context.

Default value: ''


Top ↑

Return

(bool) Whether the site is protected by Basic Auth.


Top ↑

Source

File: wp-includes/load.php

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 );
}


Top ↑

Changelog

Changelog
VersionDescription
5.6.1Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.