public function testGeneratedHtml() { $settings = new SnippetSettings(array("app_id" => "foo", "name" => "Nikola Tesla"), NULL, NULL, array()); $snippet = new Snippet($settings); $expectedHtml = <<<HTML <script data-cfasync="false"> window.intercomSettings = {"app_id":"foo","name":"Nikola Tesla"}; </script> <script data-cfasync="false">(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/foo';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> HTML; $this->assertEquals($expectedHtml, $snippet->html()); }
function add_intercom_snippet() { $options = get_option('intercom'); $raw_data = array("app_id" => WordPressEscaper::escJS($options['app_id'])); if ($options['enableChat'] === 'true') { $raw_data['widget']['activator'] = '#IntercomDefaultWidget'; } $snippet_settings = new SnippetSettings((array) apply_filters('intercom_snippet_rawdata', $raw_data), WordPressEscaper::escJS($options['secret']), wp_get_current_user()); $snippet = new Snippet($snippet_settings); echo $snippet->html(); }
function add_intercom_snippet() { $options = get_option('intercom'); $snippet_settings = new SnippetSettings(array("app_id" => WordpressEscaper::escJS($options['app_id'])), WordpressEscaper::escJS($options['secret']), wp_get_current_user()); $snippet = new Snippet($snippet_settings); echo $snippet->html(); }