I work with WordPress everyday, and across the web we have been hearing about the WordPress Rest API. I have used the Rest API and its going to be a great improvement and change to how we think and use WordPress today.
But when I work on projects, internally or for clients, we also say “I just want to do XYZ cool thing“. Most of the time it refers to interacting with a third party API to add/display/do new things in WordPress, and while it might use the WordPress Rest API, its not the first thing needed for the project.
Now all APIs are a little bit different, some are simple, some complex, some have great documentation while others do not. Some also happen to provide client libraries, and PHP is popular for client libraries.
We could fairly easily just drop a PHP client library for any API we want to use and be off to the races. However due to the many benefits of doing things the WordPress Way (like it, or hate it), many developers will write their own specific solution for interacting with the API for their needs. I believe there is much to benefit from for having a PHP client library specifically built for WordPress.
I think this could help bring some nice standardization to using third-party APIs in WordPress. For example if you search the plugins on wordpress.org for Google Analytics you will find 937 plugins listed. Now I’m sure many of these just offer a simply way to add the UA code, but there are still quite a few that use the Google Analytics API to create dashboards, or save data within WordPress.
What if there was One Standard Google Analytics PHP client library specifically built for WordPress? I think that could be a major value add to the WordPress community and Google Analytics users. This is just one API, and one example, there are many more public APIs out there that need a WordPress Specific client library.
With this idea in mind, I started a new organization on Github, WP API Libraries.
This project is very much in its infancy, and many of the guidelines needs to be discussed and solidified. Here is just a quick list of suggested rules for the projects:
- Follow WordPress PHP & JS Coding Standards
- Use WP Remote Request or other appropriate WordPress functions for API calls. No using curl or other methods directly for calls.
- PHP 7 Must be fully supported, support for older versions of PHP not required.
- Error messages should be set with WP Error.
- API Classes should not save any data to the DB.
- All methods of the API should be supported.
- All API classes should default to JSON.
If anyone is interested in getting involved, please don’t hesitate to reach out.