Hello boss
About this
https://buddydev.com/hide-buddypress-members-directory/
–
I want to make it visible for just about 4 specific users (including admin)
These users already have a user-role serving another important function and i dont want to mess with those roles
How do i make visible per user??
….
….
*****Also for other users who can’t see it…i want them to be redirected to another page/post of my choice when they click the members page link. (the page would have a message telling them that they are not allowed to view this page… Instead of them just seeing error 404)
Sorry i think this topic is meant to be
: “SHOW member list/page TO
specific users”…
…
Sorry my mistakeHi,
Thank you for the question.Do you want to keep the list of user ids or name for allowing?
Regards
BrajeshI dont get boss
..
Both…teach me both.. How to keep the user id and name..teach me the two
Hi,
Here is the code.1. Let us define a function to check if the current user has one of the ids in the lsit
/** * Check if the directory should be visible to a user. * * @return bool */ function bp_custom_is_directory_visible() { $visible_to_user_ids = array( 1, 2, 3, 20 ); return is_user_logged_in() && in_array( get_current_user_id(), $visible_to_user_ids ); }
You can add your own user ids.
In case you wish to use username instead of the id, we can redefine the same function as
/** * Check if the directory should be visible to a user. * * @return bool */ function bp_custom_is_directory_visible() { $visible_to_user_names = array( 'admin', 'xyz' ); return is_user_logged_in() && in_array( wp_get_current_user()->user_login, $visible_to_user_names ); }
Please note, you can use only one of the above as I have used same function name. Putting both in your file will generate error.
Now that we have written the function for checking user, we can update our code from blog to use it as
/** * Hide Members Directory from everyone. */ function buddydev_hide_members_directory_for_all() { if ( bp_is_members_directory() && ! bp_custom_is_directory_visible() ) { bp_do_404(); load_template( get_404_template() ); exit( 0 ); } } add_action( 'bp_template_redirect', 'buddydev_hide_members_directory_for_all' );
That’s all.
Hope it works for you.
Regards
BrajeshThank you boss…i appreciate you so much ( i used by user ID cos thats the one that worked)
I.wonder is it possible to redirect those who are not allowed to see the page.. To redirect them to another page of my choice?
No Issues.
Please remove these line
bp_do_404(); load_template( get_404_template() ); exit( 0 );
and replace them with
bp_core_redirect( "http://yoursite_url");
That will do it.
Regards
BrajeshThank you sir..ild try it out as soon as i can…no electricity for days
You must be logged in to reply to this topic.