Skip to:
Content
Pages
Categories
Search
Top
Bottom

Login Redirect to "My Groups" page

  • Avatar of treins12
    treins12
    Participant

    @treins12

    I’d like to have users go to the My Groups page directly after login.
    From here they could see their groups.

    How can I do this?
    I’ve seen the way you can direct a user to their profile, but would prefer the Groups index page.
    Thanks for any suggestions.

Viewing 6 replies - 1 through 6 (of 6 total)
  • Avatar of shughey
    shughey
    Participant

    @shughey

    I am searching for the same, just a redirect after logging in to the groups page, nothing else.

    Thanks

    Avatar of shanebp
    shanebp
    Moderator

    @shanebp

    >I’ve seen the way you can direct a user to their profile

    Use the same approach and replace the profile url with the groups url.

    bp_core_redirect( get_option('home') . '/groups/' );

    Avatar of shughey
    shughey
    Participant

    @shughey

    shanebp,

    I appreciate your suggestion but I’ve no idea where to begin with this. Am I supposed to add the code to bp-core, or where?

    Avatar of shanebp
    shanebp
    Moderator

    @shanebp

    If your groups are at url/groups/
    then try pasting the code below into your theme / functions.php

    It should redirect non-admins to the groups page.

    based on http://codex.wordpress.org/Plugin_API/Filter_Reference/login_redirect

    function shug_login_redirect( $redirect_to, $request, $user ) {
    	//is there a user to check?
    	global $user;
    	if ( isset( $user->roles ) && is_array( $user->roles ) ) {
    		//check for admins
    		if ( in_array( 'administrator', $user->roles ) ) {
    			// redirect them to the default place
    			return $redirect_to;
    		} else {
    			return home_url('/groups/');
    		}
    	} else {
    		return $redirect_to;
    	}
    }
    add_filter( 'login_redirect', 'shug_login_redirect', 10, 3 );
    Avatar of shughey
    shughey
    Participant

    @shughey

    Thanks, I’ll work on it.

    Avatar of shughey
    shughey
    Participant

    @shughey

    Worked!!! Thanks!!!

Viewing 6 replies - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.