check that you have put the url in correctly – copy from the setting into your browser and check that it works it needs to be the full url
The URL is definitely correct.
Is what I’m trying to achieve standard functionality?
Can you post here what you have put into the setting?
Just trying to redirect to the login page, have tried other URL’s as well.
http://teamtwobees.com/wp-login.php
Click to activate forum visibility is ticked.
Forum visibility is set to ‘Private’
Thanks
Simon
yes for a private forum with visibility that is the expected behaviour.
If the forum is private then it is not seen by non-logged in users, so the logic is that as you don’t expect non-logged in users to know that the forum exists, you wouldn’t want them to know that a topic exists, and login would tell them that they url existed, so they get a 404 in all cases.
Set the forum to public, and the logon screen will appear.
Ok, makes sense. Think I’ve got the hang of it now.
Thanks for your help,
Simon
Great – glad you’re fixed !
I added a link to a private forum in the menu so that a logged in user could easily access the forum. Yes I could add a menu for logged in users, but I decided to instead redirect the not logged in users.
Here is the code I used:
// Redirect private bbPress forum to specific page.
add_action('template_redirect', 'private_content_redirect_to_login', 9);
function private_content_redirect_to_login() {
global $wp_query,$wpdb;
if (is_404()) {
$host = $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
$path = dirname($_SERVER['REQUEST_URI']);
$forums = "forum";
$location = "https://direitoshumanosangola.org/not-logged-in/";
}
if(strpos( $path, $forums ) !== false){
wp_safe_redirect($location);
exit;
}
}
I made a tutorial for it here:
https://www.easywebdesigntutorials.com/hide-buddypress-pages-and-bbpress-forums-from-not-logged-in-users/
that’s great – thanks for posting your solution and a tutorial – that will definitely help others 🙂
hello,
Thanks for the tutorial
Hi this function no longer works in PHP8.1, can you do an update?
It’s complaining about these two lines
if(strpos( $path, $forums ) !== false){
wp_safe_redirect($location);
Hi
Warning: Undefined variable $path in /Applications/MAMP/htdocs/wordpress/wp-content/themes/AHWM-COM/functions.php on line 362
Warning: Undefined variable $forums in /Applications/MAMP/htdocs/wordpress/wp-content/themes/AHWM-COM/functions.php on line 362
Warning: Undefined variable $location in /Applications/MAMP/htdocs/wordpress/wp-content/themes/AHWM-COM/functions.php on line 363
It stops anything else loading the page is just blank other than this message. If I remove the function everything works.
php 8.1 is a lot more fussy
try this (untested but should work)
function private_content_redirect_to_login() {
global $wp_query,$wpdb;
if (is_404()) {
$host = $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
$path = dirname($_SERVER['REQUEST_URI']);
$forums = "forum";
$location = "https://direitoshumanosangola.org/not-logged-in/";
if(strpos( $path, $forums ) !== false){
wp_safe_redirect($location);
exit;
}
}
}
no problem – glad you are fixed 🙂