llms_rest_authorization_required_error( string $message = '', boolean $check_authenticated = true )

Return a WP_Error with proper code, message and status for unauthorized requests.


Parameters Parameters

$message

(string) (Optional) The custom error message. When no custom message is provided a predefined message will be used.

Default value: ''

$check_authenticated

(boolean) (Optional) Whether or not checking if the current user is logged in. Default true.

Default value: true


Top ↑

Return Return

(WP_Error)


Top ↑

Source Source

File: libraries/lifterlms-rest/includes/server/llms-rest-server-functions.php

function llms_rest_authorization_required_error( $message = '', $check_authenticated = true ) {
	if ( $check_authenticated && is_user_logged_in() ) {
		// 403.
		$error_code = 'llms_rest_forbidden_request';
		$_message   = __( 'You are not authorized to perform this request.', 'lifterlms' );
		$status     = WP_Http::FORBIDDEN; // 403.
	} else {
		// 401.
		$error_code = 'llms_rest_unauthorized_request';
		$_message   = __( 'The API credentials were invalid.', 'lifterlms' );
		$status     = WP_Http::UNAUTHORIZED; // 401.
	}

	$message = ! $message ? $_message : $message;
	return new WP_Error( $error_code, $message, array( 'status' => $status ) );
}


Top ↑

Changelog Changelog

Changelog
Version Description
1.0.0-beta.18 Use WP_Http constants for the error status.
1.0.0-beta.12 Added a second paramater to avoid checking if the user is logged in.
1.0.0-beta.1 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.