Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Automatically logs in the user and redirects them to their profile when they activate their account.
<?php
add_action( "bp_core_activated_user", "bp_autologin_on_activation", 40, 3 );
function bp_autologin_on_activation( $user_id, $key, $user) {
global $bp, $wpdb;
//simulate Bp activation
/* Check for an uploaded avatar and move that to the correct user folder, just do what bp does */
if ( is_multisite() )
$hashed_key = wp_hash( $key );
else
$hashed_key = wp_hash( $user_id );
/* Check if the avatar folder exists. If it does, rename it, move it and delete the signup avatar dir */
if ( file_exists( BP_AVATAR_UPLOAD_PATH . '/avatars/signups/' . $hashed_key ) )
@rename( BP_AVATAR_UPLOAD_PATH . '/avatars/signups/' . $hashed_key, BP_AVATAR_UPLOAD_PATH . '/avatars/' . $user_id );
bp_core_add_message( __( 'Your account is now active!', 'buddypress' ) );
$bp->activation_complete = true;
//now login and redirect
wp_set_auth_cookie( $user_id, true, false );
bp_core_redirect( apply_filters ( "bpdev_autoactivate_redirect_url", bp_core_get_user_domain( $user_id ), $user_id ) );
}
?>
@bijanbiria

This comment has been minimized.

Show comment
Hide comment
@bijanbiria

bijanbiria Sep 27, 2014

♥ ♥ ♥ thanks a lot

♥ ♥ ♥ thanks a lot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment