Last active
November 4, 2016 12:43
-
-
Save mtrl/0c873a0560f68b94452f86c643ccf90b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Check for the existence of a header authentication token before dispatching any data | |
add_filter( 'rest_pre_dispatch', function() { | |
$requestPath = $_SERVER['REQUEST_URI']; | |
if($requestPath != '/wp-json/jwt-auth/v1/token') { | |
$tokenValidationResponse = apply_filters('validate_token', null); | |
if(gettype($tokenValidationResponse) == 'object' && get_class($tokenValidationResponse) == "WP_Error") { | |
foreach($tokenValidationResponse->error_data as $key => $error) { | |
$status = $error['status']; | |
$msg = $key; | |
}; | |
return array( | |
'error' => array( | |
'msg' => $msg, | |
'code' => $status, | |
)); | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment