AI Search
Classic Search
 Search Phrase:
 Search Type:
Advanced search options
 Search in Forums:
 Search in date period:

 Sort Search Results by:

Filter by custom fields

Topic prefix

AI Assistant
Notifications
Clear all

[Solved] Show login page when not logged in, but community page when logged in

6 Posts
2 Users
1 Reactions
463 Views
Posts: 7
Topic starter
Translate
English
Spanish
French
German
Italian
Portuguese
Russian
Chinese
Japanese
Korean
Arabic
Hindi
Dutch
Polish
Turkish
Vietnamese
Thai
Swedish
Danish
Finnish
Norwegian
Czech
Hungarian
Romanian
Greek
Hebrew
Indonesian
Malay
Ukrainian
Bulgarian
Croatian
Slovak
Slovenian
Serbian
Lithuanian
Latvian
Estonian
(@isitjustme)
Active Member
Joined: 7 months ago
[#63607]

I've searched the forums but can't find this specific issue I'm having, apologies if I've missed something obvious.

I am using Ultimate Member for registration and login, all working ok.  I have disabled guest access using the recommended method so users need to be registered and logged in to view the forums, also all working ok.

The issue I have is I can't work out which URL to link to from our main website menu so that if a user is not logged in they see the UM login page (/login), but if they are already logged in they go straight to the /community page.

If going to /community and not logged in, all they see is the forum title, header and footer (no login page).

If going to /login when already logged in, they see their profile name and a couple of links (account and logout).

Is there something clever I can do with redirections to achieve the desired result?


5 Replies
Posts: 7
Topic starter
Translate
English
Spanish
French
German
Italian
Portuguese
Russian
Chinese
Japanese
Korean
Arabic
Hindi
Dutch
Polish
Turkish
Vietnamese
Thai
Swedish
Danish
Finnish
Norwegian
Czech
Hungarian
Romanian
Greek
Hebrew
Indonesian
Malay
Ukrainian
Bulgarian
Croatian
Slovak
Slovenian
Serbian
Lithuanian
Latvian
Estonian
(@isitjustme)
Active Member
Joined: 7 months ago
Reply
4 Replies
Sofy
 Sofy
Admin
(@sofy)
Joined: 8 years ago

Support Team
Posts: 5774
Translate
English
Spanish
French
German
Italian
Portuguese
Russian
Chinese
Japanese
Korean
Arabic
Hindi
Dutch
Polish
Turkish
Vietnamese
Thai
Swedish
Danish
Finnish
Norwegian
Czech
Hungarian
Romanian
Greek
Hebrew
Indonesian
Malay
Ukrainian
Bulgarian
Croatian
Slovak
Slovenian
Serbian
Lithuanian
Latvian
Estonian

@isitjustme 

If guests should not see any forums, please use this hook code:

add_filter('wpforo_after_init_current_object', function ($current_object){
    if( in_array($current_object['template'], array('forum', 'topic')) ){
        if( !WPF()->current_userid ){
	        wp_redirect( wpforo_login_url() );
	        exit();
        }
    }
    return $current_object;
});

Reply
(@isitjustme)
Joined: 7 months ago

Active Member
Posts: 7
Translate
English
Spanish
French
German
Italian
Portuguese
Russian
Chinese
Japanese
Korean
Arabic
Hindi
Dutch
Polish
Turkish
Vietnamese
Thai
Swedish
Danish
Finnish
Norwegian
Czech
Hungarian
Romanian
Greek
Hebrew
Indonesian
Malay
Ukrainian
Bulgarian
Croatian
Slovak
Slovenian
Serbian
Lithuanian
Latvian
Estonian

@sofy I've added this to wpforo/themes/classic/functions.php, is that correct?  (I am using the classic theme).

It doesn't appear to be working.  When I am not logged in and go to /community/ it does not redirect to the login page.  I assume that is what it is supposed to do?


Reply
Sofy
 Sofy
Admin
(@sofy)
Joined: 8 years ago

Support Team
Posts: 5774
Sofy
Translate
English
Spanish
French
German
Italian
Portuguese
Russian
Chinese
Japanese
Korean
Arabic
Hindi
Dutch
Polish
Turkish
Vietnamese
Thai
Swedish
Danish
Finnish
Norwegian
Czech
Hungarian
Romanian
Greek
Hebrew
Indonesian
Malay
Ukrainian
Bulgarian
Croatian
Slovak
Slovenian
Serbian
Lithuanian
Latvian
Estonian

@isitjustme 

You should insert it in the active theme functions.php file. 

Helpful article: https://www.wpbeginner.com/plugins/how-to-easily-add-custom-code-in-wordpress-without-breaking-your-site/


Reply
(@isitjustme)
Joined: 7 months ago

Active Member
Posts: 7
Sofy
Translate
English
Spanish
French
German
Italian
Portuguese
Russian
Chinese
Japanese
Korean
Arabic
Hindi
Dutch
Polish
Turkish
Vietnamese
Thai
Swedish
Danish
Finnish
Norwegian
Czech
Hungarian
Romanian
Greek
Hebrew
Indonesian
Malay
Ukrainian
Bulgarian
Croatian
Slovak
Slovenian
Serbian
Lithuanian
Latvian
Estonian

@sofy Thank you so much, I now have it working.


Reply
Share: