2. There will be code
WP-API v1 code
There will be learning
There will be memes
Be Warned
3. WordPress developer at
Disney
and the co-founder of
My first install of WordPress was
0.7 and been a user &
developer since
Roy Sivan Twitter/Github - @royboy789 roysivan.com | arcctrl.com
Who is this geek?
10. THE RESPONSE - SERVER SIDE TECH VS. CLIENT SIDE TECH
One request to rule them all
“I want my blog posts”
SERVER - RETURNS PARSED HTML WP-API - RETURNS JSON
11. Benefits of Loading Client Side
Less load on the server
CDN all template files
Easier to cache JS and HTML
VERY Scalable
AJAX - can transform your UI / UX
15. Step 1: Custom Endpoints for you
(WP-API v1 - PHP)
function register_routes( $routes ) {
$routes[‘/my_route'] = array(
array( array( $this, ‘my_callback_function’),
WP_JSON_Server::CREATABLE |
WP_JSON_Server::ACCEPT_JSON
)
return $routes;
);
function my_callback_function() { …… }
16. // Get Pages
$.get( APIdata.wp_api_url + ‘/posts’, { ‘type’: ‘page’ }
.done( function( res ) {
do_something( res );
})
.fail( function( error ) {
console.log( error );
});
Step 2: Get Data from WP-API
(using jQuery)
17. /posts - WP-API endpoint
{
ID: 1
content: '<p>Welcome to WordPress. This is your first post. Edit or
delete it, then start blogging!</p>',
title: 'Hello world!',
status: 'publish',
author : {..},
...
},
…
Step 2.5: Get Data from WP-API
The response object
(JSON)
18. Step 3: Beautiful Template with the data
Code Example: Client Side Loop
(AngularJS)
//list all posts - this is HTML
<article class="postWrapper" ng-repeat="post in posts” >
<h3 class="page_title text-center">
<a href=“/coh/#/post/{{post.ID}}” class="content">
{{post.title}}
</a>
</h3>
{{post.content}}
</article>