WC_REST_Authentication::send_unauthorized_headers()publicWC 1.0

If the consumer_key and consumer_secret $_GET parameters are NOT provided and the Basic auth headers are either not present or the consumer secret does not match the consumer key provided, then return the correct Basic headers and an error message.

Method of the class: WC_REST_Authentication{}

No Hooks.




$WC_REST_Authentication = new WC_REST_Authentication();
$WC_REST_Authentication->send_unauthorized_headers( $response );
$response(WP_REST_Response) (required)
Current response being served.

WC_REST_Authentication::send_unauthorized_headers() code WC 7.5.1

public function send_unauthorized_headers( $response ) {
	if ( is_wp_error( $this->get_error() ) && 'basic_auth' === $this->auth_method ) {
		$auth_message = __( 'WooCommerce API. Use a consumer key in the username field and a consumer secret in the password field.', 'woocommerce' );
		$response->header( 'WWW-Authenticate', 'Basic realm="' . $auth_message . '"', true );

	return $response;