WordPress and Facebook Integration
I’d been using the Wordbook app for quite a bit but I’d always found that it lacked some features that I liked. I’ve now added these functions and got it doing things how I’d like.
So rather than keep cluttering up the original wordbook application page I’ve forked by code off totally.
I created a new Facebook application called Wordbooker and then created a new plugin called Wordbooker in the WordPress Extensions site.
Upgrading from the Forked Version.
As this is basically a new application its a bit messy as doing a normal removal of the old forked version will remove any record of posts/comments made with the forked version.
If you wish to retain that history then you need to back up the existing wordbook_postcomments table BEFORE you remove the forked version of wordbook.
Go into the options page for Wordbook and reset the configuration for wordbook
From the plugins page de-activate the wordbook plugin.
Delete the wordbook directory from wp-content/plugins
Upload the wordbooker directory into the wp-content/plugins directory
Go into the Plugins page and enable Wordbooker.
Go to the options page for Wordbooker and it will ask you to get a login key from Facebook and then ask you to grant two extra permissions needed by Wordbooker – these allow Wordbooker to publish to your wall and also to fetch comments from it.
Click on the Save Configuration button.
You can then set up the various options on the option screen:
** Multiple Facebook account / WordPress account support **
If you as the blog owner only want it so that WP posts go to your FB account then go into the Options screen and set the default account to be yours, and that should be it, any person using a different WP account to post to your blog will publish those stories to your FB account.
But what if you’ve got a Family WB where different people would like to post to WP and to their OWN FB accounts. Simply get each of them to login to WP as themselves and configure WB as if they were the only user. Then when all of them have done this go back in as yourself and set the Default account to be you.
On the Edit Post page there is a WordBook Options block which includes a drop down list of the blog you wish to post to, if you want to post to your default blog then you don’t need to touch this but if someone wants to post that post to their FB account all they need to do is pick their name from the drop down list before they post.
** Length of Extract **
This allows you to change the length of the extract posted to Facebook. The minimum value is 200 and the maximum is 400 (at the moment) with the default being 256 characters. The extract will be trimmed to the nearest full word BELOW this value.
** Default Publish Post to Facebook **
This allows you to choose if posts should automatically be posted to Facebook. This option can be overridden from the Edit Post page
** Post Attribute **
This allows you to change the attribute line when posts are sent to Facebook. By default this is set to “Posted a new post on their blog”. This option can be overridden from the Edit Post page.
** Republish Post if edited more than x days ago **
This allows you to control how long it should be before Wordbook considers an edited post to be a “new” post and re-publishes it to Facebook.
** Override Re-Publication window **
This allows to to force all edits to be reposted to Facebook ignoring the republish window. This option can be overridden from the Edit Post page.
** Update Facebook Status **
If this option is checked then the title of your blog post and its permalink will be posted to your status, along with the text specified here. This can be overridden from the Edit Post page. NOTE: If this option is Selected then your status is ALWAYS updated, even if you choose NOT to publish your post to Facebook.
** Import Comments from Facebook for Wordbook Posts **
This version of Wordbook supports the importing of comments made on Facebook back into your WordPress blog. This allows you to set the default behaviour. This option can be overridden from the Edit Post page
** Auto Approve imported comments **
If you trust your friends on Facebook then you’re probably quite happy for their comments to automatically get posted as comments on your WordPress blog. If this option is not set then any imported comments are held in the moderation queue.
Once you’ve got the options set how you want then save them.
If you exported the wordbook_postcomments table before upgrading then you can now import it back into the database.
There may be times when you you are posting a blog entry and you’d like to do something differently, like NOT publish a post, or change your choice on what you do with comment. So on the Add New and Edit posts page you should now find a Wordbooker Options Override block where you can override several defaults:
If you are the administrator of a Facebook Fan page then you’ll also be given the option of posting to that page instead of posting to your own wall. At the moment there is a bug in the API which means that posts made to Fan Pages are shown as YOU posting on the Fan Page wall – rather than it looking like the Fan Page has posted the post directly.
PROBLEMS
If you’ve got problems its probably best to post them on the Wordbooker Page on Facebook where people can create new threads for each bug/problem and people can easily see if any fixes have been made


