Burt’s answer on the other thread is Not a hack since it doesn’t touch the core files and works perfectly as a plugin-in or in the /mu-plugins/bp-custom.php file.
Which is the final code? Does it include error message+redirect so the user understands what is going on?
It seems like your not getting any traction with this issue. I understand your need to have a plugin that restricts group access to only those members within a group.
As I mentioned in the thread you referenced above, we are working on an overall privacy component for BuddyPress. What you are seeking will be one of the features of this component.
Perhaps someone will point out an existing plugin that I’m not aware of, or go and create it for you! But, if that does not happen, you at least know that this functionality is in the works.
There are bits of code all over the place + several plugins for “privacy” or “member access”. I’m just trying to get people’s insights in what currently the best solution is.
I had tried a version of the code from the previous thread, but it had some problems in the redirect.
I will try to put something together again as soon as I have time, probably two weeks from now, and will post the result on this thread.
Sometimes I start threads as reminders to myself, issues on my to do list. Hopefully these threads will turn into useful documentation and summaries of solutions.
this is an easy fix to keep non members out.
in you’re header for your member theme..
header(“HTTP/1.1 302 Moved Temporarily”);
header(‘Location: ‘ . get_settings(‘siteurl’) . ‘/wp-signup.php?redirect_to=’ . urlencode($_SERVER[‘REQUEST_URI’]));
header(“Status: 302 Moved Temporarily”);
make sure to put it above the <!DOCTYPE….
But as with the code in the other thread, I still need to figure out how to let the user no what is going on. I’ll get to it later in June…
Perhaps we’ll have some component-based solution in an alpha form by then that you can test out.
The important bit of logic there is the line
if(!is_user_logged_in()… basically saying… if the user is not logged in… do this (i.e. direct to homepage). Could you not simply redirect somewhere else? Better yet… could you not simply hardcode your navigation and wrap some of your navigation with this if statement so they don’t even see the links to groups, etc.. Just thinking out loud here.
@David Lewis, I know. I use something similar a lot in my current site, based on PunBB. I’m not really a coder though, so ‘simply redirect’ will probably require trial and error.
Hardcoding in the navigation is a good suggestion. I could do that in template files, right?
Yah… whichever file has your Home, Blog, Groups, Members etc. navigation. You could maybe just hardcode those links instead of using a buddypress function and then wrap the ones your want hidden with that if statement. Again… I’m just talking off the top of my head. I haven’t actually tried this. I think you might have to do it in a few places though since home uses it’s own theme right? Let us know if you get it working. I’m going to want to do a similar trick (for the time being… until the permissions access component is released).
I just did a quick test. In the home theme at least (wp-content/themes/bphome/header.php) the global nav at the top is already hardcoded. So it’s dead easy to hide the groups and members links simply by wrapping it with this:
<?php if(is_user_logged_in()): ?>
[ links for logged in users only go here ]
<?php endif; ?>
In my template, the “groups” and “members” links appear on lines 48-53.
Note that the last item in the navigation is:
<?php do_action( 'bp_nav_items' ); ?>This function could pulling in more navigation links if you are using any plugins… like bp-events for instance.
That said… I like the solution in this thread much better.
The “solution” above is very “low tech” and in fact, isn’t really a solution since it doesn’t actually restrict access… it just hides some links. Probably not a good way to go. You could probably still get into a group by… let’s say… clicking on someone’s profile link and then clicking on a link to a group they are a member of.