Good thinking. Using the logged in status natural to bbPress to do this. Just looking at the code it would work, but I will test this out on my dev forum and report back as well. I could see this expanded into a plugin very easily….
Trent
thanks for this one! nice work.
ps: would be great if the admin could restrict some forums to certain users. would be great if this could be done!
topicQ, you are quite right. The lack of Forum restriction per user I think is a major drawback in bb-Press, but I’m guessing it’s also high up on their list of things to do since all forum applications have it.
Otherwise a plugin could do that but it would have to be extensive.
it would be great if someone could write a plugin…
coz i dont think that there will be an update soon. but who knows…
forum restrictions is really essential for my board.
greetings topiQ
here is the plugin..
please note that the bb hook for initialization was change after the blix release (0.73). it was changed from ‘init’ to ‘bb_init’
function my_check_private_forum($test='') {
global $bb,$bb_current_user;
$login_page = $bb->path . 'bb-login.php';
if ($_SERVER['PHP_SELF'] != $login_page) {
if ( !$bb_current_user ) {
header('Location: ' . $bb->domain . $bb->path . 'bb-login.php');
}
}
}
add_action( 'bb_init', 'my_check_private_forum');
so1o: does this plugin need to be used with the code posted earlier in this thread, or is it standalone?
If it is standalone (ment to function on its own) I am not getting any results. I put the plugin into my-plugins and no results. Everything loads as normal.
Any pointers.
i would think it is standalone..
are you sure you aren’t logged in.. it would redirect the user to login.php if he isnt logged in. if you are logged in it would load normally
also check the bb-settings.php file.. check what is the name of the hook for initialization. as i mentioned the hook name was changed from init to bb-init.
if the bb-settings file has this
do_action('init', '');
then change the last line of the plugin to
add_action( 'init', 'my_check_private_forum');
works now. I mis-read your disclaimer earlier. So those of us using .73 need to change ‘bb-init’ to ‘init’ in the plug-in.
but i find some problem when we long in my forum chases its tail on the login.php form.. do you find that problem?
i think this would be safer option..
function my_check_private_forum() {
global $bb;
$login_page = $bb->path . 'bb-login.php';
if (!bb_is_user_logged_in() && $_SERVER['PHP_SELF'] != $login_page) {
header('Location: ' . $bb->domain . $bb->path . 'bb-login.php');
}
}
add_action( 'bb_init', 'my_check_private_forum');
any thoughts?.. any one?
where do i have to put this code? in the header.php file? and whats the difference between the first post’s code? can you restrict the user group of a forum with this one?!
this is a plugin.. create a something.php in the plugins directory and drop it in there..
the plugin will not restrict user on a forums basis..
So10. That is beautiful! There are 4 or 5 of you that really are rocking and rolling! I will do some research here because really there are about 20-30 plugins now for bbPress bouncing around. I will try and think of a way to get them listed in one place…..
Trent
@so1o: yes thats clear, but what is the difference between your plugin and the one from papercuts3’s first post?!
@trent: as a moderator you should add the new plugins here as there are already some…
https://bbpress.org/plugins/
topicQ: I think the function is exactly the same but my initial post was a working script where you had to make a change in your files, the one so10 sent is an actual plugin, which is a better way of integrating new options.
Thanks for following up on this, we have now a plugin for private forums.
Cheers
ok. now everything works fine…
just one more question:
is it okay if i put the “my_check_private_forum()” in the header.php before the doctype stuff (due to W3C)?!
nothing prevents you from doing that… only thing is tomorrow if you change the template you will have to have this code there too..
if you keep it in a plugin file in the my-plugins dir it will automatically come thru with the new files..
cheers
so with your plugin i dont have to add the “my_check_private_forum()” to the header.php?! if i dont do this it does not work…
please note that the bb hook for initialization was change after the blix release (0.73). it was changed from ‘init’ to ‘bb_init’
check the bb-settings.php file.. check what is the name of the hook for initialization. as i mentioned the hook name was changed from init to bb-init.
if the bb-settings file has this
do_action(‘init’, ”);
then change the last line of the plugin to
add_action( ‘init’, ‘my_check_private_forum’);
@topiQ – I am working on permissions for plugin page, but I still don’t have access to that one yet.
@papercuts – Great work on this.
Trent
@so1o: it works now! do u use a newer release than .73?!
yup.. i use the latest on the repository..
cheers
Would there be a way to exclude certain forums for this plugin as “public” forums or just have a list of “private” forums. Basically, can this be adapted to actually have private forums and topics in that forum that don’t show up unless logged in, but the rest show up all the time?
This has been asked for several times and would be really useful for even myself as I would like to have certain posts only for members!
Trent