Simple Membership Plugin › Forums › Simple Membership Plugin › Auto redirect when a user not login
- This topic has 9 replies, 2 voices, and was last updated 9 years, 2 months ago by
mbrsolution.
-
AuthorPosts
-
September 15, 2017 at 11:44 am #11975
hrc
ParticipantI saw this link.
https://simple-membership-plugin.com/auto-redirect-non-logged-in-users-protect-whole-site/But that creates infinity loop in Wp-admin page.
How should I do to avoid WP admin tool loop problem?September 16, 2017 at 5:58 am #11976mbrsolution
ModeratorHi, something else in your site is conflicting with the above function. Can you share what your function looks like?
Thank you
September 16, 2017 at 7:00 am #11977hrc
Participantmbrsolution, Thanks. Here’s my code.
add_filter( 'pre_get_posts', 'swpm_auto_redirect_non_members' ); function swpm_auto_redirect_non_members() { if( !is_admin() && !SwpmMemberUtils::is_member_logged_in() && !is_page( array( 'membership-login', 'membership-join' )) ) { wp_redirect( 'http://example.com/membership-login/' ); exit; } }If you are under published page, it’s OK. But if you are in admin page, it doesn’t work correctly.
September 16, 2017 at 8:31 am #11978mbrsolution
ModeratorJust one question is example.com your actual domain name? Or did you not included for security reasons?
September 16, 2017 at 8:54 pm #11982hrc
ParticipantAh, you’re correct. Actual url is here.
http://lifestyle-supportguide.com/I think it’s plain wprdpress page.
September 16, 2017 at 9:26 pm #11983mbrsolution
ModeratorSo if you add the following URL
http://lifestyle-supportguide.com/membership-loginto your code does it work?September 16, 2017 at 10:55 pm #11984hrc
ParticipantYou mean like this?
add_filter( 'pre_get_posts', 'swpm_auto_redirect_non_members' ); function swpm_auto_redirect_non_members() { if( !is_admin() && !SwpmMemberUtils::is_member_logged_in() && !is_page( array( 'membership-login', 'membership-join' )) ) { wp_redirect( 'http://lifestyle-supportguide.com/membership-login/' ); exit; } }Actually, I did.
But in my administration tool(under /wp-admin), it created infinity loop with “too many redirect”.September 16, 2017 at 11:12 pm #11985mbrsolution
ModeratorHi, I have submitted a message to the plugin developers to investigate further your issue.
Thank you
September 17, 2017 at 12:22 am #11987hrc
ParticipantSo what should I do?
September 17, 2017 at 12:48 am #11988mbrsolution
ModeratorHi, just wait until you hear from the developers. They will reply to this post.
Kind regards
-
AuthorPosts
- You must be logged in to reply to this topic.