I saw this in a support thread
function redirectAfterAvatarUpload() { $location = '/members/'.bp_core_get_username(bp_loggedin_user_id()).'/profile/edit/group/1/'; bp_core_redirect($location); return; } add_action('xprofile_avatar_uploaded','redirectAfterAvatarUpload' );
I also tried this but did not work
It also seems that profile photo is uploaded via ajax so would a redirect be possible
function redirect_after_avatar_upload() { if ( ! function_exists( 'buddypress' ) ) { return; } // check for user's last activity. $last_activity = bp_get_user_last_activity( $user->ID ); if ( empty( $last_activity ) ) { $page_url = site_url( '/onboard-invite-friends/' ); bp_core_redirect($page_url); } } add_action('xprofile_avatar_uploaded','redirect_after_avatar_upload' );
Hi Tosin,
Thank you for the question.This needs to be done on client side(via js).
Please remove the above code that you are using and add the followj g php code
/** * Redirect user on successful php upload and crop. */ add_action( 'bp_enqueue_scripts', function () { // you can set the url value to anything. $url = trailingslashit( trailingslashit( bp_get_members_directory_permalink() ) . 'me/' . bp_get_members_invitations_slug() ); ob_start(); ?> bp.Avatar.Attachment.on( 'change:url', function( data ) { if( data.get('object') == 'user' ) { window.location="<?php echo esc_url( $url ); ?>"; } } ); <?php $script = ob_get_clean(); wp_add_inline_script( 'bp-avatar', $script, 'after' ); }, 100 );
That will take care of your redirect. Please let me know if it works for you or not?
Regards
BrajeshIt did not work after photo upload
This is my code
add_action( 'bp_enqueue_scripts', function () { // you can set the url value to anything. $url = site_url( '/refer-friends/' ); ob_start(); ?> bp.Avatar.Attachment.on( 'change:url', function( data ) { if( data.get('object') == 'user' ) { window.location="<?php echo esc_url( $url ); ?>"; } } ); <?php $script = ob_get_clean(); wp_add_inline_script( 'bp-avatar', $script, 'after' ); }, 100 );
Please try on a fresh install. If you have some redirect code, the js event may not be firing.
Regards
Brajesh
Viewing 6 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic.
This topic is: not resolved