Support » Plugin: Passwordless Login » Add filter to allow/disallow certain users/roles from using this feature

  • Resolved lucasbustamante

    (@lucasbustamante)


    I would like to ask for a filter that allows me to restrict this feature to certain roles/users. For instance: Disallow users with the “administrator” role from using this feature.

    As a suggestion, I have adapted the wpa_valid_account function with such filter:

    
    /**
     * Checks to see if an account is valid. Either email or username
     *
     * @since v.1.0
     *
     * @return bool | WP_Error
     */
    function wpa_valid_account( $account ){
    	if( is_email( $account ) ) {
    		$get_by = 'email';
    		$account = sanitize_email( $account );
    	} else {
    		$get_by = 'login';
    		$account = sanitize_user( $account );
    	}
    
    	$user = get_user_by( $get_by, $account );
    	
    	if ( $user instanceof \WP_User ) {
    	    $user_allowed = apply_filters( 'passwordless_login/is_user_allowed', true, $user );
    	    
    	    if ( $user_allowed ) {
    		    return $user->data->user_email;
            }
        }
    
    	return new WP_Error( 'invalid_account', __( 'The username or email you provided do not exist. Please try again.', 'passwordless-login' ) );
    }
    

    Thank you

Viewing 1 replies (of 1 total)
  • Plugin Author Cristian Antohe

    (@sareiodata)

    Hi,

    Thank you for recommending this. We’re probably not going to implement this right away so it’s best to just modify the plugin to your needs. Just make sure you change the version number to something like 9999.

    It’s a fairly simple plugin that you can maintain changes to it if needed. We don’t have plans for extending the functionality in the near future. We’re just maintaining it so it works with new version of PHP and WordPress.

Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.