Reply To: Hook for when a user first logs in
Hi @ndh01,
I think you could do this just with buddypress.
(just please backup database before….. etc)
Go to Profile Fields—> (Click) Add New Field Group
Add New Field (text) say Field Name virgin
Then add the following to your functions.php
function vub_login_redirect($redirect_to, $set_for, $user){
global $current_user, $bp, $wpdb;
$val = 'no';
if (bp_get_profile_field_data (virgin, $user -> ID )!=""){
$redirect_to = bp_core_get_user_domain($user->ID) .'/groups/';
}else{
xprofile_set_field_data( 'virgin', $user -> ID, $val);
$redirect_to = bp_core_get_user_domain($user->ID) .'/profile/change-avatar/';
}
wp_redirect( $redirect_to );
exit();
}
add_action('login_redirect', 'vub_login_redirect', 20, 3);
Alternatively you could as you have suggested create a new meta.
A useful plugin for that would be User Meta Manager
Add Custom Meta say a text field Name — firsttimer
then add the following (instead of the above) to your functions.php
function vu_login_redirect($redirect_to, $set_for, $user){
global $current_user, $wpdb;
$firsttimer = get_usermeta($user -> ID, 'firsttimer',single);
$val = 'no';
if (!empty ($firsttimer)) {
$redirect_to = bp_core_get_user_domain($user->ID) .'/groups/';
}else{
update_user_meta( $user -> ID,'firsttimer',$val);
$redirect_to = bp_core_get_user_domain($user->ID) .'/profile/change-avatar/';
}
wp_redirect( $redirect_to );
exit();
}
add_action('login_redirect', 'vu_login_redirect', 20, 3);
Obviously change the redirects to wherever you want the user to go.