Last active
July 27, 2019 12:36
-
-
Save marktenney/c2685b7b5bc314caebcc7f29df77de4b to your computer and use it in GitHub Desktop.
Add intercom messenger to any network users who have admin access.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/****** Add Intercom ********/ | |
/****** Be sure to add your APP ID on lines 12 + 29 ******/ | |
add_action('wp_enqueue_scripts', 'dgtl_enqueue'); // This action adds the messenger to the front end. | |
function dgtl_enqueue() { | |
if ( current_user_can('edit_posts') ) { // Only run messenger if user can edit posts (contributor+). | |
global $current_user; | |
$current_user = wp_get_current_user(); | |
?> | |
<script> | |
window.intercomSettings = { | |
app_id: "", // Add the App ID for your Intercom Account here | |
name: '<?php $current_user = wp_get_current_user(); | |
echo $current_user->display_name; ?>', | |
email: '<?php $current_user = wp_get_current_user(); | |
echo $current_user->user_email; ?>', | |
custom_launcher_selector: '.dgtl-intercom-support' // This allows you to have a button class to launch | |
}; | |
</script> | |
<script>(function(){var w=window;var ic=w.Intercom;if(typeof ic==="function"){ic('reattach_activator');ic('update',intercomSettings);}else{var d=document;var i=function(){i.c(arguments)};i.q=[];i.c=function(args){i.q.push(args)};w.Intercom=i;function l(){var s=d.createElement('script');s.type='text/javascript';s.async=true;s.src='https://widget.intercom.io/widget/tfug2fqr';var x=d.getElementsByTagName('script')[0];x.parentNode.insertBefore(s,x);}if(w.attachEvent){w.attachEvent('onload',l);}else{w.addEventListener('load',l,false);}}})()</script> | |
<?php | |
} | |
} | |
add_action('admin_enqueue_scripts', function(){ | |
?> | |
<script> | |
window.intercomSettings = { | |
app_id: "", // Add the App ID for your Intercom Account here | |
name: '<?php $current_user = wp_get_current_user(); | |
echo $current_user->display_name; ?>', | |
email: '<?php $current_user = wp_get_current_user(); | |
echo $current_user->user_email; ?>', | |
custom_launcher_selector: '.dgtl-intercom-support' | |
}; | |
</script> | |
<script>(function(){var w=window;var ic=w.Intercom;if(typeof ic==="function"){ic('reattach_activator');ic('update',intercomSettings);}else{var d=document;var i=function(){i.c(arguments)};i.q=[];i.c=function(args){i.q.push(args)};w.Intercom=i;function l(){var s=d.createElement('script');s.type='text/javascript';s.async=true;s.src='https://widget.intercom.io/widget/tfug2fqr';var x=d.getElementsByTagName('script')[0];x.parentNode.insertBefore(s,x);}if(w.attachEvent){w.attachEvent('onload',l);}else{w.addEventListener('load',l,false);}}})()</script> | |
<?php | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment