SlideShare a Scribd company logo
Integrating WordPress
With Web APIs
Randy Hoyt
About Me




            Randy Hoyt     randyhoyt.com
                           @randyhoyt


            Presentation   randyhoyt.com/wcmia


#wcmia                                     @randyhoyt
Overview



 • APIs: Defined
 • Two Examples:
         1. Get Treehouse Badges
         2. Get ShopLocket Products
 • WordPress Functions

#wcmia                                @randyhoyt
API
Application Programming Interface
A point where two systems,
  subjects, organizations, etc.,
  meet and interact.


Interface, http://dictionary.com/browse/interface
[Keyboard]
[Lock and Key]
An interface for software
 components to communicate
 with each other.


Wikipedia: API, http://trhou.se/defineAPI
API Examples




 • Android SDK: Camera API




#wcmia                       @randyhoyt
import android.hardware.Camera;


Camera.getNumberOfCameras();
Camera.open(cameraId);
API Examples




 • Android SDK: Camera API
 • WordPress: Plugin API


#wcmia                       @randyhoyt
<?php
/*
Plugin Name: Treehouse Badges
Description: Displays the badges ...
Version: 1.0
*/
?>


add_action('init','treehouse_badges_init');
...
API Examples




 • Android SDK: Camera API
 • WordPress: Plugin API
 • HTML5: Canvas API

#wcmia                       @randyhoyt
var canvas = document.getElementById("canvas");

var context = canvas.getContext("2d");

context.fillRect(10, 10, 40, 380, "#000000");

context.drawImage(img, x, y, 100, 77);
Web APIs
REST
Representational State Transfer
RESTful API
Example #1: Treehouse
[Treehouse screenshot]
JavaScript Object Notation:
 Text-based open standard
 designed for human-readable
 data interchange.


Wikipedia: JSON, http://trhou.se/defineJSON
{
     "firstName": "John",
     "lastName": "Smith",
     "address": {
         "streetAddress": "21 2nd Street",
         "city": "New York",
         "state": "NY",
         "postalCode": 10021
     },
     "phoneNumber": [
         {
             "type": "home",
             "number": "212 555-1234"
         },
         {
             "type": "fax",
             "number": "646 555-4567"
         }
     ]
 }

Wikipedia: JSON, http://trhou.se/defineJSON
[Treehouse JSON]
[HTML]
Asynchronous JavaScript and XML:
 Technique used by the browser to
 retrieve data from a server in the
 background without interfering with
 the existing page


Wikipedia: Ajax, http://trhou.se/defineAJAX
[AJAX Request Code]
[Badge Code]
[Badge Display]
Integrating WordPress With Web APIs
Integrating WordPress With Web APIs
Integrating WordPress With Web APIs
Integrating WordPress With Web APIs
Integrating WordPress With Web APIs
Integrating WordPress With Web APIs
Integrating WordPress With Web APIs
Integrating WordPress With Web APIs
<?php

$curl = curl_init();

curl_setopt_array($curl, array(

      CURLOPT_RETURNTRANSFER => 1,

      CURLOPT_URL => 'http://teamtreehou...

));

$resp = curl_exec($curl);

curl_close($curl);

?>
GET	
  Request	
  with	
  WordPress	
  HTTP	
  API




WordPress, http://codex.wordpress.org/HTTP_API
REST: Types of Requests



  • GET               (Read)
  • POST              (Create)
  • PUT               (Update)
  • DELETE            (Delete)

#wcmia                             @randyhoyt
Integrating WordPress With Web APIs
Integrating WordPress With Web APIs
Integrating WordPress With Web APIs
Integrating WordPress With Web APIs
Integrating WordPress With Web APIs
API Questions




 • Does it have to
     be real time?

 • What if something
     goes wrong?

#wcmia                   @randyhoyt
Example #2: ShopLocket
[Screenshot of WP]
[Screenshot of WordPress]
[Screenshot of Product Picker]
[Screenshot of Product Picker]
[Screenshot of Shortcode]
[Screenshot of Website]
Authentication
OAuth
  An open protocol to allow secure
  authorization in a simple and standard
  method from web, mobile and desktop
  applications.




