@coach-afrane
Functions.php
// Limit the Access To WordPress Dashboard. Only Admin
add_action( 'init', 'blockusers_init' );
function blockusers_init() {
if ( is_admin() && !current_user_can( 'administrator' ) && !( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
wp_redirect( home_url() );
exit;
}
}
// Limit the Access To WordPress Dashboard. Only Admin and Editor
add_action( 'init', 'blockusers_init' );
function blockusers_init() {
if ( is_admin() && !current_user_can( 'administrator' ) && !current_user_can( 'editor' ) && !( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
wp_redirect( home_url() );
exit;
}
}
// BP Redirect To Profile
function redirect_to_profile( $redirect_to_calculated, $redirect_url_specified, $user ) {
if ( ! $user || is_wp_error( $user ) ) {
return $redirect_to_calculated;
}
//If the redirect is not specified, assume it to be dashboard
if ( empty( $redirect_to_calculated ) ) {
$redirect_to_calculated = admin_url();
}
// if the user is not site admin, redirect to his/her profile
if ( ! is_super_admin( $user->ID ) ) {
return bp_core_get_user_domain( $user->ID );
} else {
//if site admin or not logged in, do not do anything much
return $redirect_to_calculated;
}
}
add_filter( 'login_redirect', 'redirect_to_profile', 100, 3 );
// Exclude Admins from Directories and BP Widgets
add_filter( 'bp_after_has_members_parse_args', 'buddydev_exclude_users' );
function buddydev_exclude_users( $args ) {
//do not exclude in admin
if( is_admin() && ! defined( 'DOING_AJAX' ) ) {
return $args;
}
$excluded = isset( $args['exclude'] )? $args['exclude'] : array();
if( !is_array( $excluded ) ) {
$excluded = explode(',', $excluded );
}
$user_ids = array( 1 ); //user ids
$excluded = array_merge( $excluded, $user_ids );
$args['exclude'] = $excluded;
return $args;
}
Sorry, it didn’t work for me.
Maybe i need to explain myself better.
I want any user who is already logged, to be redirected to the profile if the user tries to access the login page (which i have made the home page).
I am using a multisite.
I hope i didn’t have to apply all the snippets you provided. I used only the BP redirect to profile and it didn’t work.
Thanks.
Okey @coach-afrane, you want something like this: Thrive link
You just showed me some really nice idea for my community.
However, it is not exactly what i need.
I was able to go back to the login page when i click on the link you gave, though it showed “Great! You have successfully login.”
In my case, after logging in, if you click on the homepage(which is the login page) link or logo, it will take you to your profile since you are logged in already.
Thanks for your patience.
If it’s just a redirect to back to their profile page when they try to access the home page, you could add some code to the home page that looks something like this.
if( is_user_logged_in() ) {
$redirect_url = bp_loggedin_user_domain();
wp_redirect( $redirect_url );
}
Thanks a lot @xxjonfenxx.
But, how do i add the code to the home page?