Skip to content

Instantly share code, notes, and snippets.

@lanche86
Last active December 29, 2015 09:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lanche86/7648922 to your computer and use it in GitHub Desktop.
Save lanche86/7648922 to your computer and use it in GitHub Desktop.
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
Copy link

♥ ♥ ♥ thanks a lot

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