Skip to:
Content
Pages
Categories
Search
Top
Bottom

Privacy options (friends only viewing)

  • @pcrain

    Member

    Is there an easy way I could make profiles only viewable by friends? Possibly just display an ‘add friend’ link instead of the full profile?

    Thanks,

    Paul

Viewing 16 replies - 1 through 16 (of 16 total)
  • @pcrain

    Member

    Here’s what I did as a temporary solution (this is prob. not the best way, so I wouldnt recommend it). In each /theme/buddypress/plugin folder, for example /theme/buddypress/profile/index.php after div id=”content”> I added

    <?php

    global $bp, $wpmu;
    $potential_friend_id = $bp['current_userid'];
    $friend_status = BP_Friends_Friendship::check_is_friend( $bp['loggedin_userid'], $potential_friend_id );
    if ( $friend_status != 'is_friend' && $potential_friend_id != $bp['loggedin_userid']) {
    echo "You must be friends to view this profile.".bp_add_friend_button();
    } else { ?>

    then before the last </div> in the file i added

    <?php } ?>

    @gogoplata

    Participant

    Glad you found and shared a temporary workaround. This was also brought up in another topic recently, and Andy said “In the first version for the end of the year, BuddyPress will only support open networks. However, the plan is to put together a generic privacy component which can be used by all components to restrict and allow customizable privacy levels.”.

    Privacy isn’t built in yet but it will be soon enough.

    @apeatling

    Keymaster

    Thanks pcrain, that’s a nice quick solution for people who want to close off profiles to the public.

    A proper privacy component will be coming, just not before the end of the year as gogoplata mentioned.

    @andrea_r

    Participant

    The only other option currently available is a plugin that makes the blog itself private. No idea how it acts with BP.

    http://wpmudev.org/project/More-Privacy-Options

    @trent

    Participant

    That plugin will work with BP, but it takes the site-admin manually editing the blog privacy since there is no place for the user to change privacy since it is locked out of the blog admin for home base blogs ;)

    Trent

    @andrea_r

    Participant

    Ah! :D Good check there Trent.

    @trent

    Participant

    Need to ask some experts. Playing around, if you use dsader’s privacy plugin, couldn’t you just edit line 120 of bp-core-homebase-functions.php from:

    <input type="hidden" name="blog_public" value="0" />

    to:

    <input type="hidden" name="blog_public" value="-1" />

    Wouldn’t that make the blog registered to members of the community only since the -1 is that option for the plugin?

    Trent

    @andrea_r

    Participant

    Yep. Should work. Not retroactively, but on all news ones created after that.

    Ron and I were also thinking on the public side, you could do a check at the top of the theme profile page for is_logged_in, than if not, display something else.

    @apeatling

    Keymaster

    Not sure about the plugin, but yes, an is_user_logged_in() check would limit the profile to only logged in users if you wanted to close it off.

    @nirok

    Participant

    <?php if ( is_user_logged_in() ) : ?>

    …..

    <?php endif; ?>

    works really well as you can just add it to the different components you don’t want to show up unless they are logged in…

    @nirok

    Participant

    Is there another code snippet like this that allows just the user to view a part of there profile or only approved friends??

    @sandeepdude

    Participant

    @Pcrain

    When i placed your code,it shows this error message

    Fatal error: Cannot use object of type stdClass as array in /home/username/public_html/sitename/wp-content/bp-themes/bpmember/friends/index.php on line 13

    @jeffsayre

    Participant

    @sandeepdude

    I have not seen Pcrain in the forums for quite some time. I doubt you’ll get a response. This thread was started 8 months ago. Since then, the BuddyPress codebase has changed considerably and the solutions presented in this thread may be out of date.

    If you have not yet read this thread, please do so.

    To your point, a proper privacy component is in the works. It will be available as a plugin on a future version of BuddyPress.

    @texet

    Participant

    @Pcrain

    When i placed your code,it shows this error message

    Fatal error: Cannot use object of type stdClass as array in /home/username/public_html/sitename/wp-content/bp-themes/bpmember/friends/index.php on line 13

    If you update your code thusly, it should work:

    <?php

    global $bp, $wpmu;
    $potential_friend_id = $bp->displayed_user;
    $friend_status = BP_Friends_Friendship::check_is_friend( $bp->loggedin_user, $potential_friend_id );
    if ( $friend_status != 'is_friend' && $potential_friend_id != $bp->loggedin_user) {
    echo "You must be friends to view this profile.".bp_add_friend_button();
    } else { ?>

    And of course add the

    <?php } ?>

    at the end.

    @texet

    Participant

    actually, there is something wrong with this code I posted.

    Will need to check and get back to you

    @texet

    Participant

    OK, I think I fixed the code. Seems to work for me. Can anyone test and confirm?

    <?php
    global $bp;
    $potential_friend_id = $bp->displayed_user->id;
    $friend_requester_id = $bp->loggedin_user->id;
    $friend_status = BP_Friends_Friendship::check_is_friend( $friend_requester_id, $potential_friend_id );
    if ( $friend_status != 'is_friend' && $potential_friend_id != $friend_requester_id) {
    echo '<br><br>Oops! You must be friends with <div style="font-weight:bold; display:inline">' . $bp->bp_options_title . '</div> to view this profile.<br>Click the "Add Friend" button above to request friendship.' . bp_add_friend_button();
    } else { ?>

    … do stuff …

    <?php } ?>

Viewing 16 replies - 1 through 16 (of 16 total)
  • The topic ‘Privacy options (friends only viewing)’ is closed to new replies.
Skip to toolbar