HI there,
Unfortunately, this falls outside the scope of support I offer for WP-Forge. This is a “how to” question which I have covered here https://wordpress.org/support/topic/support-issue-clarification?replies=1
I apologize for any inconvenience this may cause.
Thanks anyways , I found the solution online.
Here is the final code , eventually you end up with a table containing all logged in users , with their locations based on gelocation by IP.
function addUserLocation($login){
$user = get_user_by('login',$login);
global $wpdb;
$loc = json_decode( file_get_contents('http://ipinfo.io/'.$_SERVER['REMOTE_ADDR'].'/json') )->loc;
$latitude = explode(',' , $loc)[0];
$longitude = explode(',' , $loc)[1];
$wpdb->insert(
'locations',
array(
'user_id' => $user->ID ,
'firstname' => $user->display_name ,
'lastname' => $user->last_name,
'email' => $user->user_email,
'latitude' => $latitude ,
'longitude' => $longitude
),
array(
'%d' ,
'%s' ,
'%s' ,
'%s' ,
'%s' ,
'%s'
)
);
}
function removeUserLocation(){
global $current_user;
global $wpdb;
$wpdb->delete( 'locations', array( 'user_id' => $current_user->data->ID ), array( '%d' ) );
}
add_action( 'wp_login' , 'addUserLocation', 99 );
add_action( 'clear_auth_cookie', 'removeUserLocation' , 1);
Ofc you have to create this table first 😀
Awesome, glad you got it working. I appreciate you posted what you found here, it may help someone else in the future.