WP REST API: Actionable.co

24
Blog - shawnhooper.ca Twitter - @shawnhooper REST API Case Study: Actionable.co WordCamp Miami 2017 Shawn Hooper Director of IT, actionable.co

Transcript of WP REST API: Actionable.co

Page 1: WP REST API: Actionable.co

Blog - shawnhooper.ca Twitter - @shawnhooper

REST API Case Study: Actionable.co

WordCamp Miami 2017

Shawn Hooper Director of IT, actionable.co

Page 2: WP REST API: Actionable.co

Blog - shawnhooper.ca Twitter - @shawnhooper

Good Afternoon!

I’m Shawn Hooper, the Director of IT at Actionable.co

Being a distributed company, everything we do is in the cloud….

Actionable

Page 3: WP REST API: Actionable.co

Blog - shawnhooper.ca Twitter - @shawnhooper

Our core offering is the Actionable Conversations platform. (NodeJS)

Actionable

Page 4: WP REST API: Actionable.co

Blog - shawnhooper.ca Twitter - @shawnhooper

Our core offering is the Actionable Conversations platform. (NodeJS)

We also have 3 public-facing websites marketing to different audiences (all WordPress).

Actionable

Page 5: WP REST API: Actionable.co

Blog - shawnhooper.ca Twitter - @shawnhooper

Our core offering is the Actionable Conversations platform. (NodeJS)

We also have 3 public-facing websites marketing to different audiences (all WordPress).

Our Intranet is also a WordPress site.

Actionable

Page 6: WP REST API: Actionable.co

Blog - shawnhooper.ca Twitter - @shawnhooper

We also use many 3rd party services w/ APIs:

Teachable (Online Courses) Infusionsoft (CRM)

Zoom (Webinars & Conference Calls) G Suite (Google Apps)

Xero (Accounting)BambooHR (HR Management)

…. and many more

Actionable

Page 7: WP REST API: Actionable.co

Blog - shawnhooper.ca Twitter - @shawnhooper

How we use the REST API…

Page 8: WP REST API: Actionable.co

Blog - shawnhooper.ca Twitter - @shawnhooper

To Manage Content…

Page 9: WP REST API: Actionable.co

Blog - shawnhooper.ca Twitter - @shawnhooper

Actionable Conversations

Learning & Development Platform

Developed in NodeJS

Our learning modules are content.Used the WP REST API to retrieve modules &

avoid making a custom CMS.

Why re-invent the wheel…

Page 10: WP REST API: Actionable.co

Blog - shawnhooper.ca Twitter - @shawnhooper

Modified ‘module’ Custom Post Type endpoint

to return required meta fields with the register_rest_field() function.

Why re-invent the wheel…

Page 11: WP REST API: Actionable.co

Blog - shawnhooper.ca Twitter - @shawnhooper

Modified ‘module’ Custom Post Type endpoint

to return required meta fields with the register_rest_field() function.

Wrote a plugin that added WPML information to this post type, showing current locale, and the locale, post ID and permalink to other available

languages.

Why re-invent the wheel…

Page 12: WP REST API: Actionable.co

Blog - shawnhooper.ca Twitter - @shawnhooper

Linking Between Blogs

Page 13: WP REST API: Actionable.co

Blog - shawnhooper.ca Twitter - @shawnhooper

We have three public facing websites with blogs.

Using the REST API, we retrieve the most recent post from each blog and display them in a widget

on all the sites.

/wp-json/wp/v2/posts/?per_page=1

(Cached for 24 hours)

Linking Between Blogs

Page 14: WP REST API: Actionable.co

Blog - shawnhooper.ca Twitter - @shawnhooper

We no longer use admin-ajax.php to handle AJAX

requests, but REST endpoints instead.

- Better Documented ( wp-json/ )- Code re-use from other sites and apps

(Example: Looking up valid email address)

Goodbye admin-ajax.php

Page 15: WP REST API: Actionable.co

Blog - shawnhooper.ca Twitter - @shawnhooper

To Optimize…

Page 16: WP REST API: Actionable.co

Blog - shawnhooper.ca Twitter - @shawnhooper

Clearing the Cache

Page 17: WP REST API: Actionable.co

Blog - shawnhooper.ca Twitter - @shawnhooper

Clearing the Cache

The data about our consultant network is maintained in one of our internal databases.

The page is populated using a shortcode.

This is slow.

So I cached it. Forever.

Page 18: WP REST API: Actionable.co

Blog - shawnhooper.ca Twitter - @shawnhooper

Clearing the CacheClear the cache only on data change

Page 19: WP REST API: Actionable.co

Blog - shawnhooper.ca Twitter - @shawnhooper

To Automate…

Page 20: WP REST API: Actionable.co

Blog - shawnhooper.ca Twitter - @shawnhooper

Problem:

An employee’s manager & HR need to know when a new team member completes their on boarding

courses in Teachable.

Solution:

Use REST API to accept web hooks from Teachable and then interface with Slack and our HRMS.

Teachable Webhooks

Page 21: WP REST API: Actionable.co

Blog - shawnhooper.ca Twitter - @shawnhooper

When an opportunity is marked as Closed-Won in Infusionsoft, we automatically create a record in our accounting software using the WP REST API.

Infusionsoft -> Xero

Page 22: WP REST API: Actionable.co

Blog - shawnhooper.ca Twitter - @shawnhooper

Problem:

User Management of Several Websites without Multisite

Solution:

Use REST API to remotely create user accounts from an admin page on our Intranet.

Bulk User Creation

Page 23: WP REST API: Actionable.co

Blog - shawnhooper.ca Twitter - @shawnhooper

POST /wp/v2/users/

combined with Google Apps Login plugin.

Bulk User Creation

Page 24: WP REST API: Actionable.co

Blog - shawnhooper.ca Twitter - @shawnhooper

You can find these slides, notes and more atshawnhooper.ca

Tweet Me @shawnhooper

WordPress Slack: shooper

Thank You!