Skip Navigation

[Resolved] Redirect from limited content to Login form

This support ticket is created 6 years, 9 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 24 replies, has 2 voices.

Last updated by JanP6468 6 years, 9 months ago.

Assisted by: Shane.

Author
Posts
#613850

Tell us what you are trying to do?
Trying to redirect users who attempt accessing limited content ("My Account" page) to Login page.

Is there any documentation that you are following?
https://toolset.com/documentation/user-guides/cred-training-course/part-7-building-account-page-login-form/#setting-the-login-form-layout-to-appear-on-the-my-account-page-for-visitors

This one. Unlike in the step 5. of the manual, I cannot select the option "Show Template Layout" (most probably because I am not using Layouts but Beaver Builder).

Is there a similar example that we can see?

What is the link to your site?

#613913

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Jan,

Thank you for contacting our support forum.

Instead of a page template option, you should see the option to display a content template instead.

Please let me know and what are the options you are seeing.

Thanks,
Shane

#614148
screnshot 6.jpg

Hi Shane,

That I indeed do see, but what do I do with that? There is no option of redirecting to Login page as in the manual (see the screenshot).

#614322

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Jan,

What you need to do is to create a login page template by going to Views -> Content template and then adding the shortcode for the login page.
https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-login-form

Please let me know if this helps.
Thanks,
Shane

#614384

Hi Shane,

That kind of works, but only enables editing of the content layout, not a full page, meaning the Login page the unregistered users are "redirected to" is very poorly looking.

What I need is a simple redirect to the login page which I already designed. Is that possible, please?

Thank you,

Jan

#614419

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Jan,

The only other alternative I can think of is to either use our Layouts plugin to create the login page template or check the user's permissions in your page template and then redirect them using php if they have no access to that particular page.

Please let me know which solution you want to try then we can proceed from there.

Thanks,
Shane

#614567

One more thing to add: as I had the settings you recommended set up (login form content template), page builder was running crazy because I was using "page builder content template within page builder content template" - and none of the existent pages loaded correctly (!). This problem auto-fixed itself when I deleted the Login form content template. (Got me really scared there for a second, haha.)

That said, I am afraid that the Layouts would be conflicting with page builder eventually creating design/administrative mess, and as much as I honestly love Toolset and all your plugins, I still prefer page builder for the layout editing. Additionally, I think the php solution is also more elegant, cutting right to the chase - and hopefully, it won't be too complicated for this (seemingly simple) redirect.

However, my knowledge of PHP is literally 0, so if you could help me with it, I would really appreciate it! 🙂

Thank you for your help,

Jan

#614659

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Jan,

I can attempt to assist with this but I would need to look at your site and the page that you don't want your guests to have access to.

The Private fields will be enabled for your next response.

Thanks,
Shane

#615675

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Jan,

This is a live site correct?

Would you mind if I installed the duplicator plugin in order to create a copy so that I can perform the tests ?

Thanks,
Shane

#615676

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Alternatively you could add this to your functions.php

add_action( 'template_redirect', 'redirect_to_specific_page' );

function redirect_to_specific_page() {

if ( is_page('slug') && ! is_user_logged_in() ) {

wp_redirect( '<em><u>hidden link</u></em>', 301 ); 
  exit;
    }
}

What you need to do is provide the slug of the page you want to redirect the user from and then place the link of the page you want them to redirect to in the wp_redirect function.

In your case the is_page() function should be is_page('my-account')

#615683

Hi Shane,

In case there is a more elegant solution than adding code for each page that needs to be redirected (there are more pages limited to "registered biker" user role), it would be great.

I think it is fine if you install a duplicator and create a copy for testing, as long as you treat it with absolute confidentiality and delete the copy and any backdoor access afterwards.

Thank you,

Jan

#615769

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Jan,

Actually this was the most suitable solution I could think of. The other was to add a condition to the template file itself.

However you can create an array of ID's for the pages you want to do this for and it will apply .

Example

add_action( 'template_redirect', 'redirect_to_specific_page' );
 
function redirect_to_specific_page() {
$arr = array(1,2,3,4,5,6);
 
if ( is_page($arr) && ! is_user_logged_in() ) {
 
wp_redirect( '<em><u>hidden link</u></em>', 301 ); 
  exit;
    }
}

Where 1,2,3,4,5,6 is the individual ID of each page.

Please let me know if this helps.
Thanks,
Shane

#616709

Hi Shane,

Where exactly should I put this code, please?

Also, new problems arose. I'm not sure if you did any changes in the Access Control or how this broke, but now the "Registered bikers content" custom post group doesn't work and even guests can see the limited content. Also, post and user forms in this logged-in environment do not work now, although I didn't change any Access settings and "Registered bikers" (custom role) should be able to change "Bikes" (custom post type).

In other words, hell is breaking loose, I have no clue why, and am getting a bit desperate.

#616814

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Jan,

I didn't make any change to your website at all since I saw that it was a live site.

The function should be added to your functions.php file, remember to change the 1,2,3,4,5,6 to the ID of the posts you want to redirect guests from.

Were there any plugins installed on your site or any updates made as this could have caused the issue ?

Please let me know.
Thanks,
Shane

#616848

No new plugins were installed since it stopped working. Changes were made, but not any that would influence this functionality. The setup looks exactly the same as it did - from an amateur's perspective it should work, I have no clue how guests are able to access the pages, and even the "My Account" sub-item in the top menu (below Bike Register) doesn't show, meaning the setup is probably well done.