Title: wp_is_site_protected_by_basic_auth
Published: February 17, 2021
Last modified: May 20, 2026

---

# wp_is_site_protected_by_basic_auth( string $context = '' ): bool

## In this article

 * [Description](https://developer.wordpress.org/reference/functions/wp_is_site_protected_by_basic_auth/?output_format=md#description)
 * [Parameters](https://developer.wordpress.org/reference/functions/wp_is_site_protected_by_basic_auth/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/functions/wp_is_site_protected_by_basic_auth/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/functions/wp_is_site_protected_by_basic_auth/?output_format=md#source)
 * [Hooks](https://developer.wordpress.org/reference/functions/wp_is_site_protected_by_basic_auth/?output_format=md#hooks)
 * [Related](https://developer.wordpress.org/reference/functions/wp_is_site_protected_by_basic_auth/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/wp_is_site_protected_by_basic_auth/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/functions/wp_is_site_protected_by_basic_auth/?output_format=md#wp--skip-link--target)

Checks if this site is protected by HTTP Basic Auth.

## 󠀁[Description](https://developer.wordpress.org/reference/functions/wp_is_site_protected_by_basic_auth/?output_format=md#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.

## 󠀁[Parameters](https://developer.wordpress.org/reference/functions/wp_is_site_protected_by_basic_auth/?output_format=md#parameters)󠁿

 `$context`stringoptional

The context to check for protection. Accepts `'login'`, `'admin'`, and `'front'`.

Defaults to the current context.

Default:`''`

## 󠀁[Return](https://developer.wordpress.org/reference/functions/wp_is_site_protected_by_basic_auth/?output_format=md#return)󠁿

 bool Whether the site is protected by Basic Auth.

## 󠀁[Source](https://developer.wordpress.org/reference/functions/wp_is_site_protected_by_basic_auth/?output_format=md#source)󠁿

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

[View all references](https://developer.wordpress.org/reference/files/wp-includes/load.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.0/src/wp-includes/load.php#L2025)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.0/src/wp-includes/load.php#L2025-L2049)

## 󠀁[Hooks](https://developer.wordpress.org/reference/functions/wp_is_site_protected_by_basic_auth/?output_format=md#hooks)󠁿

 [apply_filters( ‘wp_is_site_protected_by_basic_auth’, bool $is_protected, string $context )](https://developer.wordpress.org/reference/hooks/wp_is_site_protected_by_basic_auth/)

Filters whether a site is protected by HTTP Basic Auth.

## 󠀁[Related](https://developer.wordpress.org/reference/functions/wp_is_site_protected_by_basic_auth/?output_format=md#related)󠁿

| Uses | Description | 
| [is_admin()](https://developer.wordpress.org/reference/functions/is_admin/)`wp-includes/load.php` |

Determines whether the current request is for an administrative interface page.

  | 
| [apply_filters()](https://developer.wordpress.org/reference/functions/apply_filters/)`wp-includes/plugin.php` |

Calls the callback functions that have been added to a filter hook.

  |

| Used by | Description | 
| [WP_Site_Health::get_tests()](https://developer.wordpress.org/reference/classes/wp_site_health/get_tests/)`wp-admin/includes/class-wp-site-health.php` |

Returns a set of tests that belong to the site status page.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/wp_is_site_protected_by_basic_auth/?output_format=md#changelog)󠁿

| Version | Description | 
| [5.6.1](https://developer.wordpress.org/reference/since/5.6.1/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_is_site_protected_by_basic_auth%2F)
before being able to contribute a note or feedback.