{ $cache[ $media_type ] = (bool) preg_match( '/(^|\s|,)application\/([\w!#\$&-\^\.\+]+\+)?json(\+oembed)?($|\s|;|,)/i', $media_type ); } return $cache[ $media_type ]; } /** * Checks whether current request is an XML request, or is expecting an XML response. * * @since 5.2.0 * * @return bool True if `Accepts` or `Content-Type` headers contain `text/xml` * or one of the related MIME types. False otherwise. */ function wp_is_xml_request() { $accepted = array( 'text/xml', 'application/rss+xml', 'application/atom+xml', 'application/rdf+xml', 'text/xml+oembed', 'application/xml+oembed', ); if ( isset( $_SERVER['HTTP_ACCEPT'] ) ) { foreach ( $accepted as $type ) { if ( str_contains( $_SERVER['HTTP_ACCEPT'], $type ) ) { return true; } } } if ( isset( $_SERVER['CONTENT_TYPE'] ) && in_array( $_SERVER['CONTENT_TYPE'], $accepted, true ) ) { return true; } return false; } /** * Checks if this site is protected by HTTP Basic Auth. * * 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. * * @since 5.6.1 * * @global string $pagenow The filename of the current screen. * * @param string $context The context to check for protection. Accepts 'login', 'admin', and 'front'. * Defaults to the current context. * @return bool Whether the site is protected by 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 ); }