OAuth, http://oauth.net/
App ID
5f4a89f2d6655ac7a8859343d6d15257
9410e7b659b200e00aaf3721cf46269e


App Secret
fa963a1ef3702c16d934500f7621697e2
d6bfd05d3ef1751a32bdeb2a0599020
[ShopLocket]
[ShopLocket Login]
[ShopLocket]
/? code = 53fe... & state = auth...
$args = array(
    "code" => $_GET["code"],
    "app_id" => "app id",
    "app_secret" => "app secret",
);
           [GET Request]
$response = wp_remote_post(
               'https://www.shoplocket.com/'
                   . 'oauth/token',
               $args
            );
Token:
310826b20a535a422ccaa46d65c7065f
83e403b9218a38962ab4e43021b93585
[Token]
API Questions




 • Does it have to
     be real time?

 • What if something
     goes wrong?

#wcmia                   @randyhoyt
Integrating WordPress With Web APIs
Integrating WordPress With Web APIs
Integrating WordPress With Web APIs
Integrating WordPress With Web APIs
Integrating WordPress With Web APIs
Integrating WordPress With Web APIs
Integrating WordPress With Web APIs
Integrating WordPress With Web APIs
[Refresh Button]
Integrating WordPress With Web APIs
WordPress Functions
Integrating WordPress With Web APIs
Integrating WordPress With Web APIs
WordPress wp_ajax, http://trhou.se/wp_ajax_hook
Integrating WordPress With Web APIs
GET	
  Request	
  with	
  WordPress	
  HTTP	
  API




WordPress HTTP API, http://codex.wordpress.org/HTTP_API
Integrating WordPress With Web APIs
WordPress update_option, http://trhou.se/update_option
Transients?




WordPress, http://codex.wordpress.org/Transients_API
Integrating WordPress
With Web APIs

Randy Hoyt     randyhoyt.com
               @randyhoyt

Presentation   randyhoyt.com/wcmia

More Related Content

PPTX
Integrating External APIs with WordPress
PPTX
Consuming & embedding external content in WordPress
PDF
PDF
Integrating WordPress With Web APIs
PPTX
Working with Images in WordPress
PDF
Djangoアプリのデプロイに関するプラクティス / Deploy django application
PDF
Django の認証処理実装パターン / Django Authentication Patterns
PDF
Intro to WordPress Plugin Development
Integrating External APIs with WordPress
Consuming & embedding external content in WordPress
Integrating WordPress With Web APIs
Working with Images in WordPress
Djangoアプリのデプロイに関するプラクティス / Deploy django application
Django の認証処理実装パターン / Django Authentication Patterns
Intro to WordPress Plugin Development

What's hot (19)

PDF
jQuery UI and Plugins
PPTX
Apex & jQuery Mobile
PPTX
Rest API Security
PPTX
Secure Your REST API (The Right Way)
PPTX
Threat Hunting Web Shells Using Splunk
PPT
PHPUG Presentation
PDF
Using OAuth with PHP
PPTX
Build A Killer Client For Your REST+JSON API
KEY
Making WordPress Your CMS and Automatically Updating a Self Hosted WordPress ...
PPTX
Poisoning Google images
ODP
Mohanraj - Securing Your Web Api With OAuth
PDF
WordPress Theme & Plugin development best practices - phpXperts seminar 2011
PPTX
Token Authentication for Java Applications
PPTX
AppForum 2014 Boost Hybrid App Performance
PDF
Caching in WordPress
PDF
Building Mobile Applications with Ionic
PPT
WordPress Security - WordCamp NYC 2009
PDF
All you need to know about JavaScript loading and execution in the browser - ...
PDF
WordCamp Mid-Atlantic WordPress Security
jQuery UI and Plugins
Apex & jQuery Mobile
Rest API Security
Secure Your REST API (The Right Way)
Threat Hunting Web Shells Using Splunk
PHPUG Presentation
Using OAuth with PHP
Build A Killer Client For Your REST+JSON API
Making WordPress Your CMS and Automatically Updating a Self Hosted WordPress ...
Poisoning Google images
Mohanraj - Securing Your Web Api With OAuth
WordPress Theme & Plugin development best practices - phpXperts seminar 2011
Token Authentication for Java Applications
AppForum 2014 Boost Hybrid App Performance
Caching in WordPress
Building Mobile Applications with Ionic
WordPress Security - WordCamp NYC 2009
All you need to know about JavaScript loading and execution in the browser - ...
WordCamp Mid-Atlantic WordPress Security
Ad

