• Resolved rafaelzrt

    (@rafaelzrt)


    Hello!

    Can I restrict and redirect access of users to the Login Page?

    I followed the tutorial https://docs.ultimatemember.com/article/1620-restriction-content

    But I couldn’t make it work for the Login Page.

    I made a test in a new page and it worked perfectly all the options: restriction to logged in, to logged out, with restriction message or redirect to another URL.

    Is that anything that prevents redirection on this page or is there something I could test? I appreciate any suggestions, thanks.

    My configurations are:

    Settings>Access>Restriction Content
    – Site accessible to everyone
    – Enable the “Content Restriction” settings for post types: Pages

    Login Page:
    – Restrict access to this post? Yes
    – Who can access this post? Logged Out Users
    – What happens when users without access try to view the post? Redirect User
    – Where should users be redirected to? Custom URL (my account page url)

    My Login Page is set to be my UM Login Page and UM Register Page. I want that when logged in users try to access this they are redirected to my account page (or even home).

    Thank you.

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Support Aswin Giri

    (@aswingiri)

    Hello @rafaelzrt

    UM restriction does not work on Login page but you can try following code snippet to make it work:

    add_action('template_redirect',function(){
        global $post;
        if ( um_is_core_page( 'login' ) ) {
            $restriction = get_post_meta( $post->ID, 'um_content_restriction', true );
            if( $restriction ){
                $access = $restriction['_um_custom_access_settings'];
                $accessable = $restriction['_um_accessible'];
                $is_redirect = $restriction['_um_access_redirect'];
                $url = $restriction['_um_access_redirect_url'];
    
                if( $access == 1 && $accessable == 1 && $is_redirect ==1 ){
                    wp_redirect($url);
                    die;
                }
    
            }
        }
    },1001);

    You can add the above code snippets to your theme’s functions.php or you can install “Code Snippets” plugin to add them to your site.

    Thread Starter rafaelzrt

    (@rafaelzrt)

    It worked. Thank you very much.

    Plugin Support Ultimate Member Support

    (@ultimatemembersupport)

    Thanks for letting us know.

    Thread Starter rafaelzrt

    (@rafaelzrt)

    Ops, looks like it didn’t worked properly πŸ™

    I tested more now. It redirects the logged in user properly as set in my configurations in the page, redirecting to a custom url (account page). But now the logged out user is not able to access the login page. ERR_TOO_MANY_REDIRECTS

    I inserted the above code with the plugin Code Snippets and applied it only to the front-end.

    • This reply was modified 3 weeks, 1 day ago by rafaelzrt.
    Plugin Support Ultimate Member Support

    (@ultimatemembersupport)

    Hi @rafaelzrt

    Sorry for the late response. Please try this updated code snippet:

    add_action('template_redirect',function(){
        global $post;
        if ( um_is_core_page( 'login' ) && is_user_logged_in()  ) {
            $restriction = get_post_meta( $post->ID, 'um_content_restriction', true );
            if( $restriction ){
                $access = $restriction['_um_custom_access_settings'];
                $accessable = $restriction['_um_accessible'];
                $is_redirect = $restriction['_um_access_redirect'];
                $url = $restriction['_um_access_redirect_url'];
    
                if( $access == 1 && $accessable == 1 && $is_redirect ==1 ){
                    wp_redirect($url);
                    die;
                }
    
            }
        }
    },1001);
    Thread Starter rafaelzrt

    (@rafaelzrt)

    That worked, thank you very much!

    Perhaps, it could be a feature for future updates for the plugin. Possibility to do normal restrictions to the UM Login page.

    Plugin Support Ultimate Member Support

    (@ultimatemembersupport)

    Hi @rafaelzrt

    Thanks for letting us know. I’ve added this to our feature request list. I’m marking this as resolved now.

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