SSO in Wordpress
To implement SSO in Wordpress so that users logged-in your wordpress sites get automatically logged-in to Dead Simple Chat, follow this guide.
In this Guide we use the Dead Simple Chat Basic SSO and Login the Users into the Dead Simple Chat, Chat Room who are already logged-in to Wordpress.
    1.
    Login to your Wordpress dashboard and open themes editor Appearance → Theme Editor
    2.
    The edit Theme Functions file (functions.php)
    3.
    Add the following code on top of the file
1
function hook_javascript() {
2
if(is_user_logged_in()) {
3
$output="<script> window.userObject = ".json_encode(wp_get_current_user()).";</script>";
4
echo $output;
5
} else {
6
$output="<script> window.userObject;; </script>";
7
echo $output;
8
}
9
}
10
add_action('wp_head','hook_javascript')
Copied!
functions.php with Dead Simple Chat SSO snippet
4. The open Theme Footer file (footer.php) and paste the following code in the footer
1
<script type="text/javascript">
2
var frames = document.getElementsByClassName("myFrame");
3
for (var i =0; i < frames.length; i++) {
4
frames[i].src = frames[i].src + "?username=" + userObject.data.user_nicename;
5
}
6
</script>
Copied!
footer.php with Dead Simple Chat SSO snippet
5. Now get the embed code of your chat room from the Dead Simple Chat Dashboard
Dead Simple Chat Dashboard with Embed Code
Paste the iFrame code wherever you like to the chat on your Wordpress site, it can be added as a Custom HTML block, but add the class="myFrame" to the iFrame.
1
<iframe class="myFrame" src="https://deadsimplechat.com/JmWhoSUBX" width="100%"
2
height="500px"></iframe>
Copied!
6. That's it! Now the user will be automatically logged-in to the chatroom when are logged-in to your site.
Last modified 1mo ago
Copy link