Members only
-
Hi everyone, my site is done, but I want to add a “members only’ for buddypress pages. members, groups, forums etc.. and have non members sign up to view these pages.
Is there a way to do this?
Ive tried a number of so called members only plugins, but none worked. This may need to be hard coded.
-
Try this:
http://www.primothemes.com/post/s2member-membership-plugin-with-paypal/
s2member allows for both free and paid levels (up to 4), and you can get really creative with what you want to restrict; from simple URIs to custom conditionals, and all the way to a whole bunch of hooks & filters to play with. Oh,and it works just fine with BP. Just be sure to read the documentation… there’s a lot!
Thanks, I did install that and there is a load of info there. Maybe ill work on that and see how it is.
This plug-in works great, however it sends users to the backend login form and not the register page. Can’t figure out how to redirect to register page.
class RegisteredUsersOnly {
var $exclusions = array();
// Class initialization
function RegisteredUsersOnly ()
{
// Register our hooks
add_action( ‘wp’, array(&$this, ‘MaybeRedirect’) );
add_action( ‘init’, array(&$this, ‘LoginFormMessage’) );
add_action( ‘login_head’, array(&$this, ‘NoIndex’), 1 );}
// Depending on conditions, run an authentication check
function MaybeRedirect() {
global $bp;
// If the user is logged in, then abort
if ( current_user_can(‘read’) ) return;if ($bp&&($bp->current_component == BP_REGISTER_SLUG ))//buddypress
return;
#’wp-trackback.php’,
#’wp-app.php’,
$this->exclusions = array(
‘wp-login.php’,
‘wp-signup.php’,
‘wp-register.php’,
‘wp-activate.php’,
‘wp-cron.php’ // Just incase
);
// If the current script name is in the exclusion list, abort
if ( in_array( basename($_SERVER), apply_filters( ‘registered-users-only_exclusions’, $this->exclusions) ) ) return;// Still here? Okay, then redirect to the login form
auth_redirect();
}// Use some deprecate code (yeah, I know) to insert a “You must login” error message to the login form
// If this breaks in the future, oh well, it’s just a pretty message for users
function LoginFormMessage() {
// Don’t show the error message if anything else is going on (registration, etc.)
if ( ‘wp-login.php’ != basename($_SERVER) || !empty($_POST) || ( !empty($_GET) && empty($_GET) ) ) return;global $error;
$error = __( ‘Only registered users can watch this site. Please register or login.’, ‘registered-users-only’ );
}// Tell bots to go away (they shouldn’t index the login form)
function NoIndex() {
echo ” n”;
}}
// Start this plugin once all other plugins are fully loaded
add_action( ‘plugins_loaded’, create_function( ”, ‘global $RegisteredUsersOnly; $RegisteredUsersOnly = new RegisteredUsersOnly();’ ) );@Shnooka30 You really should use s2member. There’s quite a bit to it, but it’s all very well documented and it sounds like it will do exactly what you want it to do.
That code looks like the Registered Users Only 2 plugin.
I made a mod to that plugin awhile ago to better support BP… check it out for some pointers:
http://pastebin.com/x8MpfLW1It doesn’t, There is no way to set the re-direct with s2. I’m looking for my users to go to my site and when they click on members or groups it takes them to /register/ page, not the login.php.
This plug-in doesn’t allow this to happen. Here is a example of of a site that has a similar site as mine. http://sofastop.com/
Sorry, i didnt see that last post, let me try
Sweet, Thanks RAY, that did the trick…
Sorry I misread. I thought you meant “members only” as in paid members. Not just registered members. s2member needs the paid membership and then it will do what you described for paying members.
@techguy….no worries, I appreciate your help. I hope to one day use the paid membership, but that type of membership is a hard sell and very few sites could offer such a tool.
@r-a-y is there any method of testing whether the page concerned is a root component, that is the page lives in the root directory e.g example.com/groups/
reason for asking is as the plugin stands anonymous users only ever see a login page, that can tend to put people off? they may base their decision to join based on what they see going on on the site to that end my preferred approach (or at least a further angle to take in restricting access) is to allow visual access to all top level pages but not deeper into the site.
I had thought that one could check on whether a page is a root component but can’t track that down, I can take various steps to getting closer to this by adding bp_is_front_page() to the :
if (bp_is_register_page() || bp_is_activation_page() || bp_is_front_page() )
and could add is_page(‘wp page’) for blog created pages – although oddly a page created to act as the blog page while setting front page to say ‘activity stream’ doesn’t appear to work??Also of course one can add directory paths to the exclusion array:
$this->exclusions = array(
'wp-login.php',
'wp-signup.php',
'/wp-content/themes/child-theme-name/groups/'
But that isn’t best approach as it fails if one changes themes and child themes override bp-default so one can’t set that if suing child themes.Overall and ideally a check to see if the page/directory/componant lived at root level would seem the best approach.
@hnla – try
bp_is_directory()
on the if(bp_is_register_page() … ) line.@r-a-y thanks, that’s the one. Obvious as soon as I saw it written that allows all top level pages to be viewed but doesn’t allow to further drill down.
@r-a-y great update for the ruo2. question for you.. i have added bp_is_front_page() to the if line.. which allows me to show the Home Page (and the Register Page redirect for everything else).. but i also need to add one more page for non-registered users to view… can i call it out specifically by name or what is the best method?
And how are you creating that page? I gave a clue to how to add a WP Page to the ‘allowed to be viewed’ pages
It’s a page… not a post. Not Buddypress content (not in Groups, Forums, Activity, etc). Just a simple Terms of Use static page that I would also like non-registered people to view.
@cdmmcg – Just add a conditional WP tag to the bp_is_register_page() line.
is_page('your-page-slug')
Thanks – perfect.
Just like I showed, and added exactly for the reason that you asked! Ho Hum . next time I’ll simply ask a question
Hey Ray,
My users are added through another piece of software so I don’t allow registrations on site.
The plugin get caught in a loop obviously since the register page redirects to the front site which is trying to redirect to the register page etc.
I’d like this to redirect to my about page where I will provide a link to the site where they can actually sign up.
I see where to to change this but what would I change it to?
bp_core_redirect(bp_get_signup_page());
Is it just my slug for my page?
Thanks so much.
V
Nevermind,
This worked:
bp_core_redirect(basename($_SERVER).’/about’);
- The topic ‘Members only’ is closed to new replies.