-
First off, amazing job on this plugin! Well worth the price for the amount of time it just saved me. Keep up the good work!
My issue:
Not sure if I’m missing something, but I don’t see a way (within the plugin) to redirect users to the login page if they’re not already logged in. My entire site is private, so this feature is necessary for me. Before using Userpro, I was using the following function to accomplish this:
function please_log_in() {
if ( !is_user_logged_in() )
auth_redirect();
}This now causes a redirect loop because of the redirects created by the plugin. I’ve tried adding a bunch of different scenarios to the conditional, but none seem to completely fix the problem. I know I’m missing something simple here. This is likely possible with very little code. What am I missing?
Any suggestions are greatly appreciated. Thanks again for a great product!
Jeremy
I too am interested in knowing if I can restrict the entire site with this plugin.
PS Jeremy, I’m guessing this question won’t be answered by support until you verify your purchase by saving your envato purchase code in your profile.
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.
Locking an entire site homepage from guests, or entire site is being developed.
This feature is being developed into USERPRO core plugin. 🙂
You must be logged in to reply to this topic.