If you want to disable Magic Login for specific roles instead of disabling it on user level, you can do that with this snippet:
/**
* Disable Magic Login for specific roles
*
* @param null $null default value for shortcircuit
* @param object $user \WP_User object
*
* @return \WP_Error|null
*/
function magic_login_maybe_disabled_for_role( $null, $user ) {
if ( ! is_a( $user, '\WP_User' ) ) {
return $null;
}
$roles_to_disable = ['administrator', 'editor', 'author'];
foreach ( $roles_to_disable as $role ) {
if ( in_array( $role, $user->roles ) ) {
return new \WP_Error( 'magic_login_disabled_role', esc_html__( 'Magic login is not allowed for your role!', 'magic-login' ) );
}
}
return $null;
}
add_filter( 'magic_login_pre_send_login_link', __NAMESPACE__ . '\\magic_login_maybe_disabled_for_role', 20, 2 );
In this example, Magic Login will be disabled for admin, editor and author roles.