Similar to Integrating WordPress With Web APIs (20)

PDF
Understanding Identity in the World of Web APIs – Ronnie Mitra, API Architec...
PDF
API Technical Writing
PDF
Crossing the Boundaries of Web Applications with OpenSocial
PDF
HTML for the Mobile Web, Firefox OS
PPTX
Vue.js + Django - configuración para desarrollo con webpack y HMR
PDF
Workshop KrakYourNet2016 - Web applications hacking Ruby on Rails example
PPS
Hacking Client Side Insecurities
PPT
Hybrid Application Development for Maemo N900 Device using Qt Webkit - Discov...
PDF
RoR Workshop - Web applications hacking - Ruby on Rails example
PPT
PPTX
HTML5 for Rich User Experience
KEY
Rhodes
PDF
MesosCon - Be a microservices hero
PDF
The Future of Progressive Web Apps - Google for Indonesia
PDF
GDD Japan 2009 - Designing OpenSocial Apps For Speed and Scale
PPTX
Open Source Ajax Solution @OSDC.tw 2009
PPT
Robotlegs on Top of Gaia
PDF
SoftLayer API 12032015
PPTX
Disrupting the application eco system with progressive web applications
PDF
APIs for modern web apps
Understanding Identity in the World of Web APIs – Ronnie Mitra, API Architec...
API Technical Writing
Crossing the Boundaries of Web Applications with OpenSocial
HTML for the Mobile Web, Firefox OS
Vue.js + Django - configuración para desarrollo con webpack y HMR
Workshop KrakYourNet2016 - Web applications hacking Ruby on Rails example
Hacking Client Side Insecurities
Hybrid Application Development for Maemo N900 Device using Qt Webkit - Discov...
RoR Workshop - Web applications hacking - Ruby on Rails example
HTML5 for Rich User Experience
Rhodes
MesosCon - Be a microservices hero
The Future of Progressive Web Apps - Google for Indonesia
GDD Japan 2009 - Designing OpenSocial Apps For Speed and Scale
Open Source Ajax Solution @OSDC.tw 2009
Robotlegs on Top of Gaia
SoftLayer API 12032015
Disrupting the application eco system with progressive web applications
APIs for modern web apps
Ad

Recently uploaded (20)

PPTX
Big Data Technologies - Introduction.pptx
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PPTX
Cloud computing and distributed systems.
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Approach and Philosophy of On baking technology
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PPTX
Spectroscopy.pptx food analysis technology
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Electronic commerce courselecture one. Pdf
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PPTX
MYSQL Presentation for SQL database connectivity
PDF
NewMind AI Weekly Chronicles - August'25 Week I
Big Data Technologies - Introduction.pptx
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Cloud computing and distributed systems.
The Rise and Fall of 3GPP – Time for a Sabbatical?
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Per capita expenditure prediction using model stacking based on satellite ima...
Approach and Philosophy of On baking technology
Diabetes mellitus diagnosis method based random forest with bat algorithm
“AI and Expert System Decision Support & Business Intelligence Systems”
Programs and apps: productivity, graphics, security and other tools
Building Integrated photovoltaic BIPV_UPV.pdf
Dropbox Q2 2025 Financial Results & Investor Presentation
Spectroscopy.pptx food analysis technology
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Electronic commerce courselecture one. Pdf
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
MYSQL Presentation for SQL database connectivity
NewMind AI Weekly Chronicles - August'25 Week I

Integrating WordPress With Web APIs