June 29 2010
WP-RESTful WordPress Plugin
Tagged Under : api, extension, networking, plugin, rest, restful, Wordpress
Hello!
I’m 99% sure that you already heard about APIs or REST APIs, it’s what Twitter, flickr and a lot more companies use to share they’re resources with a consumer.
A consumer can be anything from a website (for example, showing your Twitter updates on your blog or personal website) to a desktop / mobile application (iPhone, Android, Windows Mobile, …).
This is possible because all information sent to and from the API is encoded in either two common, inter-platform language, XML and JSON.
The difference between a regular API and a REST API is on the way they work. A REST API requires two entities to work, a client and a server.
Download WP-RESTful (Version 0.1)
Download WP-RESTful Users Plugin (Version 0.1)
Download WP-RESTful Categories Plugin (Version 0.1)
Download WP-RESTful Tags Plugin (Version 0.1)
Follow me for real-time updates
How does it work?
WP-RESTful uses OAuth, a widely, commonly and open source API implementation used all over the World (Wide Web).
The way it work is fairly simple.
First a Consumer registers with a Server. At this point the Server will provide the Consumer with 2 tokens, a public and a private token. The public token will be used to communicate and identify the Consumer with the Server while the private token will be stored locally for security and integrity reasons.
After this the Consumer will request the Server with a Request Token. This Request Token will be used to initiate the Authentication Protocol in where the Consumer will be required to authorize the Server.
The Server will create 2 new token (definitive tokens). They will be our authentication tokens.
I know this sounds and seems complicated but you won’t need to do anything as the Plugin will do almost everything for you (Registration and Authentication process are manual).
Plugin features
- Add new Plugins to API Plugin to extend functionalities to any way you want/need. (See next group)
- Fully manageable Client and Server side.
- Ability to choose what fields are allowed to be returned to the consumer.
- Ability to restrict modules to OAuth authentication process or liberated them and make them open.
- Load balance system where you can specify how many requests a given consumer is allowed in a 60 minute timeframe.
- Out of the box Post and Comments management.
- And much more…
Plugins
As stated on “Plugin Features” you have the ability to develop and/or add new modules to your REST API. This means, for example, if you use a plugin like WP E-Commerce, you can develop a plugin for the REST API in order to provide support for WP E-Commerce resources.
The way these plugins are developed is very similar to how plugins for WordPress are developed.
You can see this video that explains how plugins work and how you can develop them.
Requirements?
All requirements for the plugin to work properly are addressed by the plugin itself, upon activation. You can see your system status on WP-RESTful link after activation the plugin.
How to install?
This plugin is installed like any other WordPress plugin out there.
- First you need to download it from WordPress Plugin Repository.
- Upload the contents of the compacted file to your plugin folder on your WordPress installation.
- Go to your WordPress Administration page and activate the Plugin (Plugins → Installed → WP-RESTful → Activate)
- Create a new page, name it API, set the permalink to /api and set the content as [REST_return] and save the page.
- Go to WP-RESTful → WP-RESTful to check your system status.
I need help!
Check these two videos. They will help you starting up.
This post will be updated, if needed, to reflect changes made to the plugin.













