插件有一个过滤器drh_allow_rest_api 它确定当前用户是否具有完全访问权限,并且可以跳过白名单检查。默认情况下,这只是is_user_logged_in()
:
/**
* Allow carte blanche access for logged-in users (or allow override via filter)
*
* @return bool
*/
private function allow_rest_api() {
return (bool) apply_filters( \'dra_allow_rest_api\', is_user_logged_in() );
}
因此,如果是外部用户,我们可以挂接它以清除“is\\u user\\u logged\\u in”标志:
function dra_disallow_external_users( $logged_in ) {
if ( $logged_in ) {
$user = wp_get_current_user();
if ( $user && in_array( \'external_user\', $user->roles ) ) {
// Treat external_users as unauthenticated
// i.e. only allow access to whitelisted endpoints.
return false;
}
}
return $logged_in;
}
add_filter( \'dra_allow_rest_api\', \'dra_disallow_external_users\', 10, 1 );