I am in process of writing a plugin that has front-end shortcodes that display a user’s information/data. If the user is not logged in, I need to redirect to a front-end login page/form. What would be the best practice here? My plugin creates the pages that I use as well as add the shortcodes to those pages. So, if there is a way to “protect” those pages I would love to know.
2 comments
Comments are closed.
Not sure about the best practices, but I have a few custom login-sensitive pages which simply display a message if user is not logged and is trying to view the page directly:
Note: both the
login
andregister
pages are custom pages as well.You can’t redirect users from a shortcode. Shortcodes run too late– well after content has been sent. But given that your plugin is creating the Pages you should be able to do this: