BuddyDev

Hide BuddyPress Members Directory

Do you want to hide or disable BuddyPress members directory? It is easy and I am going to help you do it quickly.

We will be seeing five examples for :-

  • How to hide BuddyPress members directory for everyone( including search engines)
  • How to hide BuddyPress members directory for everyone except site admin
  • How to hide BuddyPress members directory from non members
  • How to hide BuddyPress members directory from users with certain roles.
  • How to hide members directory from all except users with certain roles.

I guess these examples should cover most of the possible scenerios.

Strategy:-

We are going to hook to ‘bp_template_redirect‘ action. We can either

  • Redirect users to some other page when they access members directory
  • Or we can throw a page not found(404) error.

I am going with the second approach. We will throw 404 error when a user who is not allowed to see members directory tries to visit it.

To achieve our goal, we will be using bp_do_404() to set the status header(we can do without it but why repeat) and then load 404 template.

Example 1:- Hiding BuddyPress Members directory from everyone

Here is the result.

Example 2:- Hiding BuddyPress Members directory from everyone except Site admin.

After all, our super admins have superpowers. Let us not hide the directory from them.

Example 3:- Hide BuddyPress members directory from non logged users(non members)

With this code, the members directory will be visible to the logged in users only. In other words, Now the directory is available to community members only.

Example 4:- Hide members directory from users with certain roles.

I am going to show with ‘subscriber’ and ‘contributor’ role, please feel free to extend it.

Example 5:- Make BuddyPress directory visible to user with certain roles only.

In this example, the members directory will be hidden from everyone except users with allowed roles.

You can put the code in your bp-custom.php or in your theme/child theme’s functions.php.

Have fun and I hope you are enjoying your journey with BuddyPress 🙂

2 Responses to Hide BuddyPress Members Directory

  • Hello,

    How can I apply redirect to signup page instead of 404 page with Example 3

    Thanks

  • Great! thanks for sharing this. loved it.

Subscribe