Skip to:
Content
Pages
Categories
Search
Top
Bottom

Plugin to show components to registered Users only

  • Avatar of sandeepdude
    sandeepdude
    Participant

    @sandeepdude

    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)
  • Avatar of Kunal17
    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?

    Avatar of Gpo1
    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?

    Avatar of Peterverkooijen
    peterverkooijen
    Participant

    @peterverkooijen

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

    Avatar of zeitweise
    zeitweise
    Participant

    @zeitweise

    @sandeepdude This roundup was very helpful, thank you!

    Avatar of Peterverkooijen
    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.

    Avatar of pxlgirl
    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.

    Avatar of Jeff Sayre
    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.

    Avatar of David Lewis
    David Lewis
    Participant

    @takeo

    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.

    Avatar of wordpressfan
    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; } ?>

    Avatar of roydeanjr
    roydeanjr
    Participant

    @roydeanjr

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

    Avatar of roydeanjr
    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.

    Avatar of Jehy
    Jehy
    Participant

    @jehy

    Avatar of PJ
    PJ
    Participant

    @pjnu

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

    Thank you.

    Avatar of tiramisucraft
    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.