Skip to:
Content
Pages
Categories
Search
Top
Bottom

How to redirect away from bbpress profile


  • piperpam27
    Participant

    @piperpam27

    Hi there,

    I’m working with a custom profile setup (consolidating the profiles from multiple plugins) and and wondering how I can redirect a bbpress user to this central profile when they try to access their forum profile. In other words, how do I make it so that someone who tries to visit:

    http://www.example.com/forums/user/johnsmith

    is redirected to:

    http://www.example.com/profile

    I saw a very old post in this forum that discussed this topic, and they suggested using the following method:

    add_action('bb_init', 'profile_redirect');
    
    function profile_redirect() {
        if (is_bb_profile() && $_GET['tab'] != 'edit' && $_GET['tab'] != 'favorites') {
            $user = bb_get_user($_GET['id']);
            if ($user) wp_redirect("http://www.example.com/member/" . $user->user_nicename);
        }
    }

    Since it’s so old, it doesn’t work anymore, and honestly, what I’d like to do is slightly different. I’d like to redirect a user away from the profile page (regardless of which section they’re on–whether it be favorites, subscriptions, or edit profile) as long as:

    1. They are logged in
    2. They are on their ownprofile page

    How could I do that with the current version of WordPress?

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

  • Robin W
    Moderator

    @robin-w

    so where do you want them to go if they are either not logged in, or are looking at someone else’s profile page? (as that’ll determine where you might start!)


    piperpam27
    Participant

    @piperpam27

    Sorry, that wasn’t clear in my first post. They’ll regardless of which user is logged in, they’ll need to go here:

    http://www.example.com/profile

    The session data will determine which information to display.


    Robin W
    Moderator

    @robin-w

    suggest you start with looking at

    bbpress/includes/extend/buddypress/members.php

    This changes bbpress to go to buddypress profile, and should give you all the code you need.


    piperpam27
    Participant

    @piperpam27

    Great, thanks!


    piperpam27
    Participant

    @piperpam27

    For future readers, I was able to accomplish the redirect with this simple line of code:

    add_filter( 'bbp_pre_get_user_profile_url', function() {
    	return get_bloginfo('url').'/profile';
    });

    Very simple, really!

    You can also change the default url for favorites and subscriptions by doing this:

    
    // Replace the default link for the favorites
    add_filter( 'bbp_get_favorites_permalink', function() {
    	return get_bloginfo('url').'/profile/forum-favorites';
    });
    
    // Replace the default link for subscriptions
    add_filter( 'bbp_get_subscriptions_permalink', function() {
    	return get_bloginfo('url').'/profile/forum-subscriptions';
    });
    

    Of course, if you’re using pre PHP 5.3.1 (or are developing a plugin) you’ll need to create actual functions rather than using anonymous functions.

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

You must be logged in to reply to this topic.