WP_Site_Health::get_test_authorization_header() WordPress Method

The WP_Site_Health::get_test_authorization_header() method is used to get the Authorization header for a site health test. This header is used to authenticate the user making the request.

WP_Site_Health::get_test_authorization_header() #

Tests if the Authorization header has the expected values.


Return

(array)


Top ↑

Source

File: wp-admin/includes/class-wp-site-health.php

2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
public function get_test_authorization_header() {
    $result = array(
        'label'       => __( 'The Authorization header is working as expected' ),
        'status'      => 'good',
        'badge'       => array(
            'label' => __( 'Security' ),
            'color' => 'blue',
        ),
        'description' => sprintf(
            '<p>%s</p>',
            __( 'The Authorization header comes from the third-party applications you approve. Without it, those apps cannot connect to your site.' )
        ),
        'actions'     => '',
        'test'        => 'authorization_header',
    );
 
    if ( ! isset( $_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW'] ) ) {
        $result['label'] = __( 'The authorization header is missing' );
    } elseif ( 'user' !== $_SERVER['PHP_AUTH_USER'] || 'pwd' !== $_SERVER['PHP_AUTH_PW'] ) {
        $result['label'] = __( 'The authorization header is invalid' );
    } else {
        return $result;
    }
 
    $result['status'] = 'recommended';
 
    if ( ! function_exists( 'got_mod_rewrite' ) ) {
        require_once ABSPATH . 'wp-admin/includes/misc.php';
    }
 
    if ( got_mod_rewrite() ) {
        $result['actions'] .= sprintf(
            '<p><a href="%s">%s</a></p>',
            esc_url( admin_url( 'options-permalink.php' ) ),
            __( 'Flush permalinks' )
        );
    } else {
        $result['actions'] .= sprintf(
            '<p><a href="%s" target="_blank" rel="noopener">%s <span class="screen-reader-text">%s</span><span aria-hidden="true" class="dashicons dashicons-external"></span></a></p>',
            __( 'Learn how to configure the Authorization header.' ),
            /* translators: Accessibility text. */
            __( '(opens in a new tab)' )
        );
    }
 
    return $result;
}


Top ↑

Changelog

Changelog
VersionDescription
5.6.0Introduced.

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.