SlideShare a Scribd company logo
KATHLEEN VIGNOS
@kathleencodes
WIREDandtheWPRESTAPI
IN THE LOOP? THIRD PARTY? CUSTOM JSON? SYNCH’ING? EXTERNAL? SPA?
IN THE LOOP? THIRD PARTY? CUSTOM JSON? SYNCH’ING? EXTERNAL? SPA?
IN THE LOOP? THIRD PARTY? CUSTOM JSON? SYNCH’ING? EXTERNAL? SPA?
THIRD PARTY? CUSTOM JSON?
SYNCH’ING? EXTERNAL? SPA?
LATEST NEWS?
? ??
? ? ?
NOPE.IN THE LOOP?
IN THE LOOP? THIRD PARTY? CUSTOM JSON? SYNCH’ING? EXTERNAL? SPA?
LATEST NEWS?
LATEST NEWS?
IN THE LOOP? THIRD PARTY? CUSTOM JSON? SYNCH’ING? EXTERNAL? SPA?
Example: Latest News
• WIRED module used
everywhere
• WP REST API req’d
additional HTTP request
• needs deduping
(sometimes)
LATEST NEWS?
LATEST NEWS? THIRD PARTY? CUSTOM JSON? SYNCH’ING? EXTERNAL? SPA?
YES.
ELEMENTARY,
MY DEAR.
THIRD PARTY?
GET REQUEST
TO /POSTS/
ENDPOINT
WELL, SORT OF
LATEST NEWS? THIRD PARTY? CUSTOM JSON? SYNCH’ING? EXTERNAL? SPA?
Example:
• include vendor js
• add outbrain data
attributes
• fallback: WP REST API
LATEST NEWS? THIRD PARTY? CUSTOM JSON? SYNCH’ING? EXTERNAL? SPA?
var apiUrl = 'http://' + location.host + '/wp-json/wp/v2/posts/';
// Fallback if OBR not available
if ( typeof OBR === 'undefined' ) {
$( getAll('poweredByOutbrain') ).remove();
return $.getJSON( apiUrl, function(res) {
if ( elementId === 'we-recommend' ) {
return smart.rec( get('we-recommend') );
}
}
}
LATEST NEWS? THIRD PARTY? CUSTOM JSON? SYNCH’ING? EXTERNAL? SPA?
smart = (function() {
var mostRecent = function( target, apiUrl ) {
function render( res ) {
var frag = document.createDocumentFragment();
var data = res.slice( 0, 5 );
data.forEach(function( value, i ) {
var currLi = document.createElement('li');
....
frag.appendChild( currLi );
});
return target.appendChild( frag );
}
return $.getJSON( apiUrl, render );
};
return {
rec: mostRecent
};
}());
YES, WITH MY
CONDOLENCESCUSTOM JSON?
GET REQUEST
TO CUSTOM
ENDPOINT
THIRD PARTY? CUSTOM JSON? SYNCH’ING? EXTERNAL? SPA?LATEST NEWS?
THIRD PARTY? CUSTOM JSON? SYNCH’ING? EXTERNAL? SPA?
Example:
• Custom endpoint
• Parse WP post content to
markdown
• Output in Apple Native
Format
LATEST NEWS?
LATEST NEWS? THIRD PARTY? CUSTOM JSON? SYNCH’ING? EXTERNAL? SPA?
register_rest_route( 'apple-news/v2', '/post/(?P<post_id>w+)', array(
'methods' => WP_REST_Server::READABLE,
'callback' => array( $this, 'rest_post_output' ),
'args' => array(
'bundle',
'images',
'template',
),
) );
LATEST NEWS? THIRD PARTY? CUSTOM JSON? SYNCH’ING? EXTERNAL? SPA?
Apple News Plugin ParserWP DB
LATEST NEWS? THIRD PARTY? CUSTOM JSON? SYNCH’ING? EXTERNAL? SPA?
Apple News Plugin Parser Apple News Custom JSON
LATEST NEWS? THIRD PARTY? CUSTOM JSON? SYNCH’ING? EXTERNAL? SPA?
Apple News Plugin Parser Apple News Custom JSON
{
"role": "gallery",
"layout": "carouselLayoutNoTop",
"items": [
{
"path": "http://www.wired.com/wp-content/uploads/2016/01/CES_07-NEW-
NEW2.jpg",
"URL": "bundle://CES_07-NEW-NEW2.jpg",
"caption": "Drones as far as the eye can see."
},
{
"path": "http://www.wired.com/wp-content/uploads/2016/01/CES_11-NEW-
NEW2.jpg",
"URL": "bundle://CES_11-NEW-NEW2.jpg",
"caption": "There are still some old-school immersion tactics. This
attendee is sitting through a pre-programmed routine to lower his heart
rate and help him feel more relaxed."
}
]
}
LATEST NEWS? THIRD PARTY? CUSTOM JSON? SYNCH’ING? EXTERNAL? SPA?
Apple News Preview
(simulators)
Apple News Custom JSON
YEP, WE CAN
AUTOMATE
THAT
SYNCH’ING?
POST REQUEST
TO CREATE
POSTS ON
PUBLISH HOOK
THIRD PARTY? CUSTOM JSON? SYNCH’ING? EXTERNAL? SPA?LATEST NEWS?
THIRD PARTY? CUSTOM JSON? SYNCH’ING? EXTERNAL? SPA?
Example: Betta Beta Data Getta
• Publish/update hook
• Make POST request via
WP REST API with post_id
LIVE: www.wired.com
BETA: beta.wired.com
1. data-push
1
LATEST NEWS?
THIRD PARTY? CUSTOM JSON? SYNCH’ING? EXTERNAL? SPA?
Example: Betta Beta Data Getta
• Validate request
• Make GET request via WP
REST API for post_id
• Create post
LIVE: www.wired.com
BETA: beta.wired.com
2. data-pull
2
LATEST NEWS?
LATEST NEWS? THIRD PARTY? CUSTOM JSON? SYNCH’ING? EXTERNAL? SPA?
public function __construct() {
add_action( 'wp_insert_post', array( $this, 'notify_beta_site_post' ),
100, 3 );
}
public function notify_beta_site_post( $post_id, $post, $update ) {
$this->update_object( $post_id, 'post' );
}
public function update_object( $post_id, $object ) {
$this->make_request( $post_id, $object );
}
LATEST NEWS? THIRD PARTY? CUSTOM JSON? SYNCH’ING? EXTERNAL? SPA?
public function make_request( $id, $object ) {
// example: 'http://beta.wired.com/?beta-push=1';
$request_url = $this->get_request_url();
$request_args = array(
'body' => array(
'id' => absint( $id ),
'object' => $object,
),
'headers' => array(
'api-key' => DATA_PUSH_API_KEY,
'api-secret' => DATA_PUSH_API_SECRET,
),
'blocking' => false,
);
$result = wp_remote_post(
$request_url,
$request_args
);
}
LATEST NEWS? THIRD PARTY? CUSTOM JSON? SYNCH’ING? EXTERNAL? SPA?
public function __construct() {
add_action( 'init', array( $this, 'route_pull_request' ), 11 );
}
public function route_pull_request() {
if ( ! $this->validate_request() ) {
return;
}
$id = $this->get_request_id();
$object = $this->get_request_object(); // ex: ‘post’
$data = $this->get_data( $id, 'post' );
$result = $this->save_response_post( $id, $data );
exit();
}
LATEST NEWS? THIRD PARTY? CUSTOM JSON? SYNCH’ING? EXTERNAL? SPA?
public function get_data( $id, $object ) {
$data = array();
$request_url = get_request_url_post( $id );
// example: https://www.wired.com/wp-json/posts/1234567?context=edit
$response = wp_remote_get(
$request_url,
array_merge(
$args
)
);
if ( 200 === (int) wp_remote_retrieve_response_code( $response ) ) {
$body = json_decode( wp_remote_retrieve_body( $response ), true );
// Check to make sure the data looks right
if ( isset( $body['ID'], $body['title'] ) ) {
$data = $body;
}
}
return $data;
}
LATEST NEWS? THIRD PARTY? CUSTOM JSON? SYNCH’ING? EXTERNAL? SPA?
public function save_response_post( $id, $data ) {
$existing_post = get_post( $id );
$prepared_data = $this->prepare_post_data( $data, $id );
if ( empty( $existing_post ) ) {
$result = wp_insert_post( $prepared_data );
} else {
$result = wp_update_post( $prepared_data );
}
foreach ( $data['post_meta'] as $meta ) {
// Note that this will break serialized meta data. Our meta data
does not include serialized meta data.
update_post_meta( $result, $meta['key'], $this->$meta['value'] );
}
return $result;
}
SURE, LET’S
GET CREATIVE!EXTERNAL?
POST REQUEST
TO CREATE
POSTS WITH
AUTH
THIRD PARTY? CUSTOM JSON? SYNCH’ING? EXTERNAL? SPA?LATEST NEWS?
IN THE LOOP? THIRD PARTY? CUSTOM JSON? SYNCH’ING? EXTERNAL? SPA?
Example:
• Node application listens
for requests from Slack
• Bot invited to channel
• Every comment or image
creates a “liveblog
update” post type via WP
REST API
• WP template w/ React
updates content
Liveblog
LATEST NEWS? THIRD PARTY? CUSTOM JSON? SYNCH’ING? EXTERNAL? SPA?
WP DBNode Serverslack
IN THE LOOP? THIRD PARTY? CUSTOM JSON? SYNCH’ING? EXTERNAL? SPA?
LATEST NEWS? THIRD PARTY? CUSTOM JSON? SYNCH’ING? EXTERNAL? SPA?
var addPost = function(preparedMessage, authorID) {
return function() {
// example wpAPIUrl: http://www.wired.com/wp-json/
request( extend(
requestBase,
{
method: 'POST',
uri: config.wpAPIUrl() + '/liveblog',
body: {
type: 'liveblog',
status: 'publish',
title: preparedMessage.ts,
content: preparedMessage.text,
author: authorID,
featured_image: (preparedMessage.featuredImageID) ?
preparedMessage.featuredImageID : 0
}
}
...
LATEST NEWS? THIRD PARTY? CUSTOM JSON? SYNCH’ING? EXTERNAL? SPA?
public function __construct() {
add_action( 'rest_api_init', array( $this, 'register_routes' ) );
}
public function register_routes() {
// example: http://www.wired.com/wp-json/wired/v2/liveblog/1949283/
posts/
// React script hits this endpoint to grab the post objects
register_rest_route( 'wired/v2', '/liveblog/(?P<post_id>w+)/posts',
array(
'methods' => WP_REST_Server::READABLE,
'callback' => array( $this, 'posts_callback' ),
'args' => array(
'post_id',
),
) );
}
LATEST NEWS? THIRD PARTY? CUSTOM JSON? SYNCH’ING? EXTERNAL? SPA?
public function posts_callback( $request ) {
$posts = '';
$params = $request->get_params();
$post_id = ( isset( $params['post_id'] ) ) ?
absint( $params['post_id'] ) : 0;
$posts = array(
'version' => time(),
'posts' => $this->get_liveblog_posts( $post_id )
);
return $posts;
}
LATEST NEWS? THIRD PARTY? CUSTOM JSON? SYNCH’ING? EXTERNAL? SPA?
public function get_liveblog_posts( $post_id ) {
$liveblog_meta = get_post_meta( $post_id, '_liveblog', true );
$query = new WP_Query( array(
'posts_per_page' => 500,
'post_type' => array( wired_get_liveblog_post()->post_type ),
'tax_query' => array( array(
'taxonomy' => wired_get_liveblog_post()->taxonomy,
'field' => 'name',
'terms' => $liveblog_meta['slack-channel-name'],
))
) );
if ( $query->have_posts() ) {
while ( $query->have_posts() ) {
$query->the_post();
$clean_posts[] = array(
'id' => get_the_ID(),
...
);
}}
wp_reset_postdata();
return $clean_posts;
}
YES, BECAUSE
#NODEJSSPA?
JSON OBJECTS
#FTW!
THIRD PARTY? CUSTOM JSON? SYNCH’ING? EXTERNAL? SPA?LATEST NEWS?
THIRD PARTY? CUSTOM JSON? SYNCH’ING? EXTERNAL? SPA?LATEST NEWS?
Example: Homepage Curator (in the future)
• Dashboard: Replace WP posts admin table
ajax with SPA using React components
• Create custom WP REST API endpoint for
homepage and all section fronts
• Front end: Build homepage and section fronts
with React components
• Ability to swipe from section to section
without reload
THIRD PARTY? CUSTOM JSON? SYNCH’ING? EXTERNAL? SPA?LATEST NEWS?
THIRD PARTY? CUSTOM JSON? SYNCH’ING? EXTERNAL? SPA?LATEST NEWS?
THIRD PARTY? CUSTOM JSON? SYNCH’ING? EXTERNAL? SPA?LATEST NEWS?
THIRD PARTY? CUSTOM JSON?
SYNCH’ING? EXTERNAL? SPA?
LATEST NEWS?
NOPE. WELL, SORT OF.
YES, WITH MY
CONDOLENCES
YEP, WE CAN
AUTOMATE
THAT
SURE, LET’S
GET CREATIVE!
YES, BECAUSE
#NODEJS
THIRD PARTY? CUSTOM JSON? SYNCH’ING? EXTERNAL? SPA?
All Code Samples in this Gist:
http://bit.ly/day-of-rest-2016-kv
Slides:
http://www.slideshare.net/kvignos/wired-and-the-wp-rest-api
LATEST NEWS?
KATHLEEN VIGNOS
@kathleencodes
THANKYOU!

More Related Content

What's hot

And now you have two problems. Ruby regular expressions for fun and profit by...
And now you have two problems. Ruby regular expressions for fun and profit by...And now you have two problems. Ruby regular expressions for fun and profit by...
And now you have two problems. Ruby regular expressions for fun and profit by...
Codemotion
 
PHP code examples
PHP code examplesPHP code examples
PHP code examples
programmingslides
 
ABC of Perl programming
ABC of Perl programmingABC of Perl programming
ABC of Perl programming
Bo Hua Yang
 
Moving from Django Apps to Services
Moving from Django Apps to ServicesMoving from Django Apps to Services
Moving from Django Apps to Services
Craig Kerstiens
 
Awash in a sea of connections
Awash in a sea of connectionsAwash in a sea of connections
Awash in a sea of connectionsGalen Charlton
 
A Little Backbone For Your App
A Little Backbone For Your AppA Little Backbone For Your App
A Little Backbone For Your App
Luca Mearelli
 
Putting the Cat in the Catalogue: A Feline-Inspired OPAC Theme For Koha
Putting the Cat in the Catalogue: A Feline-Inspired OPAC Theme For KohaPutting the Cat in the Catalogue: A Feline-Inspired OPAC Theme For Koha
Putting the Cat in the Catalogue: A Feline-Inspired OPAC Theme For Koha
Galen Charlton
 
Writing Apps the Google-y Way (Brisbane)
Writing Apps the Google-y Way (Brisbane)Writing Apps the Google-y Way (Brisbane)
Writing Apps the Google-y Way (Brisbane)
Pamela Fox
 
PerlでWeb API入門
PerlでWeb API入門PerlでWeb API入門
PerlでWeb API入門Yusuke Wada
 
With a Mighty Hammer
With a Mighty HammerWith a Mighty Hammer
With a Mighty Hammer
Ben Scofield
 
Django - 次の一歩 gumiStudy#3
Django - 次の一歩 gumiStudy#3Django - 次の一歩 gumiStudy#3
Django - 次の一歩 gumiStudy#3
makoto tsuyuki
 
The effective use of Django ORM
The effective use of Django ORMThe effective use of Django ORM
The effective use of Django ORM
Yaroslav Muravskyi
 
OSCON Google App Engine Codelab - July 2010
OSCON Google App Engine Codelab - July 2010OSCON Google App Engine Codelab - July 2010
OSCON Google App Engine Codelab - July 2010
ikailan
 
RESTful API 제대로 만들기
RESTful API 제대로 만들기RESTful API 제대로 만들기
RESTful API 제대로 만들기
Juwon Kim
 
Developing apps using Perl
Developing apps using PerlDeveloping apps using Perl
Developing apps using Perl
Anatoly Sharifulin
 
Keeping it Small: Getting to know the Slim Micro Framework
Keeping it Small: Getting to know the Slim Micro FrameworkKeeping it Small: Getting to know the Slim Micro Framework
Keeping it Small: Getting to know the Slim Micro FrameworkJeremy Kendall
 
Hack in the Box Keynote 2006
Hack in the Box Keynote 2006Hack in the Box Keynote 2006
Hack in the Box Keynote 2006
Mark Curphey
 
Keeping it small - Getting to know the Slim PHP micro framework
Keeping it small - Getting to know the Slim PHP micro frameworkKeeping it small - Getting to know the Slim PHP micro framework
Keeping it small - Getting to know the Slim PHP micro framework
Jeremy Kendall
 

What's hot (20)

And now you have two problems. Ruby regular expressions for fun and profit by...
And now you have two problems. Ruby regular expressions for fun and profit by...And now you have two problems. Ruby regular expressions for fun and profit by...
And now you have two problems. Ruby regular expressions for fun and profit by...
 
PHP code examples
PHP code examplesPHP code examples
PHP code examples
 
ABC of Perl programming
ABC of Perl programmingABC of Perl programming
ABC of Perl programming
 
Moving from Django Apps to Services
Moving from Django Apps to ServicesMoving from Django Apps to Services
Moving from Django Apps to Services
 
Awash in a sea of connections
Awash in a sea of connectionsAwash in a sea of connections
Awash in a sea of connections
 
A Little Backbone For Your App
A Little Backbone For Your AppA Little Backbone For Your App
A Little Backbone For Your App
 
Putting the Cat in the Catalogue: A Feline-Inspired OPAC Theme For Koha
Putting the Cat in the Catalogue: A Feline-Inspired OPAC Theme For KohaPutting the Cat in the Catalogue: A Feline-Inspired OPAC Theme For Koha
Putting the Cat in the Catalogue: A Feline-Inspired OPAC Theme For Koha
 
API Design - 3rd Edition
API Design - 3rd EditionAPI Design - 3rd Edition
API Design - 3rd Edition
 
Php My Sql
Php My SqlPhp My Sql
Php My Sql
 
Writing Apps the Google-y Way (Brisbane)
Writing Apps the Google-y Way (Brisbane)Writing Apps the Google-y Way (Brisbane)
Writing Apps the Google-y Way (Brisbane)
 
PerlでWeb API入門
PerlでWeb API入門PerlでWeb API入門
PerlでWeb API入門
 
With a Mighty Hammer
With a Mighty HammerWith a Mighty Hammer
With a Mighty Hammer
 
Django - 次の一歩 gumiStudy#3
Django - 次の一歩 gumiStudy#3Django - 次の一歩 gumiStudy#3
Django - 次の一歩 gumiStudy#3
 
The effective use of Django ORM
The effective use of Django ORMThe effective use of Django ORM
The effective use of Django ORM
 
OSCON Google App Engine Codelab - July 2010
OSCON Google App Engine Codelab - July 2010OSCON Google App Engine Codelab - July 2010
OSCON Google App Engine Codelab - July 2010
 
RESTful API 제대로 만들기
RESTful API 제대로 만들기RESTful API 제대로 만들기
RESTful API 제대로 만들기
 
Developing apps using Perl
Developing apps using PerlDeveloping apps using Perl
Developing apps using Perl
 
Keeping it Small: Getting to know the Slim Micro Framework
Keeping it Small: Getting to know the Slim Micro FrameworkKeeping it Small: Getting to know the Slim Micro Framework
Keeping it Small: Getting to know the Slim Micro Framework
 
Hack in the Box Keynote 2006
Hack in the Box Keynote 2006Hack in the Box Keynote 2006
Hack in the Box Keynote 2006
 
Keeping it small - Getting to know the Slim PHP micro framework
Keeping it small - Getting to know the Slim PHP micro frameworkKeeping it small - Getting to know the Slim PHP micro framework
Keeping it small - Getting to know the Slim PHP micro framework
 

Viewers also liked

WordCamp Kansai 2014_All we really need to know we have learned from wordpress.
WordCamp Kansai 2014_All we really need to know we have learned from wordpress.WordCamp Kansai 2014_All we really need to know we have learned from wordpress.
WordCamp Kansai 2014_All we really need to know we have learned from wordpress.
Hiromichi Koga
 
SW6 Associates Work For Us 2016
SW6 Associates Work For Us 2016SW6 Associates Work For Us 2016
SW6 Associates Work For Us 2016
James Wilson
 
Short and Long of Data Driven Innovation
Short and Long of Data Driven InnovationShort and Long of Data Driven Innovation
Short and Long of Data Driven Innovation
David De Roure
 
Empowering Generation Z #DigCitSummitUK
Empowering Generation Z #DigCitSummitUKEmpowering Generation Z #DigCitSummitUK
Empowering Generation Z #DigCitSummitUK
Digital Training Institute
 
Angular Remote Conf - Building with Angular & WordPress
Angular Remote Conf - Building with Angular & WordPressAngular Remote Conf - Building with Angular & WordPress
Angular Remote Conf - Building with Angular & WordPress
Roy Sivan
 
Advanced Development Workflows
Advanced Development WorkflowsAdvanced Development Workflows
Advanced Development Workflows
Micah Wood
 
今、WordPress を使う理由
今、WordPress を使う理由今、WordPress を使う理由
今、WordPress を使う理由
Naoko Takano
 
Awareness of OER and OEP in Scottish Higher Education Institutions Survey Res...
Awareness of OER and OEP in Scottish Higher Education Institutions Survey Res...Awareness of OER and OEP in Scottish Higher Education Institutions Survey Res...
Awareness of OER and OEP in Scottish Higher Education Institutions Survey Res...
OEPScotland
 
Content by the Slice, Information Architecture Workshop - Mobile UXCamp DC 2015
Content by the Slice, Information Architecture Workshop - Mobile UXCamp DC 2015Content by the Slice, Information Architecture Workshop - Mobile UXCamp DC 2015
Content by the Slice, Information Architecture Workshop - Mobile UXCamp DC 2015
Anthony D. Paul
 
Czy blogerzy i youtuberzy zmieniają świat?
Czy blogerzy i youtuberzy zmieniają świat?Czy blogerzy i youtuberzy zmieniają świat?
Czy blogerzy i youtuberzy zmieniają świat?
Natalia Hatalska
 

Viewers also liked (10)

WordCamp Kansai 2014_All we really need to know we have learned from wordpress.
WordCamp Kansai 2014_All we really need to know we have learned from wordpress.WordCamp Kansai 2014_All we really need to know we have learned from wordpress.
WordCamp Kansai 2014_All we really need to know we have learned from wordpress.
 
SW6 Associates Work For Us 2016
SW6 Associates Work For Us 2016SW6 Associates Work For Us 2016
SW6 Associates Work For Us 2016
 
Short and Long of Data Driven Innovation
Short and Long of Data Driven InnovationShort and Long of Data Driven Innovation
Short and Long of Data Driven Innovation
 
Empowering Generation Z #DigCitSummitUK
Empowering Generation Z #DigCitSummitUKEmpowering Generation Z #DigCitSummitUK
Empowering Generation Z #DigCitSummitUK
 
Angular Remote Conf - Building with Angular & WordPress
Angular Remote Conf - Building with Angular & WordPressAngular Remote Conf - Building with Angular & WordPress
Angular Remote Conf - Building with Angular & WordPress
 
Advanced Development Workflows
Advanced Development WorkflowsAdvanced Development Workflows
Advanced Development Workflows
 
今、WordPress を使う理由
今、WordPress を使う理由今、WordPress を使う理由
今、WordPress を使う理由
 
Awareness of OER and OEP in Scottish Higher Education Institutions Survey Res...
Awareness of OER and OEP in Scottish Higher Education Institutions Survey Res...Awareness of OER and OEP in Scottish Higher Education Institutions Survey Res...
Awareness of OER and OEP in Scottish Higher Education Institutions Survey Res...
 
Content by the Slice, Information Architecture Workshop - Mobile UXCamp DC 2015
Content by the Slice, Information Architecture Workshop - Mobile UXCamp DC 2015Content by the Slice, Information Architecture Workshop - Mobile UXCamp DC 2015
Content by the Slice, Information Architecture Workshop - Mobile UXCamp DC 2015
 
Czy blogerzy i youtuberzy zmieniają świat?
Czy blogerzy i youtuberzy zmieniają świat?Czy blogerzy i youtuberzy zmieniają świat?
Czy blogerzy i youtuberzy zmieniają świat?
 

Similar to WIRED and the WP REST API

WordPress Realtime - WordCamp São Paulo 2015
WordPress Realtime - WordCamp São Paulo 2015WordPress Realtime - WordCamp São Paulo 2015
WordPress Realtime - WordCamp São Paulo 2015
Fernando Daciuk
 
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQuery
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQueryRemedie: Building a desktop app with HTTP::Engine, SQLite and jQuery
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQueryTatsuhiko Miyagawa
 
Great Developers Steal
Great Developers StealGreat Developers Steal
Great Developers Steal
Ben Scofield
 
Connecting Content Silos: One CMS, Many Sites With The WordPress REST API
 Connecting Content Silos: One CMS, Many Sites With The WordPress REST API Connecting Content Silos: One CMS, Many Sites With The WordPress REST API
Connecting Content Silos: One CMS, Many Sites With The WordPress REST API
Caldera Labs
 
WordPress REST API hacking
WordPress REST API hackingWordPress REST API hacking
WordPress REST API hacking
Jeroen van Dijk
 
GraphQL & Relay - 串起前後端世界的橋樑
GraphQL & Relay - 串起前後端世界的橋樑GraphQL & Relay - 串起前後端世界的橋樑
GraphQL & Relay - 串起前後端世界的橋樑
Pokai Chang
 
Bootstrat REST APIs with Laravel 5
Bootstrat REST APIs with Laravel 5Bootstrat REST APIs with Laravel 5
Bootstrat REST APIs with Laravel 5
Elena Kolevska
 
PHP and Rich Internet Applications
PHP and Rich Internet ApplicationsPHP and Rich Internet Applications
PHP and Rich Internet Applicationselliando dias
 
Kicking off with Zend Expressive and Doctrine ORM (PHP UK 2017)
Kicking off with Zend Expressive and Doctrine ORM (PHP UK 2017)Kicking off with Zend Expressive and Doctrine ORM (PHP UK 2017)
Kicking off with Zend Expressive and Doctrine ORM (PHP UK 2017)
James Titcumb
 
Kicking off with Zend Expressive and Doctrine ORM (Sunshine PHP 2017)
Kicking off with Zend Expressive and Doctrine ORM (Sunshine PHP 2017)Kicking off with Zend Expressive and Doctrine ORM (Sunshine PHP 2017)
Kicking off with Zend Expressive and Doctrine ORM (Sunshine PHP 2017)
James Titcumb
 
Symfony tips and tricks
Symfony tips and tricksSymfony tips and tricks
Symfony tips and tricks
Mariusz Kozłowski
 
Make WordPress realtime.
Make WordPress realtime.Make WordPress realtime.
Make WordPress realtime.
Josh Hillier
 
混搭移动开发:PhoneGap+JQurey+Dreamweaver
混搭移动开发:PhoneGap+JQurey+Dreamweaver混搭移动开发:PhoneGap+JQurey+Dreamweaver
混搭移动开发:PhoneGap+JQurey+Dreamweaveryangdj
 
After max+phonegap
After max+phonegapAfter max+phonegap
After max+phonegapyangdj
 
JSON and the APInauts
JSON and the APInautsJSON and the APInauts
JSON and the APInauts
Wynn Netherland
 
Doctrine For Beginners
Doctrine For BeginnersDoctrine For Beginners
Doctrine For Beginners
Jonathan Wage
 
WordPressでIoTをはじめよう
WordPressでIoTをはじめようWordPressでIoTをはじめよう
WordPressでIoTをはじめよう
Yuriko IKEDA
 
Coding Ajax
Coding AjaxCoding Ajax
Coding Ajax
Ted Husted
 
Teaming up WordPress API with Backbone.js in Titanium
Teaming up WordPress API with Backbone.js in TitaniumTeaming up WordPress API with Backbone.js in Titanium
Teaming up WordPress API with Backbone.js in Titanium
Jeroen van Dijk
 

Similar to WIRED and the WP REST API (20)

WordPress Realtime - WordCamp São Paulo 2015
WordPress Realtime - WordCamp São Paulo 2015WordPress Realtime - WordCamp São Paulo 2015
WordPress Realtime - WordCamp São Paulo 2015
 
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQuery
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQueryRemedie: Building a desktop app with HTTP::Engine, SQLite and jQuery
Remedie: Building a desktop app with HTTP::Engine, SQLite and jQuery
 
Great Developers Steal
Great Developers StealGreat Developers Steal
Great Developers Steal
 
Connecting Content Silos: One CMS, Many Sites With The WordPress REST API
 Connecting Content Silos: One CMS, Many Sites With The WordPress REST API Connecting Content Silos: One CMS, Many Sites With The WordPress REST API
Connecting Content Silos: One CMS, Many Sites With The WordPress REST API
 
WordPress REST API hacking
WordPress REST API hackingWordPress REST API hacking
WordPress REST API hacking
 
GraphQL & Relay - 串起前後端世界的橋樑
GraphQL & Relay - 串起前後端世界的橋樑GraphQL & Relay - 串起前後端世界的橋樑
GraphQL & Relay - 串起前後端世界的橋樑
 
Bootstrat REST APIs with Laravel 5
Bootstrat REST APIs with Laravel 5Bootstrat REST APIs with Laravel 5
Bootstrat REST APIs with Laravel 5
 
PHP and Rich Internet Applications
PHP and Rich Internet ApplicationsPHP and Rich Internet Applications
PHP and Rich Internet Applications
 
Kicking off with Zend Expressive and Doctrine ORM (PHP UK 2017)
Kicking off with Zend Expressive and Doctrine ORM (PHP UK 2017)Kicking off with Zend Expressive and Doctrine ORM (PHP UK 2017)
Kicking off with Zend Expressive and Doctrine ORM (PHP UK 2017)
 
Kicking off with Zend Expressive and Doctrine ORM (Sunshine PHP 2017)
Kicking off with Zend Expressive and Doctrine ORM (Sunshine PHP 2017)Kicking off with Zend Expressive and Doctrine ORM (Sunshine PHP 2017)
Kicking off with Zend Expressive and Doctrine ORM (Sunshine PHP 2017)
 
Symfony tips and tricks
Symfony tips and tricksSymfony tips and tricks
Symfony tips and tricks
 
Make WordPress realtime.
Make WordPress realtime.Make WordPress realtime.
Make WordPress realtime.
 
Django
DjangoDjango
Django
 
混搭移动开发:PhoneGap+JQurey+Dreamweaver
混搭移动开发:PhoneGap+JQurey+Dreamweaver混搭移动开发:PhoneGap+JQurey+Dreamweaver
混搭移动开发:PhoneGap+JQurey+Dreamweaver
 
After max+phonegap
After max+phonegapAfter max+phonegap
After max+phonegap
 
JSON and the APInauts
JSON and the APInautsJSON and the APInauts
JSON and the APInauts
 
Doctrine For Beginners
Doctrine For BeginnersDoctrine For Beginners
Doctrine For Beginners
 
WordPressでIoTをはじめよう
WordPressでIoTをはじめようWordPressでIoTをはじめよう
WordPressでIoTをはじめよう
 
Coding Ajax
Coding AjaxCoding Ajax
Coding Ajax
 
Teaming up WordPress API with Backbone.js in Titanium
Teaming up WordPress API with Backbone.js in TitaniumTeaming up WordPress API with Backbone.js in Titanium
Teaming up WordPress API with Backbone.js in Titanium
 

More from kvignos

LeadingEng Growing the Next Generation of Leaders, Kathleen Vignos.pdf
LeadingEng Growing the Next Generation of Leaders, Kathleen Vignos.pdfLeadingEng Growing the Next Generation of Leaders, Kathleen Vignos.pdf
LeadingEng Growing the Next Generation of Leaders, Kathleen Vignos.pdf
kvignos
 
Keeping up your technical skills as a manager
Keeping up your technical skills as a managerKeeping up your technical skills as a manager
Keeping up your technical skills as a manager
kvignos
 
How to keep up your technical skills without annoying your team(s)
How to keep up your technical skills without annoying your team(s)How to keep up your technical skills without annoying your team(s)
How to keep up your technical skills without annoying your team(s)
kvignos
 
5 leadership skills every engineer needs - North Bay Python
5 leadership skills every engineer needs - North Bay Python5 leadership skills every engineer needs - North Bay Python
5 leadership skills every engineer needs - North Bay Python
kvignos
 
Managing engineering teams through constant change final
Managing engineering teams through constant change finalManaging engineering teams through constant change final
Managing engineering teams through constant change final
kvignos
 
WordCamp SF 2014 - WIRED Migration Project
WordCamp SF 2014 - WIRED Migration ProjectWordCamp SF 2014 - WIRED Migration Project
WordCamp SF 2014 - WIRED Migration Project
kvignos
 

More from kvignos (6)

LeadingEng Growing the Next Generation of Leaders, Kathleen Vignos.pdf
LeadingEng Growing the Next Generation of Leaders, Kathleen Vignos.pdfLeadingEng Growing the Next Generation of Leaders, Kathleen Vignos.pdf
LeadingEng Growing the Next Generation of Leaders, Kathleen Vignos.pdf
 
Keeping up your technical skills as a manager
Keeping up your technical skills as a managerKeeping up your technical skills as a manager
Keeping up your technical skills as a manager
 
How to keep up your technical skills without annoying your team(s)
How to keep up your technical skills without annoying your team(s)How to keep up your technical skills without annoying your team(s)
How to keep up your technical skills without annoying your team(s)
 
5 leadership skills every engineer needs - North Bay Python
5 leadership skills every engineer needs - North Bay Python5 leadership skills every engineer needs - North Bay Python
5 leadership skills every engineer needs - North Bay Python
 
Managing engineering teams through constant change final
Managing engineering teams through constant change finalManaging engineering teams through constant change final
Managing engineering teams through constant change final
 
WordCamp SF 2014 - WIRED Migration Project
WordCamp SF 2014 - WIRED Migration ProjectWordCamp SF 2014 - WIRED Migration Project
WordCamp SF 2014 - WIRED Migration Project
 

Recently uploaded

Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
Ana-Maria Mihalceanu
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
Product School
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
Cheryl Hung
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
Safe Software
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
UiPathCommunity
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
OnBoard
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
Thijs Feryn
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Tobias Schneck
 

Recently uploaded (20)

Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
 

WIRED and the WP REST API

  • 2.
  • 3. IN THE LOOP? THIRD PARTY? CUSTOM JSON? SYNCH’ING? EXTERNAL? SPA?
  • 4. IN THE LOOP? THIRD PARTY? CUSTOM JSON? SYNCH’ING? EXTERNAL? SPA?
  • 5. IN THE LOOP? THIRD PARTY? CUSTOM JSON? SYNCH’ING? EXTERNAL? SPA?
  • 6. THIRD PARTY? CUSTOM JSON? SYNCH’ING? EXTERNAL? SPA? LATEST NEWS? ? ?? ? ? ?
  • 7. NOPE.IN THE LOOP? IN THE LOOP? THIRD PARTY? CUSTOM JSON? SYNCH’ING? EXTERNAL? SPA? LATEST NEWS? LATEST NEWS?
  • 8. IN THE LOOP? THIRD PARTY? CUSTOM JSON? SYNCH’ING? EXTERNAL? SPA? Example: Latest News • WIRED module used everywhere • WP REST API req’d additional HTTP request • needs deduping (sometimes) LATEST NEWS?
  • 9. LATEST NEWS? THIRD PARTY? CUSTOM JSON? SYNCH’ING? EXTERNAL? SPA? YES. ELEMENTARY, MY DEAR. THIRD PARTY? GET REQUEST TO /POSTS/ ENDPOINT WELL, SORT OF
  • 10. LATEST NEWS? THIRD PARTY? CUSTOM JSON? SYNCH’ING? EXTERNAL? SPA? Example: • include vendor js • add outbrain data attributes • fallback: WP REST API
  • 11. LATEST NEWS? THIRD PARTY? CUSTOM JSON? SYNCH’ING? EXTERNAL? SPA? var apiUrl = 'http://' + location.host + '/wp-json/wp/v2/posts/'; // Fallback if OBR not available if ( typeof OBR === 'undefined' ) { $( getAll('poweredByOutbrain') ).remove(); return $.getJSON( apiUrl, function(res) { if ( elementId === 'we-recommend' ) { return smart.rec( get('we-recommend') ); } } }
  • 12. LATEST NEWS? THIRD PARTY? CUSTOM JSON? SYNCH’ING? EXTERNAL? SPA? smart = (function() { var mostRecent = function( target, apiUrl ) { function render( res ) { var frag = document.createDocumentFragment(); var data = res.slice( 0, 5 ); data.forEach(function( value, i ) { var currLi = document.createElement('li'); .... frag.appendChild( currLi ); }); return target.appendChild( frag ); } return $.getJSON( apiUrl, render ); }; return { rec: mostRecent }; }());
  • 13. YES, WITH MY CONDOLENCESCUSTOM JSON? GET REQUEST TO CUSTOM ENDPOINT THIRD PARTY? CUSTOM JSON? SYNCH’ING? EXTERNAL? SPA?LATEST NEWS?
  • 14. THIRD PARTY? CUSTOM JSON? SYNCH’ING? EXTERNAL? SPA? Example: • Custom endpoint • Parse WP post content to markdown • Output in Apple Native Format LATEST NEWS?
  • 15. LATEST NEWS? THIRD PARTY? CUSTOM JSON? SYNCH’ING? EXTERNAL? SPA? register_rest_route( 'apple-news/v2', '/post/(?P<post_id>w+)', array( 'methods' => WP_REST_Server::READABLE, 'callback' => array( $this, 'rest_post_output' ), 'args' => array( 'bundle', 'images', 'template', ), ) );
  • 16. LATEST NEWS? THIRD PARTY? CUSTOM JSON? SYNCH’ING? EXTERNAL? SPA? Apple News Plugin ParserWP DB
  • 17. LATEST NEWS? THIRD PARTY? CUSTOM JSON? SYNCH’ING? EXTERNAL? SPA? Apple News Plugin Parser Apple News Custom JSON
  • 18. LATEST NEWS? THIRD PARTY? CUSTOM JSON? SYNCH’ING? EXTERNAL? SPA? Apple News Plugin Parser Apple News Custom JSON { "role": "gallery", "layout": "carouselLayoutNoTop", "items": [ { "path": "http://www.wired.com/wp-content/uploads/2016/01/CES_07-NEW- NEW2.jpg", "URL": "bundle://CES_07-NEW-NEW2.jpg", "caption": "Drones as far as the eye can see." }, { "path": "http://www.wired.com/wp-content/uploads/2016/01/CES_11-NEW- NEW2.jpg", "URL": "bundle://CES_11-NEW-NEW2.jpg", "caption": "There are still some old-school immersion tactics. This attendee is sitting through a pre-programmed routine to lower his heart rate and help him feel more relaxed." } ] }
  • 19. LATEST NEWS? THIRD PARTY? CUSTOM JSON? SYNCH’ING? EXTERNAL? SPA? Apple News Preview (simulators) Apple News Custom JSON
  • 20. YEP, WE CAN AUTOMATE THAT SYNCH’ING? POST REQUEST TO CREATE POSTS ON PUBLISH HOOK THIRD PARTY? CUSTOM JSON? SYNCH’ING? EXTERNAL? SPA?LATEST NEWS?
  • 21. THIRD PARTY? CUSTOM JSON? SYNCH’ING? EXTERNAL? SPA? Example: Betta Beta Data Getta • Publish/update hook • Make POST request via WP REST API with post_id LIVE: www.wired.com BETA: beta.wired.com 1. data-push 1 LATEST NEWS?
  • 22. THIRD PARTY? CUSTOM JSON? SYNCH’ING? EXTERNAL? SPA? Example: Betta Beta Data Getta • Validate request • Make GET request via WP REST API for post_id • Create post LIVE: www.wired.com BETA: beta.wired.com 2. data-pull 2 LATEST NEWS?
  • 23. LATEST NEWS? THIRD PARTY? CUSTOM JSON? SYNCH’ING? EXTERNAL? SPA? public function __construct() { add_action( 'wp_insert_post', array( $this, 'notify_beta_site_post' ), 100, 3 ); } public function notify_beta_site_post( $post_id, $post, $update ) { $this->update_object( $post_id, 'post' ); } public function update_object( $post_id, $object ) { $this->make_request( $post_id, $object ); }
  • 24. LATEST NEWS? THIRD PARTY? CUSTOM JSON? SYNCH’ING? EXTERNAL? SPA? public function make_request( $id, $object ) { // example: 'http://beta.wired.com/?beta-push=1'; $request_url = $this->get_request_url(); $request_args = array( 'body' => array( 'id' => absint( $id ), 'object' => $object, ), 'headers' => array( 'api-key' => DATA_PUSH_API_KEY, 'api-secret' => DATA_PUSH_API_SECRET, ), 'blocking' => false, ); $result = wp_remote_post( $request_url, $request_args ); }
  • 25. LATEST NEWS? THIRD PARTY? CUSTOM JSON? SYNCH’ING? EXTERNAL? SPA? public function __construct() { add_action( 'init', array( $this, 'route_pull_request' ), 11 ); } public function route_pull_request() { if ( ! $this->validate_request() ) { return; } $id = $this->get_request_id(); $object = $this->get_request_object(); // ex: ‘post’ $data = $this->get_data( $id, 'post' ); $result = $this->save_response_post( $id, $data ); exit(); }
  • 26. LATEST NEWS? THIRD PARTY? CUSTOM JSON? SYNCH’ING? EXTERNAL? SPA? public function get_data( $id, $object ) { $data = array(); $request_url = get_request_url_post( $id ); // example: https://www.wired.com/wp-json/posts/1234567?context=edit $response = wp_remote_get( $request_url, array_merge( $args ) ); if ( 200 === (int) wp_remote_retrieve_response_code( $response ) ) { $body = json_decode( wp_remote_retrieve_body( $response ), true ); // Check to make sure the data looks right if ( isset( $body['ID'], $body['title'] ) ) { $data = $body; } } return $data; }
  • 27. LATEST NEWS? THIRD PARTY? CUSTOM JSON? SYNCH’ING? EXTERNAL? SPA? public function save_response_post( $id, $data ) { $existing_post = get_post( $id ); $prepared_data = $this->prepare_post_data( $data, $id ); if ( empty( $existing_post ) ) { $result = wp_insert_post( $prepared_data ); } else { $result = wp_update_post( $prepared_data ); } foreach ( $data['post_meta'] as $meta ) { // Note that this will break serialized meta data. Our meta data does not include serialized meta data. update_post_meta( $result, $meta['key'], $this->$meta['value'] ); } return $result; }
  • 28. SURE, LET’S GET CREATIVE!EXTERNAL? POST REQUEST TO CREATE POSTS WITH AUTH THIRD PARTY? CUSTOM JSON? SYNCH’ING? EXTERNAL? SPA?LATEST NEWS?
  • 29. IN THE LOOP? THIRD PARTY? CUSTOM JSON? SYNCH’ING? EXTERNAL? SPA? Example: • Node application listens for requests from Slack • Bot invited to channel • Every comment or image creates a “liveblog update” post type via WP REST API • WP template w/ React updates content Liveblog
  • 30. LATEST NEWS? THIRD PARTY? CUSTOM JSON? SYNCH’ING? EXTERNAL? SPA? WP DBNode Serverslack
  • 31. IN THE LOOP? THIRD PARTY? CUSTOM JSON? SYNCH’ING? EXTERNAL? SPA?
  • 32. LATEST NEWS? THIRD PARTY? CUSTOM JSON? SYNCH’ING? EXTERNAL? SPA? var addPost = function(preparedMessage, authorID) { return function() { // example wpAPIUrl: http://www.wired.com/wp-json/ request( extend( requestBase, { method: 'POST', uri: config.wpAPIUrl() + '/liveblog', body: { type: 'liveblog', status: 'publish', title: preparedMessage.ts, content: preparedMessage.text, author: authorID, featured_image: (preparedMessage.featuredImageID) ? preparedMessage.featuredImageID : 0 } } ...
  • 33. LATEST NEWS? THIRD PARTY? CUSTOM JSON? SYNCH’ING? EXTERNAL? SPA? public function __construct() { add_action( 'rest_api_init', array( $this, 'register_routes' ) ); } public function register_routes() { // example: http://www.wired.com/wp-json/wired/v2/liveblog/1949283/ posts/ // React script hits this endpoint to grab the post objects register_rest_route( 'wired/v2', '/liveblog/(?P<post_id>w+)/posts', array( 'methods' => WP_REST_Server::READABLE, 'callback' => array( $this, 'posts_callback' ), 'args' => array( 'post_id', ), ) ); }
  • 34. LATEST NEWS? THIRD PARTY? CUSTOM JSON? SYNCH’ING? EXTERNAL? SPA? public function posts_callback( $request ) { $posts = ''; $params = $request->get_params(); $post_id = ( isset( $params['post_id'] ) ) ? absint( $params['post_id'] ) : 0; $posts = array( 'version' => time(), 'posts' => $this->get_liveblog_posts( $post_id ) ); return $posts; }
  • 35. LATEST NEWS? THIRD PARTY? CUSTOM JSON? SYNCH’ING? EXTERNAL? SPA? public function get_liveblog_posts( $post_id ) { $liveblog_meta = get_post_meta( $post_id, '_liveblog', true ); $query = new WP_Query( array( 'posts_per_page' => 500, 'post_type' => array( wired_get_liveblog_post()->post_type ), 'tax_query' => array( array( 'taxonomy' => wired_get_liveblog_post()->taxonomy, 'field' => 'name', 'terms' => $liveblog_meta['slack-channel-name'], )) ) ); if ( $query->have_posts() ) { while ( $query->have_posts() ) { $query->the_post(); $clean_posts[] = array( 'id' => get_the_ID(), ... ); }} wp_reset_postdata(); return $clean_posts; }
  • 36. YES, BECAUSE #NODEJSSPA? JSON OBJECTS #FTW! THIRD PARTY? CUSTOM JSON? SYNCH’ING? EXTERNAL? SPA?LATEST NEWS?
  • 37. THIRD PARTY? CUSTOM JSON? SYNCH’ING? EXTERNAL? SPA?LATEST NEWS? Example: Homepage Curator (in the future) • Dashboard: Replace WP posts admin table ajax with SPA using React components • Create custom WP REST API endpoint for homepage and all section fronts • Front end: Build homepage and section fronts with React components • Ability to swipe from section to section without reload
  • 38. THIRD PARTY? CUSTOM JSON? SYNCH’ING? EXTERNAL? SPA?LATEST NEWS?
  • 39. THIRD PARTY? CUSTOM JSON? SYNCH’ING? EXTERNAL? SPA?LATEST NEWS?
  • 40. THIRD PARTY? CUSTOM JSON? SYNCH’ING? EXTERNAL? SPA?LATEST NEWS?
  • 41. THIRD PARTY? CUSTOM JSON? SYNCH’ING? EXTERNAL? SPA? LATEST NEWS? NOPE. WELL, SORT OF. YES, WITH MY CONDOLENCES YEP, WE CAN AUTOMATE THAT SURE, LET’S GET CREATIVE! YES, BECAUSE #NODEJS
  • 42. THIRD PARTY? CUSTOM JSON? SYNCH’ING? EXTERNAL? SPA? All Code Samples in this Gist: http://bit.ly/day-of-rest-2016-kv Slides: http://www.slideshare.net/kvignos/wired-and-the-wp-rest-api LATEST NEWS?