The Community forums are being phased out in favor of a new Slack group.
Add your email address below to get an invitation to join the community slack group
Redirect Users to Login Page
Hi everyone!
I created a form that is limited to login users only. Is there a way to redirect the user to the login/register page instead of showing the "You do not have permission to view this form." ?
TIA!
July 16, 2017 at 4:33 am
There are a few ways to prohibit users from accessing content not meant for them. In a general sense, content that is meant for logged in users shouldn't even be shown to casual visitors. You can hide the menu item with CSS. When a person logs in, WordPress adds a class to the body tag named logged-in. You can leverage this class to hide things, For a menu item, add a class to the menu item in the menu builder called menu-item-hide. Then add the following CSS to your style sheet:
.menu-item-hide {
display: none;
}
.logged-in .menu-item-hide {
display: inline-block;
}
The menu item for the form will be hidden for the casual visitor and visible for the logged in user.
You could also use a membership plugin like S2Member to provide logged-in user only content.
Last, if you want casual visitors to see the form menu item, but then be redirected, you can do this with jQuery added to the page the form is on. The jQuery won't work if you add it to the form itself, but if you execute as soon as the page is accessed, you can redirect. Hope this helps.
July 16, 2017 at 4:38 am
Thanks for the tips!
July 16, 2017 at 10:14 am
Another approach is to use the "My Private Site" plugin
Discussion closed.