Untitled
unknown
javascript
a year ago
976 B
8
Indexable
function add_custom_js_for_canvas_users() { // Check if the user agent contains 'canvas' (case insensitive) if (strpos(strtolower($_SERVER['HTTP_USER_AGENT']), 'canvas') !== false) { if (is_user_logged_in()) { // Get the current user $current_user = wp_get_current_user(); // Get the user email $user_email = $current_user->user_email; } else { // User is logged out, set user email to empty $user_email = ''; } // Output the script in the footer section echo " <script> document.addEventListener('DOMContentLoaded', function() { setTimeout(function() { nativeFunctions.onesignalSetExternalUserId('$user_email'); }, 1000); // Delay by 1000 milliseconds (1 second) }); </script> "; } } add_action('wp_footer', 'add_custom_js_for_canvas_users');
Editor is loading...
Leave a Comment