• Resolved narekmarkosyan

    (@narekmarkosyan)


    I have Ultimate Member page for users login (they have almost no access) and hidden custom page for administrators.

    But administrators can log in via Ultimate Member login form. So in this case my hidden URL is useless.
    Is it possible to restrict administrators role login via Ultimate Member login page?

Viewing 4 replies - 1 through 4 (of 4 total)
  • @narekmarkosyan

    You can try this code snippet refusing Administrators to Login
    and redirect them to the Home page.

    You can redirect to another page by replacing home_url() with an URL within quotes.

    add_action( 'um_submit_form_errors_hook_login', 'custom_submit_form_errors_hook_login', 10, 1 );
    
    function custom_submit_form_errors_hook_login( $args ) {
    
        if ( UM()->user()->get_role() == 'administrator' ) {
            exit( wp_redirect( home_url() ) );
        }
    }

    Install the code snippet into your active theme’s functions.php file
    or use the “Code Snippets” plugin.

    https://www.ads-software.com/plugins/code-snippets/

    Thread Starter narekmarkosyan

    (@narekmarkosyan)

    Hi @missveronicatv, thank you, it works!

    I changed home_url() with my login page URL. Is it possible to show “wrong password” error after redirect?

    With this code bad guy can’t log in, but he can differ wrong password from right password.

    @narekmarkosyan

    Try this code snippet and you can change the error text if you want.

    add_action( 'um_submit_form_errors_hook_login', 'custom_submit_form_errors_hook_login', 10, 1 );
    
    function custom_submit_form_errors_hook_login( $args ) {
    
        if ( UM()->user()->get_role() == 'administrator' ) {
            UM()->form()->add_error( 'user_email', __( 'Login form restricted', 'ultimate-member' ) );
        }
    }
    Thread Starter narekmarkosyan

    (@narekmarkosyan)

    This is great! Thanks @missveronicatv !

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Restrict login for some role’ is closed to new replies.