Redirect users after posting/editing using Buddypress

This topic contains 4 reply and 3 voices, and was last updated by Tareq Hasan 11 years, 3 months ago
Viewing 4 Posts - 1 through 4 (of 4 total)
Author Posts
July 18, 2013 at 10:21 pm 6109
Tareq Hasan Hi all, Ok, I have a question I was hoping you would be able to help with. I am using WPUFPro with BuddyPress and also Theme My Login. I have four forms set up to allow users to upload Custom Posts with Taxonomies. After the user uploads/edits a custom post, I would like to redirect them back to their account to show them their posts. Now, I know there is a setting in each form to redirect them to either the post, same page, a different page or custom url. My issue is that because I am using BuddyPress and I need to include the username as part of the url. The address I want to send my users to is something like http://mysite.com/rescues/username/my-account. The '/rescues/username' element is added by BuddyPress and because every username is different, it means that I am unable to type out the required url. I am also unable to pick a specific page for the same reason. If I use the page that contains the [wpuf_dashboard] shortcode (in my case, my-pets) it will take me to http://mysite.com/my-account and omit the '/rescues/username' part. With Theme My Login, I am able to use '/%user-login%/' for redirections and it will retrieve the correct username. Would there be a work around like this for WPUF Pro? I hope all this made sense! :) Thanks Damien
July 18, 2013 at 10:29 pm 6112
Tareq Hasan Tareq Hasan

[php]
function wpuf_redirect_to_profile( $response ) {
$response[‘redirect_to’] = bp_core_get_user_domain( get_current_user_id() );

return $response;
}

add_filter( ‘wpuf_add_post_redirect’, ‘wpuf_redirect_to_profile’ );
add_filter( ‘wpuf_edit_post_redirect’, ‘wpuf_redirect_to_profile’ );
[/php]

Paste the code in your themes functions.php and set the redirect to option to a page or any URL. This code will override the URL and redirect them to the buddypress user profile and adding/editing a post.

July 18, 2013 at 11:57 pm 6116
hatchmedia hatchmedia

Excellent! Exactly what I was looking for!

Yet again, great customer support Tareq!

Damien

August 16, 2013 at 4:50 am 7009
epictum epictum

I’m also in a similar boat, but this function doesn’t work for, most likely because the Edit page I’m trying to redirect my BP users to is one that was created manually. How would I go about redirecting one of my users from mydomain.com/edit/ to mydomain.com/members/username/movies/edit/ ?

August 16, 2013 at 10:24 pm 7031
Tareq Hasan Tareq Hasan

@epictum, $response['redirect_to'] is the redirect URL. So you could put it like that:
[php]
$user = wp_get_current_user();
$response[‘redirect_to’] = home_url() . ‘/members/’ . $user->user_login . ‘/movies/edit’;;
[/php]

Viewing 4 Posts - 1 through 4 (of 4 total)