{"id":1344,"date":"2012-07-09T14:10:02","date_gmt":"2012-07-09T17:10:02","guid":{"rendered":"http:\/\/wordpress.matbra.com\/?p=1344"},"modified":"2012-07-14T21:22:54","modified_gmt":"2012-07-15T00:22:54","slug":"adicionando-eventos-ao-plugin-total-facebook","status":"publish","type":"post","link":"https:\/\/wordpress.matbra.com\/en\/2012\/07\/09\/adicionando-eventos-ao-plugin-total-facebook\/","title":{"rendered":"Adicionando eventos ao Plugin Total Facebook"},"content":{"rendered":"<p>Last week I searched a lot and tested different plugins to add facebook comments and like buttons. The one that I most liked was  <a href=\"http:\/\/wordpress.org\/extend\/plugins\/total-facebook\/\" target=\"_blank\">Plugin Total Facebook<\/a>, it is easy and have good position settings.<\/p>\n<p>Right now, the facebook does not notificate you about new comments or like that your post receives, so I decided to code this using <a href=\"https:\/\/developers.facebook.com\/docs\/reference\/javascript\/\" target=\"_blank\">Javascript SDK<\/a>. I used the event interface to know when somebody Like or Comment on your publication. <\/p>\n<p><!--more--><\/p>\n<p>A lot of my tests returned the FB object was inexistent (Uncaught ReferenceError: FB is not defined), the FB.init was already called (FB.init has already been called &#8211; this could indicate a problem) and other erros. So i modified the function fbsdk_includeWFC() to do the init async and add a function to be called when a &#8220;edge.create&#8221; (Like) event or &#8220;comment.create&#8221; (Comment) event are done. <\/p>\n<p>[code lang=&#8221;php&#8221;]<br \/>\nfunction fbsdk_includeWFC(){<br \/>\n    $wfcglb = get_option(&#8216;wfc_global&#8217;);<br \/>\n    echo  &#8221;<\/p>\n<div id=\\\"fb-root\\\"><\/div>\n<p><script><\/p>\n<p>window.fbAsyncInit = function() {\n    FB.init({\n      appId      : '\" . $wfcglb['appid'] . \"', \/\/ App ID\n      \/\/channelUrl : '\/\/WWW.YOUR_DOMAIN.COM\/channel.html', \/\/ Channel File\n      status     : true, \/\/ check login status\n      cookie     : true, \/\/ enable cookies to allow the server to access the session\n      xfbml      : true  \/\/ parse XFBML\n    });<\/p>\n<p>FB.Event.subscribe('comment.create', function (response) {\n        jQuery.ajax({\nurl: 'test.html',\n\/\/success: function (data) { alert(response.href); },\n\/\/error: function (data) { alert(response.href); }\n});\n    });\n };<\/p>\n<p>FB.Event.subscribe('edge.create', function (response) {\n        jQuery.ajax({\nurl: 'test2.html',\n\/\/success: function (data) { alert(response); },\n\/\/error: function (data) { alert(response); }\n});\n    });\n };<\/p>\n<p>(function(d){\n     var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];\n     if (d.getElementById(id)) {return;}\n     js = d.createElement('script'); js.id = id; js.async = true;\n     js.src = '\/\/connect.facebook.net\/en_US\/all.js';\n     ref.parentNode.insertBefore(js, ref);\n   }(document));<\/script>&#8220;;<\/p>\n<p> echo &#8220;<!-- added by facebook total plugin -->&#8220;;<br \/>\n}<br \/>\n[\/code]<\/p>\n<p>Now you can modified the &#8220;url&#8221; from ajax calls to call a php url and pass parameters, and with this parameters send you an e-mail for example.<\/p>\n<p>Hope this is useful for you <\/p>\n<p>Matheus<\/p>","protected":false},"excerpt":{"rendered":"<p>Last week I searched a lot and tested different plugins to add facebook comments and like buttons. The one that I most liked was Plugin<\/p>\n<div class=\"more-link-wrapper\"><a class=\"more-link\" href=\"https:\/\/wordpress.matbra.com\/en\/2012\/07\/09\/adicionando-eventos-ao-plugin-total-facebook\/\">Continue reading<span class=\"screen-reader-text\">Adicionando eventos ao Plugin Total Facebook<\/span><\/a><\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[69,65],"tags":[258,255,257,229,256],"class_list":["post-1344","post","type-post","status-publish","format-standard","hentry","category-php","category-wordpress","tag-event","tag-facebook","tag-javascript-sdk","tag-plugin","tag-total-facebook","entry"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/psjGE-lG","_links":{"self":[{"href":"https:\/\/wordpress.matbra.com\/en\/wp-json\/wp\/v2\/posts\/1344","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.matbra.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wordpress.matbra.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wordpress.matbra.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/wordpress.matbra.com\/en\/wp-json\/wp\/v2\/comments?post=1344"}],"version-history":[{"count":10,"href":"https:\/\/wordpress.matbra.com\/en\/wp-json\/wp\/v2\/posts\/1344\/revisions"}],"predecessor-version":[{"id":1383,"href":"https:\/\/wordpress.matbra.com\/en\/wp-json\/wp\/v2\/posts\/1344\/revisions\/1383"}],"wp:attachment":[{"href":"https:\/\/wordpress.matbra.com\/en\/wp-json\/wp\/v2\/media?parent=1344"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wordpress.matbra.com\/en\/wp-json\/wp\/v2\/categories?post=1344"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wordpress.matbra.com\/en\/wp-json\/wp\/v2\/tags?post=1344"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}