Currently, I am utilizing a platform that automates the device registration process for my users through Onesignal.
Upon user login, I invoke the function by using gonative_onesignal_info();
within script tags (the full function is provided below). This successfully registers the devices with Onesignal.
Now, as per the platform's guidelines, I am supposed to send this information to my server via AJAX, which is where I am facing difficulties. As mentioned in the platform's documentation, if you call gonative_onesignal_info() as shown below:
function gonative_onesignal_info(info) {
console.log(info);
}
...the 'info' object will contain the following details:
{
oneSignalUserId: 'xxxxxxx',
oneSignalPushToken: 'xxxxxx',
oneSignalSubscribed: true,
}
Here is the complete function implementation:
function onesignal_mobile_registration( $user_login, $user ) {
// Obtain user data
$user_id = $user->ID;
$user_email = $user->user_email;
?>
<script>
gonative_onesignal_info(info);
</script>
<?php
$oneSignalPushToken = ???;
update_user_meta( $user_id, 'oneSignalPushToken', $oneSignalPushToken);
}
add_filter( 'wp_login', 'onesignal_mobile_registration', 10, 2 );
Hence, my question is - how can I extract the 'oneSignalPushToken' from the JavaScript object and assign it to $oneSignalPushToken for storage in my user records? Do I need to utilize AJAX for this extraction process? If so, could you guide me on how to proceed?