I am trying to connect usetiful to my WordPress Backend.
I need to tag the users and pass information to Usetiful for further personalization.
After going through various similar Q/A threads, I managed to retrieve and pass the User ID to Usetiful, but having trouble getting the User First Name.
Here is the Code Snippet that I am using (Adding code to the Code Snippets Plugin)
<script>
window.usetifulTags = { userId : <?=get_current_user_id() ?>, firstName : <? $user_info = get_userdata(get_current_user_id());$first_name = $user_info->first_name;return $first_name;?>;};
The get_current_user_id() works well, but unable to get the User First Name/Display Name
Since this is a text, you need to wrap some quotes around it and you should make sure your PHP is a proper value to be evaluated. If you have more operations to be performed, then it is to be recommended to implement a function and only call the function.
<script>
window.usetifulTags = { userId : <?=get_current_user_id() ?>, firstName : "<? $first_name = get_userdata(get_current_user_id())->first_name ?>"};