Skip to:
Content
Pages
Categories
Search
Top
Bottom

Plugin to show components to registered Users only

  • Hello,

    after a long search in this forums,i learnt how to make the buddypress site components like members,groups not visible to non-logged in users.

    Thanks to Burt Adsit and Peterverkooijen.I learnt this from their thread http://buddypress.org/forums/topic.php?id=1651

    i started this thread to avoid confusions since there are a lot of codes and error messages in that thread.

    Ok….

    In short,create a file named bp-custom.php in the wp-content/mu-plugins folder.

    Then add this code in that file.

    <?php /* Plugin Name: bpRestrict - BuddyPress Plugin Plugin URI: http://code.ourcommoninterest.org/ Description: Restricts non-logged in users from certain areas Author: Burt Adsit Version: 0.1 Author URI: http://code.ourcommoninterest.org/ License: GNU GENERAL PUBLIC LICENSE 3.0 http://www.gnu.org/licenses/gpl.txt */ function js_restrict_access(){ global $bp, $bp_unfiltered_uri; if (!is_user_logged_in() && (BP_MEMBERS_SLUG == $bp_unfiltered_uri[0] || BP_GROUPS_SLUG == $bp->current_component || BP_BLOGS_SLUG == $bp->current_component)){ bp_core_redirect( get_option('home') . "/register?s=1" ); } } add_action( 'wp', 'js_restrict_access', 3 ); ?>

    Next,open the register.php file from wp-content/themes/bphome/

    After the <?php get_header(); ?> line,add this code

    <?php

    if($_REQUEST["s"]){?>

    <script type="text/javascript">

    jQuery(document).ready(function () {

    setTimeout(function(){ jQuery("#error").fadeOut("slow"); }, 6000);

    });

    </script>

    <div id="error" class="error">

    <h3>The page you were trying to access is for members only. Please login or register to continue.</h3>

    </div>

    <?php } ?>

    That’s it….

    now,the non-logged in users will be redirected to sign up page whenever they try to visit the members,blog or the groups…

Viewing 15 replies - 1 through 15 (of 15 total)

  • Kunal17
    Participant

    @kunal17

    Thanks for making the code more accessible. One bug in it is that if a user logs in after being shown the message at the register page, it shows them the message again (because the page loads). Is there a way to hide the message if the user viewing the register page is logged in?


    gpo1
    Participant

    @gpo1

    Any update on this and can you place it when fixed in wordpress.org Plugins Directory ,so that we can download it?


    peterverkooijen
    Participant

    @peterverkooijen

    @sandeepdude, I did not contribute anything to that code, all credit should go to Burt Adsit.


    zeitweise
    Participant

    @zeitweise

    @sandeepdude This roundup was very helpful, thank you!


    peterverkooijen
    Participant

    @peterverkooijen

    The Ajax redirect in this solution, with the register?s=1, had some annoying side effects that made it unusable. See the original thread for details.

    Or did you fix that problem, sandeepdude? I’m a bit reluctant to try it again and find out that it’s the exact same code…

    I’ll look for a solution in the next few days. Another way to show an Ajax message after redirect would probably be part of the solution.


    pxlgirl
    Participant

    @pxlgirl

    Hi,

    I get this error msg after setting up bp-custom.php and editing the register.php:

    Warning: Cannot modify header information – headers already sent by (output started at /blah/wordpress-mu/wp-content/mu-plugins/bp-custom.php:1) in /blah/wordpress-mu/wp-content/plugins/buddypress/bp-xprofile/bp-xprofile-signup.php on line 5

    What went wrong here?

    pxlgirl.


    Jeff Sayre
    Participant

    @jeffsayre

    @pxlgirl

    That’s the problem with following a thread that was started more than 2 months ago! There have been many, many changes to BuddyPress’ codebase since that time.

    One of those changes is that BP now runs in /plugins/ and not /mu-plugins/. Move your bp-custom.php file into /plugins/ and see what happens.

    I imagine it might make sense to hide the activity stream too… otherwise non-registered users clicking on links in the stream would get a LOT of annoying “please register” screens.


    wordpressfan
    Participant

    @wordpressfan

    @sandeepdude: the code works perfectly, once I took Jeff’s advice about “plugins.”

    @david lewis: good suggestion about hiding the activity stream. Is there a SLUG I can add?

    I’m my case… I’ve simply decided in home.php to wrap the “first-section” widgets with logic that will show that widget section only to logged in users… otherwise it is replaced with a positioning statement + calls to action (i.e. Join! Donate! Learn!) and a wordpress loop. Pretty simple stuff:

    <?php if (!is_user_logged_in()) { ?>

    [static content & wordpress loop for the public]

    <?php } else { ?>
    <?php if(!function_exists('dynamic_sidebar')||!dynamic_sidebar('first-section')):?>

    [widgets for members only (i.e. site activity) ]

    <?php endif; } ?>


    roydeanjr
    Participant

    @roydeanjr

    Works well while I wait for the Privacy Component Plugin. Thank you!


    roydeanjr
    Participant

    @roydeanjr

    UPDATE: Works well where implemented. There are just a lot of areas where a user could hack and get all kinds of information. I don’t have time to go through all the code to find and implement if/else/endif logic.


    Jehy
    Participant

    @jehy


    PJ
    Participant

    @pjnu

    @Jehy et. al. RUO2 works very well on my install. Have others had the same luck? :)

    Thank you.


    tiramisucraft
    Member

    @tiramisucraft

    Ahhh great one …I was looking for so long to get it…and this one was perfect with my little experience in bp

Viewing 15 replies - 1 through 15 (of 15 total)
  • The topic ‘Plugin to show components to registered Users only’ is closed to new replies.
Skip to toolbar