Support » Plugin: WPBook » [Plugin: WPBook] Patch to allow publish as FB note

  • I have modified WPBook 2.0.13 to allow the user to select if he wants to publish the post as a note in FB instead as a single stream. Also I modified the cron to allow read comments from notes and streams.

    Any suggestion would be wellcome.

    ************ The patch starts here ************
    diff -urp wpbook/includes/publish_to_facebook.php wpbook_new/includes/publish_to_facebook.php
    — wpbook/includes/publish_to_facebook.php 2011-02-21 11:22:30.000000000 -0500
    +++ wpbook_new/includes/publish_to_facebook.php 2011-03-04 14:49:38.000000000 -0500
    @@ -16,13 +16,14 @@ function wpbook_safe_publish_to_facebook

    $api_key = $wpbookAdminOptions[‘fb_api_key’];
    $secret = $wpbookAdminOptions[‘fb_secret’];
    – $target_admin = $wpbookAdminOptions[‘fb_admin_target’];
    – $target_page = $wpbookAdminOptions[‘fb_page_target’];
    – $stream_publish = $wpbookAdminOptions[‘stream_publish’];
    – $stream_publish_pages = $wpbookAdminOptions[‘stream_publish_pages’];
    – $wpbook_show_errors = $wpbookAdminOptions[‘show_errors’];
    – $wpbook_promote_external = $wpbookAdminOptions[‘promote_external’];
    – $wpbook_attribution_line = $wpbookAdminOptions[‘attribution_line’];
    + $as_note = $wpbookAdminOptions[‘fb_publish_as_note’];
    + $target_admin = $wpbookAdminOptions[‘fb_admin_target’];
    + $target_page = $wpbookAdminOptions[‘fb_page_target’];
    + $stream_publish = $wpbookAdminOptions[‘stream_publish’];
    + $stream_publish_pages = $wpbookAdminOptions[‘stream_publish_pages’];
    + $wpbook_show_errors = $wpbookAdminOptions[‘show_errors’];
    + $wpbook_promote_external = $wpbookAdminOptions[‘promote_external’];
    + $wpbook_attribution_line = $wpbookAdminOptions[‘attribution_line’];
    $facebook = new Facebook($api_key, $secret);

    if((!empty($api_key)) && (!empty($secret)) && (!empty($target_admin)) && (($stream_publish == “true”) || $stream_publish_pages == “true”)) {
    @@ -96,10 +97,16 @@ function wpbook_safe_publish_to_facebook
    $action_links = json_encode($action_links);

    if($stream_publish == “true”) {
    – $fb_response = ”;
    – try{
    – $fb_response = $facebook->api_client->stream_publish($message, $attachment, $action_links,$target_admin,$target_admin);
    – } catch (Exception $e) {
    + $fb_response = ”;
    + try{
    + if($as_note == ‘on’) {
    + $allowedtags = array(‘img’=>array(‘src’=>array(), ‘style’=>array()), ‘span’=>array(‘id’=>array(), ‘style’=>array()), ‘a’=>array(‘href’=>array()), ‘p’=>array());
    + $content = wp_kses(stripslashes(apply_filters(‘the_content’,$my_post->post_content)),$allowedtags);
    + $fb_response = $facebook->api_client->notes_create($my_title, $content, $target_admin);
    + } else {
    + $fb_response = $facebook->api_client->stream_publish($message, $attachment, $action_links,$target_admin,$target_admin);
    + }
    + } catch (Exception $e) {
    if($wpbook_show_errors) {
    $wpbook_message = ‘Caught exception in stream publish for user: ‘ . $e->getMessage() .’Error code: ‘. $e->getCode();
    wp_die($wpbook_message,’WPBook Error’);
    diff -urp wpbook/includes/wpbook_cron.php wpbook_new/includes/wpbook_cron.php
    — wpbook/includes/wpbook_cron.php 2011-02-21 11:22:30.000000000 -0500
    +++ wpbook_new/includes/wpbook_cron.php 2011-03-04 14:54:28.000000000 -0500
    @@ -149,7 +149,11 @@ function wpbook_import_comments() {
    * So far both are inconsistent at best.
    if(WPBOOK_COMMENT_METHOD == ‘comment’) {
    – $fbsql=”SELECT time,text,fromid,xid,post_id FROM comment WHERE post_id=’$mp->meta_value’ AND time > ‘$my_timestamp’ ORDER BY time ASC”;
    + $pos = strpos($mp->meta_value, ‘_’);
    + if ($pos === false)
    + $fbsql=”SELECT time,text,fromid,xid,post_id FROM comment WHERE object_id=’$mp->meta_value’ AND time > ‘$my_timestamp’ ORDER BY time ASC”;
    + else
    + $fbsql=”SELECT time,text,fromid,xid,post_id FROM comment WHERE post_id=’$mp->meta_value’ AND time > ‘$my_timestamp’ ORDER BY time ASC”;
    if(DEBUG) {
    $fp = fopen($debug_file, ‘a’);
    $debug_string=date(“Y-m-d H:i:s”,time()).” : FBcomments, fbsql is $fbsql \n”;
    diff -urp wpbook/wpbook.php wpbook_new/wpbook.php
    — wpbook/wpbook.php 2011-02-21 11:22:30.000000000 -0500
    +++ wpbook_new/wpbook.php 2011-03-04 15:01:20.000000000 -0500
    @@ -106,7 +106,7 @@ function wpbook_getAdminOptions() {

    function setAdminOptions($wpbook_installation, $fb_api_key, $fb_secret,
    – $fb_app_url,$fb_admin_target,$fb_page_target,$invite_friends,$require_email,
    + $fb_app_url,$fb_publish_as_note,$fb_admin_target,$fb_page_target,$invite_friends,$require_email,
    $give_credit,$enable_share, $allow_comments,
    @@ -125,6 +125,7 @@ function setAdminOptions($wpbook_install
    ‘fb_api_key’ => $fb_api_key,
    ‘fb_secret’ => $fb_secret,
    ‘fb_app_url’ => $fb_app_url,
    + ‘fb_publish_as_note’ => $fb_publish_as_note,
    ‘fb_admin_target’ => $fb_admin_target,
    ‘fb_page_target’ => $fb_page_target,
    ‘invite_friends’ => $invite_friends,
    @@ -213,6 +214,7 @@ function wpbook_subpanel() {
    $fb_api_key = $_POST[‘fb_api_key’];
    $fb_secret = $_POST[‘fb_secret’];
    $fb_app_url = $_POST[‘fb_app_url’];
    + $fb_publish_as_note = $_POST[‘fb_publish_as_note’];
    $fb_admin_target = $_POST[‘fb_admin_target’];
    $fb_page_target = $_POST[‘fb_page_target’];
    $invite_friends = $_POST[‘invite_friends’];
    @@ -277,7 +279,7 @@ function wpbook_subpanel() {
    – setAdminOptions(1, $fb_api_key, $fb_secret, $fb_app_url,$fb_admin_target,$fb_page_target,
    + setAdminOptions(1, $fb_api_key, $fb_secret, $fb_app_url,$fb_publish_as_note,$fb_admin_target,$fb_page_target,
    @@ -306,7 +308,7 @@ function wpbook_subpanel() {
    //set the “smart” defaults on install this only works once the page has been refeshed
    if ($wpbookAdminOptions[‘wpbook_installation’] != 1) {
    $gravatar_default = WP_PLUGIN_URL .’/wpbook/theme/default/gravatar_default.gif’;
    – setAdminOptions(1, null,null,null,null,null,true,true,true,true,true,top,null,null,”F j, Y”,”g:i a”,
    + setAdminOptions(1, null,null,null,null,null,null,true,true,true,true,true,top,null,null,”F j, Y”,”g:i a”,
    @@ -382,6 +384,10 @@ function wpbook_subpanel() {
    echo ‘ id=”set_1″ > Publish new posts to YOUR Facebook Wall ‘;
    + echo ‘<p class=”wpbook_hidden wpbook_option_set_1 sub_options”>Publish as Notes: <input type=”checkbox” name=”fb_publish_as_note” ‘;
    + if($wpbookAdminOptions[‘fb_publish_as_note’] == ‘on’) echo ‘checked’;
    + echo ‘ >’;
    + echo ‘</p>’;
    echo ‘<p class=”wpbook_hidden wpbook_option_set_1 sub_options”>YOUR Profile ID: <input type=”text” name=”fb_admin_target” value=”‘;
    echo htmlentities($wpbookAdminOptions[‘fb_admin_target’]) .'” size=”15″ /> <span id=”grant_profile_permissions”></span>’;
    /* this should be done by the Javascript now if that doesn’t work uncomment these lines
    ********** The patch ends here ********

Viewing 10 replies - 1 through 10 (of 10 total)
  • Plugin Author John Eckman


    Not sure what you mean by:

    publish the post as a note in FB instead as a single stream

    Is this a per-post option, or a global one?

    What difference does it make to post as a Note, as opposed to as an item in the stream?

    In 2.1 we’ll be converting to the OAuth and Graph API version of the FB SDK, so the whole plugin will change . . .

    Some people prefer to read a post in Facebook instead have to go to other sites to read it. In my case I have more comments from a post when it is published as a note in FB than wrote only in the site.

    When it is only a stream the users have to go to the site to read the rest of the post, and I don’t know why but they don’t write comments…. I think it is because people use to share things in FB but they don’t like to share ideas outside it. I have modified your plugin to allow this change, and now I have more comments than ever when I publish a new post.

    I have tested this change in a Scout too and now they have more comments.

    If you are going to change the plugin I would like to see this capability, or if you require it I can create the patch in the next release.

    Kind regards.

    Plugin Contributor Brooke


    If I understand this right the plugin (optionally) pulls the post in as a note then can also retrive comments from the note? Right now I use, and contrube to,Facebook Comments TNG which will pull in comments from notes back into WordPress. It does require you to manually enter the feed import url inside Facebook.

    I think that if your patch was modified to allow BOTH stream and note publish (optionally) instead of one OR the other that could be useful. It would also eleminate the need for me to use that plugin. I think it would even allow for users to import more than one feed as notes.

    Thanks for the patch. I’ll play around with it and see what I come up with.

    Plugin Author John Eckman



    I’ve been working on 2.1b, so the current ‘trunk’ is kind of a mixed bag – if you want to play around with the patch do so against 2.0.13, but know we’ll need to revisit when 2.1 is ready.

    (2.1 will use OAuth and the new Graph API, so posting as a note will still be possible but will be done differently – all posting and importing of comments will be done with the Graph API not the old Facebook Rest API.)

    Plugin Author John Eckman


    @sebaxtyian Any chance you could create a patch against 2.1b1?

    It’s on the “other releases” page off the download page on

    Plugin Author John Eckman


    FWIW, though, people don’t have to go “to the site” to read the posts – if you do NOT choose “use external permalinks” then people only have to go to the Facebook Application view to read the post – not to the external site.

    Just clearing that up for others reading the thread . . .

    Any chance you could create a patch against 2.1b1?

    Ok, I will create the patch against 2.1b1

    people don’t have to go “to the site” to read the posts

    You are right. My fault.

    It is just I prefer to publish the posts as notes because I used to have my site and FB linked using RSS, and with WPBook + Patch I get the same behavior plus the linked comments.

    Plugin Author John Eckman


    Just checked in a 2.1b2 with this patch incorporated.

    Does it make sense to also try to publish to a page as a note? That did not seem to work in my initial testing.

    I have donwloaded 2.1b2 5 days ago and I couldn’t send a stream to my FB account. I’ll check again.

    Plugin Author John Eckman


    If you downloaded five days ago that was 2.1b1, this 2.1b2 is newer.

    Did you follow the release instructions here:

    Because of the change in auth protocols and libraries there are changes you have to make and permissions to be granted, even if you had previously done so.

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘[Plugin: WPBook] Patch to allow publish as FB note’ is closed to new replies.