I would love to have a hint on this too!
I solved it by using a 404 plugin, which allowed me to generate my own 404 page, which then included links to register / login. Not a sollution but a walk around.
ok, bit of code that does redirect but this is via wordpress login- this will be added to my style pack plugin shortly, with some further features, such as bbpress login
//add private forum check
add_action( 'bbp_template_redirect', 'rew_access_if_logged_out', 3 );
function rew_access_if_logged_out(){
$topic_slug = get_option( '_bbp_topic_slug') ;
//quick check if we need to do this function
if (strpos($_SERVER['REQUEST_URI'], $topic_slug) == FALSE) return ;
$login_check=0 ;
$forum_slug = bbp_get_root_slug() ;
//if check is set (ie we prefix forums with the forum slug) then part 1 will be forum slug and part 2 will be topic slug, if not part 1 will be topic slug
$check = bbp_include_root_slug() ;
$link = explode('/',$_SERVER['REQUEST_URI']);
//next we need to topic id (post id) of the topic so we need to check if it is a topic and if so, find the topic id
if (!is_user_logged_in() && $check && $link[1] == $forum_slug && $link[2] == $topic_slug ) {
$post = rew_get_page_by_slug( $link[3], OBJECT, 'topic' );
$topic_id = $post->ID;
$login_check=1 ;
}
elseif (!is_user_logged_in() && empty($check) && $link[1] === $topic_slug) {
$post = rew_get_page_by_slug( $link[2], OBJECT, 'topic' );
$topic_id = $post->ID;
$login_check=1 ;
}
//now we need to check if the topic belongs to a private forum, so can't be seen
if (!empty ($login_check)) {
$forum_id = bbp_get_topic_forum_id($topic_id);
//if forum is private...
if (bbp_get_forum_visibility( $forum_id ) == 'private' ) {
$redirect = home_url() . '/wp-login.php?redirect_to=' . urlencode( $_SERVER['REQUEST_URI'] ); ;
wp_redirect( $redirect );
exit;
}
}
}
function rew_get_page_by_slug($page_slug, $output = OBJECT, $post_type = 'page', $status = 'publish' ) {
global $wpdb;
$page = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_name = %s AND post_type= %s", $page_slug, $post_type) );
if ( $page )
return get_post($page, $output);
return null;
}