Forum Replies Created
-
Hey Ahmed,
Since it’s not a big deal and I’m probably one of the only people that actually cares about this, I’d be happy to try to work on a solution and contribute back to the plugin if I sort it out. Have you been able to reliably reproduce the issue? If so, when does it happen? I’ve tried every platform and browser I can get my hands on and have not been able to produce that problem.
in reply to: Is the "redirect=ok" query string necessary?Oops. I was really close. Made a really silly syntax mistake on my earlier tries. Below is a function that works to redirect all logged out users to the login page. This function assumes that your login and registration urls are in the following format:
http://example.com/login and http://example.com/register.(Note that these slugs are not the default that Userpro produces when it generates pages on install. Register/login pages are set up as children of the “profile” page. For example, http://example.com/profile/login )
Throw the following in your functions.php and you should be good to go…
function please_log_in() {
if ( !is_user_logged_in() && !is_page(array(‘login’, ‘register’)) )
wp_redirect( home_url() . ‘/login’);
}
add_action( ‘template_redirect’, ‘please_log_in’ );You need to do two things. First, if your url structure is different than mine, put your slugs for your register and login pages in an array inside the !is_page() function at the end of line 2. Then add your login page slug for the redirect url where you see ‘/login’ on the 3rd line. It essentially works just like you read it above. If you are not logged in && the current page slug is not /login or /register, redirect to http://example.com/login
If your url structure is the same as mine, no modifications are needed. Just throw it in functions.php and you’re good.
Hope this helps someone.
Cheers!
Jeremy
PS thedeancorp, thanks for the heads up. Probably would have taken a little while to realize that.
in reply to: Redirect users to login if not logged in