[Resolved] Hiding Members Page to everybody (visitor and also members)
-
Is there a way to completely hide MEMBERS page? I mean, hiding the page from everybody: visitors but also members (user logged-in). I would like to let the page private, just the admin should view.
Suggestion?
Thanks a lot for your support
-
Please put this code in your bp-custom.php
function buddydev_hide_members_directory_from_all_except_admin() { if ( bp_is_members_directory() && ! is_super_admin() ) { //should we add a message too? //bp_core_add_message( 'Private page.', 'error' ); bp_core_redirect( site_url('/') ); } } add_action( 'bp_template_redirect', 'buddydev_hide_members_directory_from_all_except_admin' );
That should do it. Hoe it helps.
thank you very much. I have a problem… the page bp-custom.php seems that doesn’t exist in my file manager. How is this possible?
It is possible because it doesn’t exist and you never noticed his mention in many topics of this forum, and perhaps never read the codex. 🙂
Read here please:
@danbp thanks! I’m really new with wordpress world, and I am not a webmaster/programmer, so even if wordpress seems easy, it’s less easy for me.
If I understood: I have to create that file, put inside the suggestion of the user “brajesh”, then save the file in the plugins’ folder. Is this enough?
Thanks a lot
Can you confirm?
Thanks again
Yes. Anyway, best confirmation is to follow the instructions you received and to try them out !
I mean: is it enough to create a file bp.custom.php and upload it in the right folder? or do I have in some way “say to buddypress that there is that file”? It’s enough to create it (because I don’t have that file) and upload it?
Hello and thanks for the support, I tried the solution suggested, but after I created and then uploaded the file bp-custom in the plugins folder I got an error in every page of the website:
Parse error: syntax error, unexpected ‘function’ (T_FUNCTION) in /home/mondolap/public_html/wp-content/plugins/bp-custom.php on line 2
This is my file bp-custom:
<? php function buddydev_hide_members_directory_from_all_except_admin() { if ( bp_is_members_directory() && ! is_super_admin() ) { //should we add a message too? //bp_core_add_message( 'Private page.', 'error' ); bp_core_redirect( site_url('/') ); } } add_action( 'bp_template_redirect', 'buddydev_hide_members_directory_from_all_except_admin' ); ?>
Hi @ico33,
bp-custom file doesn’t need a closing php tag. Remove it and see if it works.
the first line of bp-custom contain
<?php
then you add your function(s)…<?php function 1 ---- function 2 ---
and so on. And that’s it !
Thanks! I did it with your suggest, so the file is
<? php function buddydev_hide_members_directory_from_all_except_admin() { if ( bp_is_members_directory() && ! is_super_admin() ) { //should we add a message too? //bp_core_add_message( 'Private page.', 'error' ); bp_core_redirect( site_url('/') ); } } add_action( 'bp_template_redirect', 'buddydev_hide_members_directory_from_all_except_admin' );
But every page of the website is now again a blank page with this error:Parse error: syntax error, unexpected ‘function’ (T_FUNCTION) in /home/mondolap/public_html/wp-content/plugins/bp-custom.php on line 2
The function is working correctly on my install.
Perhaps you have an issue with quotes, ie after copy/pasting the snippet from a topic where the code whas inserted without using the code button.
Which software do you use to publish bp-custom ?Copy/paste following and give a try:
function buddydev_hide_members_directory_from_all_except_admin() { if ( bp_is_members_directory() && ! is_super_admin() ) { //should we add a message too? //bp_core_add_message( 'Private page.', 'error' ); bp_core_redirect( site_url('/') ); } } add_action( 'bp_template_redirect', 'buddydev_hide_members_directory_from_all_except_admin' );
Nothing to do!
Error:
Parse error: syntax error, unexpected ‘function’ (T_FUNCTION) in /home/mondolap/public_html/wp-content/plugins/bp-custom.php on line 3
This is the bp-custom code:
<? php
function buddydev_hide_members_directory_from_all_except_admin() {
if ( bp_is_members_directory() && ! is_super_admin() ) {
//should we add a message too?
//bp_core_add_message( ‘Private page.’, ‘error’ );
bp_core_redirect( site_url(‘/’) );
}
}
add_action( ‘bp_template_redirect’, ‘buddydev_hide_members_directory_from_all_except_admin’ );Please use the
code button
when posting code.Try changing this:
<? php
To this:<?php
Well… i am a bit ashamed. It’s true that I’m new with wordpress and I’m not a webmaster… but damn, the problem was there @shanebp LOL
A big THANKS to everybody here!
- The topic ‘[Resolved] Hiding Members Page to everybody (visitor and also members)’ is closed to new replies.