Skip to:
Content
Pages
Categories
Search
Top
Bottom

How to make a private community?


  • nipponmonkey
    Member

    @nipponmonkey

    Hi I’m quite new to WP and BP and would like to know the best way to make a private community.

    Basically, I’d like:

    • non members should only see a login/home page with no registration options.
    • non members can not see any posts, usernames or anything else related to the community.
    • all new members can only be created by admin.
    • all logged in members have full posting rights.

    Is this easily achieved? And what’s the simplest approach?

    Cheers

Viewing 25 replies - 76 through 100 (of 104 total)

  • Josh Frank
    Participant

    @iamjoshfrank

    Wanted to say thank you and put in my endorsement for @Travel-Junkie ‘s great, simple privacy solution.

    Re-posting that code below for simplicity’s sake, found at this comment link:
    https://buddypress.org/community/groups/how-to-and-troubleshooting/forum/topic/how-to-make-a-private-community/?topic_page=2&num=15#post-44616

    Running WP 3.0.1 single-site with BuddyPress 1.2.5.2.

    Add to functions.php (may be titled Theme Functions in your Dashboard Theme Editor):

    function sh_walled_garden()
    {
    global $bp;

    if( bp_is_register_page() || bp_is_activation_page() )
    return;

    if( ! bp_is_blog_page() && ! is_user_logged_in() )
    bp_core_redirect( $bp->root_domain .’/’. BP_REGISTER_SLUG );
    }
    add_action( ‘get_header’, ‘sh_walled_garden’ );


    nipponmonkey
    Member

    @nipponmonkey

    Hi, I’m the person who started this thread about 5 months ago!

    I’ve been messing around with my own solution for a while now, and I’ve created my first couple of WP/BP plugins recently.

    In fact, I’ve just released my BuddyPress Private Community Plugin:
    https://buddypress.org/community/groups/buddypress-private-community/

    Somebody has already given it 5 stars!

    It’s basically a single static class that has a few customizable settings, you can block RSS feeds, stop widgets from displaying when the user is logged out, and set an array of pages that are public. Of course you can set the redirect page when I logged out user tries to access a private page too. It defaults to the home page, but I suggest you change that in the config.

    There is an example of how to create your own config file for the plugin, one that is saved in a place that won’t be overwritten when you update the plugin and that doesn’t require database access – so it should be a lightweight and quick plugin.

    It’s been working great for me, let me know what you think and if you find any bugs!


    gpo1
    Participant

    @gpo1

    It killed my site this plugin


    nipponmonkey
    Member

    @nipponmonkey

    @Gpo1, what happened?

    Could you give your feedback in the plugin’s forum:
    https://buddypress.org/community/groups/buddypress-private-community/forum/

    The general response has been good so far, it seems to be working fine for everyone else, so I’d be interested to know what’s going wrong for you.

    Did you get an error message?


    nipponmonkey
    Member

    @nipponmonkey

    I’ve now added greater support for allowing access to your site. In the array of allowed URIs, you can now use ‘*’ at the end of an allowed URI,

    e.g. Array(‘/public-blog’, ‘/public-blog/*’) would allow access to ‘/public-blog/post-1’, ‘/public-blog/post-2’, etc…

    This is useful for allowing greater access to your site while keeping it private, and for allowing access to parts of your site that certain other plugins might require.

    See FAQs for more information:
    https://buddypress.org/community/groups/buddypress-private-community/home/


    spinhead
    Participant

    @spinhead

    I’ve also had problems; posted my issue on the plugin’s forum.


    nipponmonkey
    Member

    @nipponmonkey

    @spinhead, the problem seems to be because your blog isn’t in the root domain. I think you need to change the config file a little to get it working. See my reply:
    https://buddypress.org/community/groups/buddypress-private-community/forum/topic/redirect-hell/

    @Travel-Junkie and @iamjoshfrank I’ve just implemented your ‘sh walled garden’ code to shield my community pages from prying eyes, and it works great.

    I was wondering however if you knew a way I could make an exception for the BuddyPress Links Directory (it’s a plugin, so there is no kind of conditional tag for this, as far as I know).

    Any help would be greatly appreciated.


    Boris
    Participant

    @travel-junkie

    Well, just add that page to the first if statement in the function. Something like this:

    `function sh_walled_garden()
    {
    global $bp;

    if( bp_is_register_page() || bp_is_activation_page() || $bp->is_directory && $bp->current_component == ‘your-links-directory-slug’ )
    return;

    if( ! bp_is_blog_page() && ! is_user_logged_in() )
    bp_core_redirect( $bp->root_domain .’/’. BP_REGISTER_SLUG );
    }
    add_action( ‘get_header’, ‘sh_walled_garden’ );`


    pcwriter
    Participant

    @pcwriter

    @travel-junkie

    Shouldn’t that line be:

    `if( bp_is_register_page() || bp_is_activation_page() || ($bp->is_directory && $bp->current_component == ‘your-links-directory-slug’) )`

    The added param should be between parentheses ‘cuz the “&&” applies only to the “is_directory”, no?


    Boris
    Participant

    @travel-junkie

    Nope, doesn’t matter in this case, cause the && gets tested before the ||, but you can use parentheses. Doesn’t hurt.

    Thanks guys, thanks to @Travel-Junkie ‘s code, I am now able to make an exception for the Links Directory, based on the ‘links’ slug.

    However, I’ve now also been asked if we can’t get the individual link page (www.website.tld/links/…) to be an exception too… Can I count on you again?


    Boris
    Participant

    @travel-junkie

    Deleting `$bp->is_directory &&` from the line above should do it. That means that all the links that have the links directory slug in the URL are excluded.

    Thanks, that did the trick!


    ABomb1977
    Member

    @abomb1977

    @Travel-Junkie

    I absolutely adore this code you’ve posted. It’s clean and easy to install, and there’s no extraneous junk that needs to be done. A simple copy/paste does the trick amazingly well for me.

    But here’s a question:

    I know that
    `if( bp_is_register_page() || bp_is_activation_page() )’
    is where I add slugs that make particular pages available to the public.

    I’m also using the bp-xtra-signup, which I think you contributed to. On my registration page, there’s a checkbox to check that says one agrees to the site TOS, but one has to open a link to see the TOS. When that link is clicked, it redirects to the front page of the site that logged out users are redirected to.

    I’m wondering two things: (1) I haven’t made a TOS page, so where is it? Does one come with that plugin? (Cause I have yet to find it. LOL) and (2) Where do I get that slug to add to the visible pages code line?

    Thanks!
    ABomb


    Boris
    Participant

    @travel-junkie

    @abomb1977
    You’ll have to create that TOS page yourself. It’ll be a normal WP page. Then you can exclude that page like this:
    `is_page(23)`

    23 in this case is the id of the page, so substitute with the proper id. You can use the page slug as well instead of the id.


    ABomb1977
    Member

    @abomb1977

    @travel-junkie

    Thanks heaps!
    The only issue is that if I add
    `is_page(slug)` or `bp_is_page(slug)`
    it makes everything visible again.

    Any ideas?


    Boris
    Participant

    @travel-junkie

    What do you mean with everything? Can you post your complete code here?


    ABomb1977
    Member

    @abomb1977

    Sure. Here’s the code:

    `function sh_walled_garden()
    {
    global $bp;

    if( bp_is_register_page() || bp_is_activation_page() || is_page(terms-of-service) || is_page(privacy-policy) )
    return;

    if( ! bp_is_blog_page() && ! is_user_logged_in() )
    bp_core_redirect( $bp->root_domain .’/’. BP_REGISTER_SLUG );
    }
    add_action( ‘get_header’, ‘sh_walled_garden’ );`

    The activity stream, member directory … the whole nine shows up to not-logged-in users if i add anything to the exclusion line.


    Boris
    Participant

    @travel-junkie

    If you use slugs you’ll need to enclose them in ‘, like `is_page( ‘terms-of-service’ )`


    ABomb1977
    Member

    @abomb1977

    LOL
    Duh on me.
    :)
    Thanks, again!


    futbolfrank
    Member

    @futbolfrank

    @Travel-Junkie
    Hello,
    Great Code, but it unfortunately doesn’t do exactly what I want to do just yet.
    I am wondering if something is possible. I am trying to create a site that is private to all non-users and directs to a page stating it is Private only and asking them to contact me on directions to register (hopefully through facebook connect).

    In my site, on the left sidebar are the login fields and a FB Connect button.
    However, I also do not want anyone to be able to register (unchecked “anyone can register” in the wp admin settings). I basically want to approve the user as they try to fully register.
    Is this possible?

    I found, anytime I try using your code along with the register box unchecked, an infinite loop happens. I was also thinking, even if it did work, I’m still out of luck b/c I tried using the invitation code checker and that plugin doesn’t seem to work on the news BP and WP.

    I also tried using the private BP plugin and that doesn’t seem to work with FB connect.
    Any suggestions?
    Thank You!


    gabu4u1
    Member

    @gabu4u1

    @Travel-Junkie Thanks for the code. I know it will help me achieve what I want.

    But my challenge is that I know nothing about coding. I have succeeded in locating the functions.php and have opened it in order to edit it. My question is where in the whole code will I place the code you wrote. Is it at the beginning or end of the code.

    I am planning to use this code below

    function sh_walled_garden()
    {
    global $bp;

    if( bp_is_register_page() || bp_is_activation_page() )
    return;

    if( ! bp_is_blog_page() && ! is_user_logged_in() )
    bp_core_redirect( $bp->root_domain .’/’. BP_REGISTER_SLUG );
    }
    add_action( ‘get_header’, ‘sh_walled_garden’ );

    Please, I will appreciate you help. I am a complete WYSIWYG person but I can follow simple instructions as regards code.

    Thank you in anticipation.

    Gabu


    gabu4u1
    Member

    @gabu4u1

    @Travel-Junkie Thanks for the code. I know it will help me achieve what I want.

    But my challenge is that I know nothing about coding. I have succeeded in locating the functions.php and have opened it in order to edit it. My question is where in the whole code will I place the code you wrote. Is it at the beginning or end of the code.

    I am planning to use this code below

    function sh_walled_garden()
    {
    global $bp;

    if( bp_is_register_page() || bp_is_activation_page() )
    return;

    if( ! bp_is_blog_page() && ! is_user_logged_in() )
    bp_core_redirect( $bp->root_domain .’/’. BP_REGISTER_SLUG );
    }
    add_action( ‘get_header’, ‘sh_walled_garden’ );

    Please, I will appreciate you help. I am a complete WYSIWYG person but I can follow simple instructions as regards code.

    Thank you in anticipation.

    Gabu


    VegasKev88
    Participant

    @vegaskev

    Nearly 3 years later, several wp & bp updates and @travel-junkie’s solution still works. Thanks for your contribution @travel-junkie. I appreciate it.

Viewing 25 replies - 76 through 100 (of 104 total)
  • The topic ‘How to make a private community?’ is closed to new replies.
Skip to toolbar