[...] This post was mentioned on Twitter by José P. Airosa, Eurico Leite. Eurico Leite said: RT @joseairosa: WP-RESTful WordPress Plugin | PHP, CSS, HTML, Web & beyond http://bit.ly/ctw1ib [...]
[...] WP-RESTful WordPress Plugin | PHP, CSS, HTML, Web & beyond [...]
Can this plugin be used to interact with other REST APIs from other services such as Google, Freshbooks, Basecamp, etc, etc?
Hello Tony,
Unfortunately no. This plugin is intended to install and have a fully working REST API on your Blog that will let other entities connect to your blog and, in the other hand, will let you connect to other WP-RESTful APIs from other Blogs.
Anyways, I’ve been working on the last few days on what you just asked. I will be releasing a new version of the plugin that will enable this functionality.
Thanks for your feedback!
Great! Specifically – I use WordPress as a centralized project management portal while developing client websites. I’ve been looking for a solution that will pull in various services I use to mange these projects and present them simply in my client portal site – a Google Doc here, a Freshbooks project task list there, etc. Rather than write custom code for each I’m looking to use a framework such as this to add different service APIs to my portal sites. I’m looking forward to watching this WP-RESTful project develop, very solid work here.
Hello Jose,
GREAT work! Congratulations!
Do you have any plan to document the way an external non-wp platform can connect and use the WP-RESTful API of a WP installation.
I realize that a wrapper for it can be a time consuming thing.
Thank you very much,
Clement
And .. I can’t wait to see the next version including the interfacer with other APIs ..
Keep us updated each time you have the chance
Hello Clement,
Thank you for your words
I have provided all the files needed for this on the “API Client PHP” folder. It works exactly as Twitter API works.
I will try to make a screencast on that in the future days.
Best regards!
Wow.. So much work ..
Right. “API Client PHP” is exactly what i need
I’m working on that as we speak
My idea is to provide 2 things:
1- An easy way to develop in-house plugins with oother APIs
2- Provide a working and simple framework for easy connection with external non wp-restful APIs.
I will try to have it ready til the end of the month.
You’ve got a new friend
Thank you,
[...] consultar mais informação na página do Plugin ou directamente no repositório de Plugins do WordPress Share this on [...]
Congratulations for the work with this plugin, really amazing stuff here. Thanks!
Thanks a lot Nuno.
Be sure to check new version by the end of the month
After reading all of the documentation, which it quite impressive, I’m still trying to figure out a good use for this. Can you list a few situations in which I would want to use this framework? The developer above with the multiple clients gives me sort of an idea. Specifically why did you develop this plugin?
Hello Zach,
Thank you for the comment.
I developed this plugin, first of all, out of fun and challenge. Secondly for a few end-game implementations:
- iPhone/Andorid/Windows Mobile app development for your blog
- Blog networking (connect more than one blog that you own to each other)
- Unified login system
- Development of a centralized blog info repository. (this is one thing that I’m thinking of for the future, basically think of this like feed aggregation, but with the possibility of sharing more than only posts… basically you can share almost everything you want from your blog)
- Advertisement system maybe. There surely is an application for this but it needs to be very well thought.
Hello! have you seen this before?
Warning: Cannot modify header information – headers already sent by (output started at /home/dusting/public_html/wp-content/themes/OnDemand/header.php:12) in /home/dusting/public_html/wp-content/plugins/wp-restful/lib/REST.inc.php on line 669
Warning: Cannot modify header information – headers already sent by (output started at /home/dusting/public_html/wp-content/themes/OnDemand/header.php:12) in /home/dusting/public_html/wp-content/plugins/wp-restful/lib/REST.inc.php on line 671
Not Found
The requested URL /api was not found.
I’m trying to work it out as we speak. Any tips would be really appreciated!
Thanks, Dustin!
Hello Dustin.
Thank you for your feedback.
That problem has also been reported by other user and I’m on the way to fix it. I apologize if it’s taking a bit of time but the work at my company has increased a lot in the past few weeks.
Doing my best.
Sorry for the inconvenience.
No worries.. You can drop me a line on twitter when you’ve got it sorted.. @thorstone137
Thanks!
[...] from: WP-RESTful WordPress Plugin | PHP, CSS, HTML, Web & beyond Tags: [...]
Hi,
First, thanks a lot for your plugin ! It is very useful !
I try to use it, with the awesome “WP-RESTful Users Plugin”, to use a worpress as OAuth provider for other sites. Unfortunately, I got the following error when i call user/verify_credentials.json :
Uncaught exception ‘OAuthException’ with message ‘SQL Error in
OAuthStoreMySQL: Unknown column ‘osr_start_time_call’ in ‘field list’
SELECT osr_allowed_calls as allowed_calls,
osr_calls as calls,
osr_last_call as last_call,
osr_start_time_call as start_time_call
FROM wpr_oauth_server_registry
WHERE osr_consumer_key = ‘bbb02fd1177486919d287d120193dcad04ce40a1f’
‘ in /var/www/wordpress/wp-content/plugins/wp-restful/lib/store/OAuthStoreMySQL.php:2167
Stack trace:
#0 /var/www/wordpress/wp-content/plugins/wp-restful/lib/store/OAuthStoreMySQL.php(2043): OAuthStoreMySQL->sql_errcheck(‘??????SELECT?os…’)
#1 /var/www/wordpress/wp-content/plugins/wp-restful/lib/store/OAuthStoreMySQL.php(806): OAuthStoreMySQL->query_row_assoc(‘??????SELECT?os…’, ‘bbb02fd11774869…’)
#2 /var/www/wordpress/wp-content/plugins/wp-restful/lib/store/OAuthStoreMySQL.php(820): OAuthStoreMySQL->getConsumerRequestCount(Array)
Greg
Hello Gregoire!
I’m glad you liked it and you managed to comment
As for the error, for some reason, WP-RESTful is not being able to find the database field required for the action. Please make sure the database is properly installed.
José,
I think it is (properly installed). But if I look in the mysql.sql script (in wp-restful/lib/store/mysql) the table definition for wpr_oauth_server_registry does not have any osr_start_time_call column !?!
Greg
Oh! That might be problem. I will take a look Gregoire and let you know my findings.
It’s peculiar, that often the simplest methods are often the most appropriate! I’ll adopt the above mentioned tips into preparation and wait to see my results. Thank you for sharing this information!
You made some fine points there. I did a search on the matter and found the majority of folks will go along with with your blog.
Les hele bloggen, ganske bra
The core REST plugins work (posts, comments), but when I try to activate any of the wp-restful plugins they are unable to find wpr_add_plugin or wpr_add_pluralization. Any suggestions to fix this?
I moved the wpr_add_* methods to be inside the function that is hooked into the activate_* action and they work now.
Hi I got the below error. How can this be fixed?
Fatal error: Call to undefined function getallheaders() in “wp-restful\lib\OAuthRequestVerifier.php” on line 88
I tried to install it the way you advice and went all alright but when I go to register the client, the server responds with a page not found. I am using wordpress 3.1 do you think it might be a problem of the new version?
thanks
Hello NT,
getallheaders is a PHP native function. You can find some more information on this at PHP.net (function.getallheaders.php).
What I recommend you doing is to contact your hosting company and ask them if they can install any dependencies for this function.
Let me know if you need more information.
Hello ali,
Haven’t had the time to test in on WP 3.1.
I am however working on a new version with a rebuilt engine and OAuth2. It will take some time, but i think it will be a great improvement.
Hi José,
Thanks for sharing this. I’m also thinking about how to this plugin might interact with other REST sources of information.
Looking forward to seeing your next exciting development.
Hi José,
We are looking for WordPress Bloggers to test our new WordPress Plugin : Tweet & Get it !
and we think that joseairosa.com is a good website to test it.
The plugin allows you to create a download button , which will hold the file you want to make available for download.
In exchange for the file the user will have to:
1. send a tweet (priorly defined by you) 2. follow your Twitter account
If you download it, you will have a demo of what the plugin exactly does :
http://tweetandgetit.com/download/
Don’t hesitate to contact us if you need support to install it.
Let me know what you think about it ?
Best Regards,
Marie de Ubeda
———————————-
Tweet&Get it !
Follow us on Twitter !
http://twitter.com/pointofviuu
http://twitter.com/tweetandgetit
José,
Thank you so much for this plugin. Unfortunately, when accessing the API page I too get the error message “The requested URL /api/register/ was not found”. Before diving in, I wanted to ask you if you ever figured out what the problem was.
Any leads would be much appreciated.
All the best,
–Konrad
Hello Konrad,
I’m sorry for the late reply.
Do you have permalinks activated?
Hi,
I too am having issues with the code below:
—
Fatal error: Call to undefined function getallheaders() in /SERVER_PATHS_HERE/wp-content/plugins/wp-restful/lib/OAuthRequestVerifier.php on line 88
—
I then tried adding the code below to my functions.php file:
—
if (!function_exists(‘getallheaders’))
{
function getallheaders()
{
foreach ($_SERVER as $name => $value)
{
if (substr($name, 0, 5) == ‘HTTP_’)
{
$headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value;
}
}
return $headers;
}
}
—
That caused this error on the /api page:
—
Warning: Cannot modify header information – headers already sent by (output started at /SERVER_PATH_GOES_HERE/wp-content/themes/twentyten/header.php:15) in /SERVER_PATH_GOES_HERE/wp-content/plugins/wp-restful/lib/REST.inc.php on line 669
Warning: Cannot modify header information – headers already sent by (output started at /SERVER_PATH_GOES_HERE/wp-content/themes/twentyten/header.php:15) in /SERVER_PATH_GOES_HERE/wp-content/plugins/wp-restful/lib/REST.inc.php on line 671
Not Found
The requested URL /api was not found.
—
Thanks so much for any help!
Matt
Hello Matthew,
Have you added the API page to the pages in wordpress?
The error that you’re getting is because that particular code is being executed and trying to add header information after the headers have already been sent to the browser. So, in any case, this code should be executed before any output is sent to the browser.
José,
Thank you for your quick response!
Yes, I have added the API page and the [REST_return] shortcode, and even refreshed Permalinks and installed a new blank boilerplate theme in case it was the template file…. I also changed the getallheaders() to emu_getallheaders() and added the function below:
—
function emu_getallheaders() {
foreach ($_SERVER as $name => $value)
{
if (substr($name, 0, 5) == ‘HTTP_’)
{
$name = str_replace(‘ ‘, ‘-’, ucwords(strtolower(str_replace(‘_’, ‘ ‘, substr($name, 5)))));
$headers[$name] = $value;
} else if ($name == “CONTENT_TYPE”) {
$headers["Content-Type"] = $value;
} else if ($name == “CONTENT_LENGTH”) {
$headers["Content-Length"] = $value;
}
}
return $headers;
}
—
I might be going in the completely wrong direction… Sorry for the trouble… I really appreciate your help.
Matt
Thanks Jose for this plug-in but I am also having the Not Found issue on a version 3.1.3 of WordPress.. Any word on a resolution or update for this plug-in?
Thanks
Hey José
1. Installed the Plugin
2. Activated the plugin
3. created API page with permalink
When I type in the api permalink in the web,
I keep getting the following error:
Fatal error: Class ‘OAuthStore’ not found in /*****/*****/*****/wp-content/plugins/wp-restful/lib/REST.inc.php on line 809
and when I type in the api/register, I get the registration form, but
with the same ERROR at the bottom…
Fatal error: Class ‘OAuthStore’ not found in /*****/*****/*****/wp-content/plugins/wp-restful/lib/REST.inc.php on line 809
any Ideas?
Hey José
I have fixed the problem….
Diagnosis:
I have one other plugin running:
s2member
This plugin has its own aotoload functions, and overrides REST.inc.php ___autoload function by calling spl_autoload_register(“functionName”);
the default ___autoload() stack is ignored if spl_autoload_register() is called, thus one has to add your autoload into this new stack,
so by default I have made the following changes to REST.inc.php
function wpr__autoload($class) {
$found = false;
@include_once ($class . ‘.php’);
…
}
spl_autoload_register (“wpr__autoload”); /* Register __autoload. */
WORK NICELY
Cheers
C
Hello Malcom,
If you can please add an issue on my github page so that I can keep track of things to do / fix.
https://github.com/joseairosa/WordPress-Plugin-WP-RESTful/issues
I will take a look ASAP
Matthew,
If you can please add an issue on my github page so that I can keep track of things to do / fix.
https://github.com/joseairosa/WordPress-Plugin-WP-RESTful/issues
I will take a look ASAP
Hello C0nan,
I’m glad things are working nicely.
Hey, I came across this when I was looking for a way to use WP as a backend for mobile development. Particularly jqtouch & sencha. I can build a mobile ‘theme’ no problem but if I want to use lets say phone gap it will need to get the data via an API. Would you have advice on how to set this up using your plugin?
Keep up the great work! You have a new follower!
Hello Jas,
You can certainly use this plugin as a backend and that’s the main reason I developed this plugin.
Since this plugins is built using OAuth you just need to find a Cocoa (iPhone) / Java (Android) library and use it to connect to your RESTful API.
It should not be difficult to implement as integrating with OAuth is one of the most common tutorials to find on the web.
Let me know if you run into any difficulties.
Jose,
I am getting the getallheaders() error, which you can see at http://leegrey.com/soae/api. I had my web host investigate, and they concluded that there is a problem in the plugin. They demonstrated that the call to getallheaders() itself works at http://leegrey.com/testgetallheaders.php.
Can you please investigate why this function fails in your plugin? In my case, I have not required OAuth authentication in the server, my request does not contain OAuth headers, and I want to use a non-WP client to call the API. I just want a simple REST server.
Thanks very much,
Lee Grey
Hi Jose, I’m having the same issue reported above about the getallheaders() function being undefined. I spoke to my host and this was the response:
Hi,
getallheaders() is not native to php5. It was a php4 function and was available in php5 but only if php is installed as an apache module. php here is not an apache module but a compiled binary. getallheaders() did become available in php 5.4 but only on fastcgi. As we are currently running 5.2.17, it is not available. We have recently finished phasing out php4 completely so that is most likely where this is coming from. If you need a workaround for that function to work with your plugin, you could define it in your functions.php file or somewhere where the plugin you’re using would be able to see it. Here’s a url to a possible workaround:
http://www.php.net/manual/en/function.getallheaders.php#84262
Otherwise, I would recommend contacting the plugin maker for an updated version of the plugin where that’s either defined or where it’s natively compatible with php 5 outside of fastcgi on php 5.4
Hello Lawrence,
Will take a look at that workaround asap.
Thank you for pointing it out
I am working on wp-ecommerce restful api’s using your plugin.. It seems the plugin is not ready for latest WP.. What is the expected date of release.. Thanks…
Hello Ramesh,
At the moment I cannot go forward with any ETA, but I’m working try get it working as soon as possible.
Thank you for your patience.
Hello,
I have bug with loading plugin classes. Poblem was in __autoload function
there is line:
@include_once ( WP_PLUGIN_DIR.”/”.$wpr_plugin_folder.”/lib/”.$class . ‘.php’);
but it just don’t work because $wpr_plugin_folder is bad. Example, Tags plugin is installed at ‘wp-restful-tags-plugin’ directory, but $wpr_plugin_folder is set to ‘wp-restful-tags’.
I solved problem changing problematic code to:
@include_once ( WP_PLUGIN_DIR.”/”.$wpr_plugin_folder.”-plugin/lib/”.$class . ‘.php’);
Off course, problem can be solved with setting correct dir name in plugin install functions.
There is plugin: PostRESTController
it has getPost() and getPosts() functions. So, it means that I can request via REST all posts or only one. I was reading code for past half an hour, maybe more, but I can not find that you implemented possibility to get only one post (or tag or whatever). I can get only all data.
Do I miss soomething or should I modify your plugin so I can request only one particular post/tag/category
Thank you
Hmm, I solved my issue in this way:
Class WPREST in contructor, there are lines:
if (strpos ( current ( $basename ), “/” )) {
$array = explode ( “/”, current ( $basename ) );
$this->setAction ( current ( $array ) );
$this->setActionRequest ( end ( $array ) );
You are using / as seperator, I just changed it to ; and now it is working just as I want it to work
In wp-restfull/wp-restfull.php you have a lot of closing th tags () but no opening one :S
Also, you are using function check_for_trailing_slash(), 5 times, that do not exists in WP nor in your plugin. It should be wpr_check_for_trailing_slash()
and sorry for spamming with comments
Hello Alex.
You should be able to request a single post with /post/id.json or xml
As for the closing tags, I will check if there’s a problem with them.
The function check_for_trailling_slash() should be, as you said, wpr_…
Thanks for pointing it out!
[...] een REST API plugin kunnen koppelingen worden gemaakt, die een rechtstreekse dataverbinding mogelijk maakt met [...]
Hello,
I guess, I should try to check this out by myself, but is it possible to use this to put a new post, or is it only readonly?
Hi,
I looked at the plugin and it says it is compatible uptil 3.05 of wordpress, I am running wordpress version 3.2.1, will the plugin work in this version?
Thanks
Awesome plugin. Are you still actively working on it? I was pretty excited when I found it, but I’ve hit a rut and I’ll probably need to use another plugin.
Right now on my API Server, I’m getting the following error:
The requested URL /api/ was not found
Even though the page itself loads up – in the page content area this error is displayed.
I think it’s likely a plugin conflict because I setup a testing server with the same permalink settings and everything, and it worked on the other server.
Is there a list of plugin conflicts? Here’s the plugins I currently have setup on the API server I’m trying to create:
Adminimize
Akismet
All in One SEO Pack
Batch Categories
Breadcrumb NavXT
Comments Notifier
Contact Form 7
CookieMonster
Example Widget
Executable PHP widget
Google XML Sitemaps
Improved Include Page
Include It
Kimili Flash Embed
Members Only
Microkid’s Related Posts
Peter’s Login Redirect
Register Plus Redux
Results count
Search Meter
Search Suggest
Shortcode Exec PHP
Simple 301 Redirects
Sort Query by Post In
UberMenu – WordPress Mega Menu Plugin
Ultimate Noindex Nofollow Tool
User Role Editor
W3 Total Cache
Widget Logic
WordPress HTTPS
wp-category-meta
wp-jquery-lightbox
WP-PageNavi
WP-RESTful
WPDB Profiling
Running WP 3.2.1.
On the client I setup, I also get the following error:
Fatal error: Call to undefined function getallheaders() in []/wp-restful/lib/OAuthRequestVerifier.php on line 88
Hi Jose, is the:
REST.inc.php on line 809 issue sorted on the server side and the OAuthRequestVerifier.php on line 88 on the client side?
Please let me know.
[...] kiezen om paywalls achter de API toegang te zetten. Er is een andere WordPress plugin genaamd WP-RESTful die dergelijke mogelijkheden heeft ingebouwd. Helaas kreeg ik hem op mijn server niet goed [...]
Hi Jose,
so i looked at the first video and got a bit confused? You mention that primary usecase of using the REST api via mobile apps.. but here you have shown the client as another website ? Would the steps be any different if the client is android or iMac ? can you post another video on same ?
Thanks,
-Premal
Hi Anantha,
I know it’s been a while since your answer. I’m sorry about that.
There were some changes on version 3.2.1 that might render this plugin unusable under certains circumstances. I would not advise it.
Hi Alex,
Thank you. At this point i’m not actively developing the plugin just because my personal time has been greatly reduced since I took my new job in London.
I would either recommend forking it on github and try and make some changes to get it working.
Hi Premal,
You can use in both situations basically. REST api is a way to expose the data from your website/app to the outside world via a controlled layer. So with the example I’ve give I would consume the data from my own blog, but I could also use it with an iPhone app in the same way.
Hi Thys,
Yes exactly like you said.