Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save justingreerbbi/c520d0a11090c25d86b5770f92e97046 to your computer and use it in GitHub Desktop.
Save justingreerbbi/c520d0a11090c25d86b5770f92e97046 to your computer and use it in GitHub Desktop.
Check user role before adding an access token
add_action('wo_set_access_token', 'check_user_before_auth');
function check_user_before_auth( $info ) {
if ( ! isset( $info['user_id'] ) ) {
return;
}
$user_id = $info['user_id'];
// Do query to checl the
$user = get_user_by( 'ID', $user_id );
if ( in_array( 'subscriber', (array) $user->roles ) ) {
wp_send_json( array(
'status' => false,
'error_description' => 'User not allowed'
), 400 );
exit;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment