Last active
December 29, 2015 09:18
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 ) ); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
♥ ♥ ♥ thanks a lot