WP API and OAuth – Using WordPress without WordPress
In this tutorial, we’ll learn how to install and use WP-API with OAuth – a WordPress plugin which uses REST-like API endpoints to allow reading of WP content to unauthenticated users, and writing of WP content to users who authenticate via OAuth (or via Cookies for themes and plugins).
Using the plugin isn’t very straightforward, and the prerequisite list is quite long, so this post was written to make it simple and relatively approachable (as long as you’re in control of your own server).
The tutorial assumes basic familiarity with the terminal, and with Vagrant for ease of development.
As usual, we’ll be using SitePoint’s trusty Homestead Improved instance to get a fresh environment up and running:
git clone https://github.com/swader/homestead_improved hi_wp_github cd hi_wp_github sed -i '' "s@map\: \.@map\: $PWD@g" Homestead.yaml
That last line is a shortcut that makes the current folder of the host machine shared into the VM’s
Code folder. I also changed the sites block to:
sites: - map: test.app to: /home/vagrant/Code/wptest
Remember to have
test.app (or the URL you choose) in your
/etc/hosts file, as per instructions.
Next, we get a new instance of WP up and running. Since Homestead has MySQL pre-installed, this is a piece of cake.
cd ~/Code wget https://wordpress.org/latest.tar.gz tar -xvzf latest.tar.gz mv wordpress wptest cd wptest cp wp-config-sample.php wp-config.php
After we update
wp-config.php accordingly and set up our keys and database credentials, the WP instance is ready and can be finalized by running it in the browser.
Despite the flak it’s taken over the years (a large part of it fired from my own Dual Flak Cannons), WP really is trying to get with the times while still accommodating their old, technically inept userbase.
One such effort is the WP-API, a REST-like set of endpoints built into WP as a plugin so that the internals of a WordPress installation can become accessible to the outside. For example, getting your posts in JSON format is as simple as pinging
Continue reading %WP API and OAuth – Using WordPress without WordPress%