January 2nd, 2010 at 6:53 pm
Hi Steve
Your plugin looks interesting. I have a question re advertising opportunites, but couldn’t find any contact info. Please can you email me.
Thanks
Gareth
January 2nd, 2010 at 6:59 pm
What do you mean advertising opportunities?
January 2nd, 2010 at 9:34 pm
Hi -
This looks great.
Question: How many images are included in the facebook excerpt of wordpress post?
Also, does this produce a duplicate post that would interfere with search rating?
Thank you for your work!
January 2nd, 2010 at 9:36 pm
I think Facebook supports 4 or 5 images max. They keep changing their minds.
January 2nd, 2010 at 9:43 pm
how about the duplicate post issue – is that something to be concerned about?
January 2nd, 2010 at 9:46 pm
What duplicate post? All this basically does is share an extract of your blog post on your facebook profile. So all its doing is directing people from FB who follow your wall that you’ve posted a blog entry.
January 3rd, 2010 at 3:37 pm
Great idea, but not working on my blog. Returns the following error:
Parse error: syntax error, unexpected ‘{‘ in /hermes/bosweb/web254/b2541/sl.nicobeth/public_html/blogworld/wp-content/plugins/wordbooker/wordbooker.php on line 143
Does the blog have to be running on a particular version of PHP? My host is still using version 4, which is causing some plugin issues.
I love the idea and would like to get the thing working — I do a lot of work on FB and WP and would LOVE for them to talk to one another.
http://wordpress.org/extend/plugins/wordbooker/
January 3rd, 2010 at 3:54 pm
Nicolette, unfortunately it can’t be run against PHP4 – Facebook no longer support PHP4 in their API libraries and I’ve been running on PHP5 for well over a year now.
Support for PHP 4 has been discontinued since 2007-12-31 according to the PHP website so really your host needs to kicked into doing something.
Sorry I can’t help further.
Steve
January 3rd, 2010 at 5:03 pm
Thought that might be the case.
Major bummer.
January 3rd, 2010 at 5:12 pm
I think that WP will soon be moving to PHP5 only, and it seems that they’ve done a lot of stuff to keep it running on PHP4but would like people to move to PHP5
http://wordpress.org/support/topic/316394?replies=14
January 3rd, 2010 at 6:44 pm
Hi Stephen,
happy new year.
i am trying to config ‘wordbooker’ by getting the code from facebook. every time I try (after I log in) I get the “oops, Facebook was not able to generate the code, try back later”
any suggestions?
January 3rd, 2010 at 6:48 pm
There is something going on with FB right now – I’m unable to make any changes to my app page. Is the error you are getting on the FB page (the one that opens in a new window when you click on the icon on the Wordbooker options page)?
January 3rd, 2010 at 8:37 pm
Yes ’tis indeed.
January 3rd, 2010 at 9:40 pm
I am not able to obtain the one-time code.
Best regards, Phil
January 3rd, 2010 at 9:48 pm
Thats a FB problem – nothing to do with my code. Whole parts of the FB back end don’t seem to be behaving properly at the moment.
January 3rd, 2010 at 9:50 pm
THX for the “speedy” answer!
January 3rd, 2010 at 11:00 pm
It might work now – the application profile has now re-appeared
January 4th, 2010 at 12:07 am
It works!
January 4th, 2010 at 11:22 am
Hello, great apps! thanks for the work!
Few questions. 1. I have tried to import posts with Chinese (Traditional) text, and in that case it would only grab the first 10 or so characters (even if I say 200). I then tested it by replacing english test on the same post and re-post, and it grab more text. Anything I could do?
2. I have Chinese text and then a Youtube video on the post, and then some jpg. The plugin didn’t grab the photo in the first go (unless I press “see more”). But if I repost with the jpg on top, the picture is shown. Anything I could do?
Thanks!!
January 4th, 2010 at 11:26 am
Oh, question 3,
If I post more than 1 post and feed to Facebook in a row, the Live Feed would only show the latest one? Is that a restriction of Facebook stopping outsiders feed? (coz I could manually posts multiple links of my blog myself and the Live feed would show them all!)
January 4th, 2010 at 11:36 am
1) I’m not sure – I’ve no idea how mysql and php (or indeed the Facebook API) handles traditional Chinese. Does the small bit of Chinese end with a set of dots? If it does then its my code that trims the post down causing problems.
2) Not sure about this one, I haven’t coded for emebedded video as I dont think the FB API handles it, but its obviously doing something odd. By default FB only displays one image now until you click on “see more”.
3) What you will probably find is that FB rolls them up into a block and you’ll see the latest post with a “See x similar posts” underneath it. That’s what I get when I’m testing it.
January 4th, 2010 at 2:14 pm
Steve:
1. Yes, with 3 dots at the tail. And other applications (including the original Facebook URL import) does show much more chinese text in the box.
2. And, I don’t want to see the video. I would rather the software could jump and grab the first photo available and make it as thumbnail of the post.
3. You mean under the “read entire article” link? no, I don’t see the ““See x similar posts” line there in the Live Feed. (but I do see all the posts separately one by one in my own profile.)
Cheers,
January 4th, 2010 at 2:27 pm
OK – its something to do with my code then.
I do :
$excerpt=current(explode(“\r”, wordwrap($excerpt, $maxlength, “\r”))).” …”;
So at a guess there are some “\r” buried in the code somewhere, or something that is tripping it up. I’ll have to look into that.
Are you using GBK-encoding by any chance?
2) I’ll have to dig into it and see if I can get it to do it for me.
3) OK, that’s odd because when I post to my test account they get rolled up with a “similar post” message when they appear on the live feed of my normal account.
January 4th, 2010 at 2:42 pm
1) OK I think I’ve worked out a fix for the string splitting.
2) How are you embedding the Youtube video?
3) Multiple posts from by test blog show up in my real account live feed with no problems.
January 4th, 2010 at 2:56 pm
Hi steve,
ran into a permission problem with FB first time out, error =200. any suggestions?
January 4th, 2010 at 3:02 pm
200 is a permissions error. Can you see if wordbooker has been added to your list of application with extended permissions inside Facebook.
Where did you get the 200 error? Was it during set up? Did the options page ask you to grant two additional permissions?
January 4th, 2010 at 3:09 pm
i received the error with my first post using the plugin. i did get the code last evening from FB and did the verification, and I received the “status” back along with my profile pic. should I find the app on FB and add it to my list of apps?
January 4th, 2010 at 3:16 pm
sorry for the addendum,
FB says that Wordbooker is ‘under construction’
January 4th, 2010 at 3:22 pm
Hmm thats odd
http://www.facebook.com/apps/application.php?id=254577506873
is its URL and its working fine for other people apparently.
Do you get your current FB status and picture when you go to the options page?
Can you remove it from your extended apps on your profile and then go into the options screen inside WordPress and do the “reset” and go through the authorisation process. There were problems with the app profile last night which might have broken things.
January 4th, 2010 at 3:26 pm
I do get my profile pic and recent status on the options page. I will go ahead and reset everything. and give you an update here rather than FB
January 4th, 2010 at 3:32 pm
Bingo. I guess last nite I was just a wee bit behind the updates.
many thanx steve.
January 4th, 2010 at 3:34 pm
OK – so its got the read privs, just not the write ones.
You could just try using the following two urls:
http://www.facebook.com/authorize.php?v=1.0&api_key=0cbf13c858237f5d74ef0c32a4db11fd&ext_perm=publish_stream
http://www.facebook.com/authorize.php?v=1.0&api_key=0cbf13c858237f5d74ef0c32a4db11fd&ext_perm=read_stream
January 4th, 2010 at 3:37 pm
done deal.
thanx again. now go have a sandwich
January 5th, 2010 at 6:04 am
Steve:
my characters should be in unicode UTF-8.
If you have any updates, I could help to test it again.
Cheers,
January 5th, 2010 at 7:38 pm
thanks. but it seems the effect is the same.
http://www.facebook.com/leonard.s.ng?ref=profile
January 5th, 2010 at 8:02 pm
OK, I’ve looked at the source of your page.
Can you edit the wordbooker.php file
Find the wordbook_post_excerpt function which should look like this:
function wordbook_post_excerpt($content, $maxlength) {
$excerpt = apply_filters(‘the_excerpt’, $content);
if (function_exists(‘strip_shortcodes’)) {
$excerpt = strip_shortcodes($excerpt);
}
#$excerpt = strip_tags($excerpt,”);
$excerpt = strip_tags($excerpt);
if (strlen($excerpt) > $maxlength) {
## Changed to stop Traditional Chinese being broken at the wrong place. Hopefully no-one will ever use this string.
$excerpt=current(explode(“SJA26666AJS”, wordwrap($excerpt, $maxlength, “SJA26666AJS”))).” …”;
}
return $excerpt;
}
and change it to look like :
function wordbook_post_excerpt($content, $maxlength) {
$excerpt = apply_filters(‘the_excerpt’, $content);
if (function_exists(‘strip_shortcodes’)) {
$excerpt = strip_shortcodes($excerpt);
}
#$excerpt = strip_tags($excerpt,”);
$excerpt = strip_tags($excerpt);
var_dump($excerpt);
if (strlen($excerpt) > $maxlength) {
## Changed to stop Traditional Chinese being broken at the wrong place. Hopefully no-one will ever use this string.
$excerpt=current(explode(“SJA26666AJS”, wordwrap($excerpt, $maxlength, “SJA26666AJS”))).” …”;
}
return $excerpt;
}
Then save it and do another test post and it should dump the excerpt onto the web browser.
Does it just contain your text or is there a large chunk of Javascript at the start.
January 5th, 2010 at 8:22 pm
it says
“Parse error: syntax error, unexpected T_STRING in /home/ngszehin/www/www/wp-content/plugins/wordbooker/wordbooker.php on line 1256″
when I attempted to save the php.
January 5th, 2010 at 8:52 pm
Gees!!! I guess it works!
It didn’t work with the posts that I have tested before, because I guess Facebook remembers it. However, I have tried (and you could see that in my profile now) another old post, and it works!
Thanks so much! And hope you enjoy the process yourself too!
January 5th, 2010 at 8:56 pm
Thats great – it was actually down the way I was processing the post data, so anyone who had the plugin that puts the “Welcome Facebook” block into your posts would have had the same problem.
If you go onto Facebook and delete the posts you can then go back into your blog, edit the old posts and just select the “Force Re-Publish Post to Facebook on Edit (overrides republish window)” option on the Wordbooker options block on the Edit Post Page and then click Update Post and it will republish them to Facebook.
January 5th, 2010 at 9:03 pm
and by the way, I would like to ask if you know there is any plugin (or otherwise you could write one) that could generate a list or index of posts in my selected category, with a thumbnail that is fetched from the external linked (liked how Facebook grab my image when we post the link there) (I hosted my photos in Fotki.com instead of my local host of WP)?
The purpose is, I would like to build a table of contents with thumbnails of all the posts which has the photos of my sons (currently under the same category). Currently I am using a simple plugin called “List Category posts” (http://picandocodigo.net/programacion/wordpress/list-category-posts-wordpress-plugin-english/) to make the table of content pages (http://ngszehin.net/entertainment/). I also have that for the photos posts (http://ngszehin.net/baby/) but I would like this to be in thumbnails instead of words. Could you think of the easiest method for this?
Cheers,
January 5th, 2010 at 9:21 pm
Have you tried asking over on the WordPress support forums http://wordpress.org/support/
January 5th, 2010 at 9:30 pm
I have tried, but no answer. So nothing pops up from your mind related to this? Or are you able to write a simple code to do this? hee hee….
January 5th, 2010 at 9:40 pm
Nothing pops up in my mind. I’m a bit busy with wordbooker and other stuff that is internal to my blog (integration with my brothers web site).
January 5th, 2010 at 9:59 pm
thanks anyway! And good work with the Wordbooker. A really nice integration indeed!
January 5th, 2010 at 10:27 pm
Thanks, and if you want to suggest more features then the discussion tab on the app profile is the best place to do it.
January 7th, 2010 at 11:36 pm
Awesome plugin, I just switched to this from Wordbook. Can’t wait for the Fan page part to work correctly!
January 8th, 2010 at 8:15 am
As soon as the bug ( http://bugs.developers.facebook.com/show_bug.cgi?id=8184 ) is fixed I’ll test it and release a fix.
January 9th, 2010 at 2:37 am
hi mate, it was working just fine for a few days now. So happy. Just 2 questions.
1. Should I expect the Wordbooker to work for my scheduled future posts? Coz I tried and didn’t work, but not sure if I have the correct setting.
2. If there is a comment on Facebook, then the comment is fed to the blog with no problem. But if the comment is left on the blog, then firstly the comment would be fed to facebook first, but then it would be fed back to the blog again. So I end up having a double for that comment. Is this normal?
January 9th, 2010 at 9:52 am
1) I’d not coded it for future made posts – but I can look into it and see how difficult it would be to add it in.
2) Its a bug which will be fixed in 1.5. There is a quick fix for it which I documented here : http://www.facebook.com/apps/application.php?v=app_2373072738&ref=nf&id=254577506873#/topic.php?uid=254577506873&topic=11923
January 11th, 2010 at 3:23 am
Thank you, Steve! I’m not a very technical person, but I was able to install and run this successfully without a hitch. This is really lovely!