[Resolved] hide profile from non-logged-in users
I have a requirement wherein users are required to be logged in to view someone else’s profile. Other section (Blog etc..) are open to guest users though.
I was worndering if someone else has done this before already and can save me from digging into bp code to get to a solution.
Any help is greatly apprecited.
you have to modify from within a child theme the profile-loop.php file
On the first line of the file, add <code><?php if ( is_user_logged_in() ) : ?></code>
At the end of the file, insert between the last endif and the last do_action this:
<code><?php else : ?>
<?php echo “<div style=’width: 600px;height:25px; padding: 4px; border: 3px solid #ff0000; text-align: center; font-style:bold; font-size: 1.3em;’> You must be logged in to view a member profile</div>”; ?>
<?php endif; ?></code>
Change the div inline style to whatever you need accordingly to your theme. The example fits with bp-default.
Take care by copy/pasting from here, the <code> tags belongs to the forum. Must be retrived.
@Chouf1 thanks. works like a charm.
Since i didn’t want anything (even the avatar image) to be displayed to non-logged in users, i added the code in home.php instead (and plugins.php, since i have 2-3 custom pages added to users profile).
I tried using the codes and got a “parse error” I am using buddy press with the Graphene theme. Please let me know what further adjustments I may need to make.
I am sure it must be some typo mistake as the code isn’t complicated or error prone. Make sure while copying the code from here, you copy it correctly and have removed unwanted formatting
Just thought I’d add another suggestion – there’s a plugin called Member Access (http://www.chrisabernethy.com/wordpress-plugins/member-access/) which controls access to pages based on whether a visitor is logged in or not. I’m using it successfully on a BuddyPress site. I think you’d have to disable access to the “Member Directory” page as well for it to work ‘out of the box’, but with some php tweaking you may be able to have the directory page show but restrict access to more detailed profile information.
Can your code be modified for private messaging? I’m trying to make the private message button on profiles visible when someone is logged out, but redirected to log in/register when a logged out/unregistered user attempts to contact someone. Can anyone point me in a general direction?
But why do you want to retro pedaling ? Those buttons are not visible for visitors. Reverting this just to redirect them to the login page and hoping they come back after registering is fussy !
I would suggest you to write a short message like:
<?php if ( !is_user_logged_in() ) : ?>
<div>If you were logged in you could send a message to this member. </div>
<?php endif; ?>
Thanks for the response, suggestion, and snippet. I agree that it’s fussy. I’ll reflect.
edit it to meet your requirement.
@bphelp I’ve removed the comments as instructed to hide sitewide forums but they’re still visible to me when logged out.
Please provide a little more info on your install. WP/BP/Themes etc.
If you removed the comments /* */ || bbp_is_single_forum() it should work. I am using a new install of WP 3.5.1 and BP 1.7 and I tested it with the default theme , twenty twelve and the Responsive Theme and it still works for me. Maybe its your theme or a plugin you have installed that is failing. Try a different theme because I can’t replicate the issue.
I tried it with the BP Default theme and it still won’t hide forums.
Strange, it works perfect for me. Maybe its a plugin interfering because on my install I only have BP, BBPress, and Private Community activated. If I log out it redirects me to the registration. If I click the forum nav button it redirects me to registration as well. Do you have other plugins installed besides the ones I listed?
hi i made a test user here:
but if you’ll notice all other buddypress functionality redirects to a registration page, and that redirect is handled by wishlist member.
if you go here
you’ll get redirected.
BUT — obviously i only want profiles visible to logged in users. the rest of the site looks to be functioning properly.
I’m using the twentytwelve theme and have a child theme set up — and am using that.
Does the above info mean that I would create the directories
and create fileprofile-loop.php
The topic ‘[Resolved] hide profile from non-logged-in users’ is closed to new replies.