I know this question has been answered before, but it's not exactly the info I am looking for.
Right now I am developing a chatbot for a client. I am kind of new to web development, but especially to wordpress (this is what the client is using).
The chatbot is added to the pages using the Insert Headers and Footers
plugin from wordpress.
I add it to the header. But I guess it would also work in the body.
Given that I don't know PHP/Wordpress, I don't know how I could pass the user role to the bot, so it would offer support only to certain user roles.
I know there are some php functions (is_user_loggedin, or wp_get_current_user) but I don't know how to actually run these.
I tried adding them between script tags like below to at least try to dump the info to the browser console, but it didn't work..
<script>
<?php
$user = wp_get_current_user();
var_dump($user);
?>
</script>
This is how I add the chatbot to the website:
I add the following to the Header
of the app using the previously mentioned plugin.
<script>!(function () {
let e = document.createElement("script"),
t = document.head || document.getElementsByTagName("head")[0];
(e.src =
"https://cdn.jsdelivr.net/npm/[email protected]/lib/index.js"),
// Replace 1.x.x with the version that you want
(e.async = !0),
(e.onload = () => {
window.WebChat.default(
{
params: { storage:"session"},
title: "TestBot",
initPayload: 'hello',
customData: { language: "en" },
socketUrl: "https://testlink.com",
inputTextFieldHint: "Ask question here",
// add other props here
},
null
);
}),
t.insertBefore(e, t.firstChild);
})();
</script>
I am trying to pass the user role to the initPayload
attribute. But I am really having trouble here understanding how to actually run and store the result of the php code.
I would really appreciate some help!