Created
October 9, 2023 17:12
-
-
Save justingreerbbi/c520d0a11090c25d86b5770f92e97046 to your computer and use it in GitHub Desktop.
Check user role before adding an access token
This file contains hidden or 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
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