SlideShare a Scribd company logo
1
Building Client Side
Applications with
WordPress & WP-API
Roy Sivan Twitter/Github - @royboy789 roysivan.com | arcctrl.com
There will be code

WP-API v1 code
There will be learning
There will be memes
Be Warned
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?
WHY?
Why build Web Applications
with WordPress?
WHY NOT
“MVC” - Client Side
M - Model ( WP )
V - VIEW ( THEME )
C - CONTROLLER
( PLUGINS )
HOW?
It’s the best!
POP QUIZ
What is the fastest
file a web server
can serve?
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
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
Single Page Web
Application
S.P.A
Not all client side apps
need to be full S.P.A’s.
Living on the client side
http://todomvc.com
wp_localize_script(
‘some-script',
'APIdata', array(
‘wp_api_url’ => esc_url_raw( get_json_url() ),
‘wp_api2_url’ => esc_url_raw( rest_get_url_prefix() . ‘/wp/v2/’ )
'api_nonce' => wp_create_nonce( 'wp_json' ),
'templateUrl' => get_stylesheet_directory( 'template_directory' )
)
);
Step 0: Setup Variable for WP-API url
(PHP)
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() { …… }
// 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)
/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)
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>
EXAMPLES?
Case Study: Client
Client
WordPress for:
Users

User Authentication

Custom Post Types

Data Storage
WP-API / S.P.A for:
DOM Memory

User Profiles

Inline Commenting

Inline Bookmarks
Case Study: CodeCavalry
CodeCavalry.com
WordPress for:
Users

User Authentication

Custom Post Types

Data Storage
S.P.A for:
Session (CPT) Create

Firebase - WebSocket

User Dashboard

User Profiles
Awesome Resources
Roy Sivan Twitter/Github - @royboy789 roysivan.com | arcctrl.com
WP-API on GitHub & Repository
https://github.com/WP-API/WP-API
https://wordpress.org/plugins/json-rest-api/
CodeCavalry
http://www.codecavalry.com
My Blog, AngularJS WP Theme & Plugin
http://www.roysivan.com/blog
http://www.roysivan.com/angular-wordpress-theme
http://www.roysivan.com/angularjs-for-wordpress
Thank You
Find me online:
Twitter: @royboy789
Github: @royboy789
CodeCavalry.com/royboy789
Roy Sivan Twitter/Github - @royboy789 roysivan.com | arcctrl.com

More Related Content

PDF
Building WordPress Client Side Applications with WP and WP-API - #wcmia
PDF
Client Side Applications with WP-API WordPress - WCMTL 2015
PDF
WordCamp San Diego 2015 - WordPress, WP-API, and Web Applications
PDF
WordPress and Client Side Web Applications WCTO
PDF
Wordcamp Toronto Presentation
ODP
Joomla REST API
PDF
Top 8 Ruby on Rails Gems
PPTX
The WordPress REST API as a Springboard for Website Greatness
Building WordPress Client Side Applications with WP and WP-API - #wcmia
Client Side Applications with WP-API WordPress - WCMTL 2015
WordCamp San Diego 2015 - WordPress, WP-API, and Web Applications
WordPress and Client Side Web Applications WCTO
Wordcamp Toronto Presentation
Joomla REST API
Top 8 Ruby on Rails Gems
The WordPress REST API as a Springboard for Website Greatness

What's hot (20)

PPTX
Phonegap Day 2016: Ember/JS & Hybrid Apps Tips
PDF
A Debugging Adventure: Journey through Ember.js Glue
PDF
Why Would A Programmer Fall In Love With SPA?
PDF
WordPress REST API v2: Overview & Exploring
PPTX
WP REST API - Building a simple Web Application
PDF
Using CI for continuous delivery Part 2
PPTX
Java spring mysql without hibernate(2) (1)
PDF
API Prefetching - HTML5DevConf - Oct. 21, 2014
PDF
Introduction to VueJS & The WordPress REST API
PDF
Pundit
PDF
Behavior Driven Development with Cucumber
PDF
How angularjs saves rails
PPTX
Oracle APEX & PhoneGap
PDF
AngularJS meets Rails
PDF
Teaming up WordPress API with Backbone.js in Titanium
PPTX
HTML5 Web Workers-unleashed
PPTX
Devise and Rails
PDF
JavaScript & AJAX in WordPress
PDF
[GeekTalk#2] Takaaki Mizuno - Api Url Design
PDF
Unleash the power of HTTP with ASP.NET Web API
Phonegap Day 2016: Ember/JS & Hybrid Apps Tips
A Debugging Adventure: Journey through Ember.js Glue
Why Would A Programmer Fall In Love With SPA?
WordPress REST API v2: Overview & Exploring
WP REST API - Building a simple Web Application
Using CI for continuous delivery Part 2
Java spring mysql without hibernate(2) (1)
API Prefetching - HTML5DevConf - Oct. 21, 2014
Introduction to VueJS & The WordPress REST API
Pundit
Behavior Driven Development with Cucumber
How angularjs saves rails
Oracle APEX & PhoneGap
AngularJS meets Rails
Teaming up WordPress API with Backbone.js in Titanium
HTML5 Web Workers-unleashed
Devise and Rails
JavaScript & AJAX in WordPress
[GeekTalk#2] Takaaki Mizuno - Api Url Design
Unleash the power of HTTP with ASP.NET Web API
Ad

Similar to How to build Client Side Applications with WordPress and WP-API | #wcmia (20)

PDF
WordCamp Raleigh 2016 - WP API, What is it good for? Absolutely Everything!
PPTX
Using WordPress as your application stack
PDF
WordCamp Wilmington 2017 WP-API Why?
PDF
Using the new WordPress REST API
PDF
Old WP REST API, New Tricks
PDF
WordCamp Birmingham 2016 - WP API, What is it good for? Absolutely Everything!
PPTX
Integrating External APIs with WordPress
PDF
JSON REST API for WordPress
PDF
JSON REST API for WordPress
PDF
Powering Content Driven Applications with the World’s Most Popular CMS #ngconf
PDF
WordPress as an application framework
PPTX
Beyond the Theme - Using WordPress as an API
PDF
WordPress is advancing rAPIdly - WordCamp San Antonio 2015
PPTX
WordPress Rest API
PDF
WordPress Café: Using WordPress as a Framework
PPTX
Build Modern Web Applications with React and WordPress
PDF
React with WordPress : Headless CMS
PDF
WORDPRESS_REST_API_WORDPRESS_REST_API.pdf
PDF
Maine WordPress Meetup JSON REST API, 3/16/2016
KEY
Doing Things the WordPress Way
WordCamp Raleigh 2016 - WP API, What is it good for? Absolutely Everything!
Using WordPress as your application stack
WordCamp Wilmington 2017 WP-API Why?
Using the new WordPress REST API
Old WP REST API, New Tricks
WordCamp Birmingham 2016 - WP API, What is it good for? Absolutely Everything!
Integrating External APIs with WordPress
JSON REST API for WordPress
JSON REST API for WordPress
Powering Content Driven Applications with the World’s Most Popular CMS #ngconf
WordPress as an application framework
Beyond the Theme - Using WordPress as an API
WordPress is advancing rAPIdly - WordCamp San Antonio 2015
WordPress Rest API
WordPress Café: Using WordPress as a Framework
Build Modern Web Applications with React and WordPress
React with WordPress : Headless CMS
WORDPRESS_REST_API_WORDPRESS_REST_API.pdf
Maine WordPress Meetup JSON REST API, 3/16/2016
Doing Things the WordPress Way
Ad

More from Roy Sivan (12)

PDF
WordPress in Enterprise
PDF
Building Gutenberg Applications & WebOPS Case Study
PDF
Building Headless Applications with WordPress & Gutenberg
PDF
Gutenberg & Custom Applications powered by WordPress
PDF
WordPress SFO Meetup - Gutenberg FAQ
PDF
WCSD - GutenWhat? A Gutenberg FAQ
PDF
A Crash Course in WordPress Gutenberg
PDF
WPCampus Online - The Case for the WordPress REST API
PDF
Angular Remote Conf - Building with Angular & WordPress
PDF
The Case for the WordPress REST API | WordCamp Montreal 2016
PDF
Building a JavaScript App powered by WordPress & AngularJS
PDF
Becoming a WordPress Artisan - Developer
WordPress in Enterprise
Building Gutenberg Applications & WebOPS Case Study
Building Headless Applications with WordPress & Gutenberg
Gutenberg & Custom Applications powered by WordPress
WordPress SFO Meetup - Gutenberg FAQ
WCSD - GutenWhat? A Gutenberg FAQ
A Crash Course in WordPress Gutenberg
WPCampus Online - The Case for the WordPress REST API
Angular Remote Conf - Building with Angular & WordPress
The Case for the WordPress REST API | WordCamp Montreal 2016
Building a JavaScript App powered by WordPress & AngularJS
Becoming a WordPress Artisan - Developer

How to build Client Side Applications with WordPress and WP-API | #wcmia

  • 1. 1 Building Client Side Applications with WordPress & WP-API Roy Sivan Twitter/Github - @royboy789 roysivan.com | arcctrl.com
  • 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?
  • 5. Why build Web Applications with WordPress? WHY NOT
  • 6. “MVC” - Client Side M - Model ( WP ) V - VIEW ( THEME ) C - CONTROLLER ( PLUGINS )
  • 9. POP QUIZ What is the fastest file a web server can serve?
  • 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
  • 12. Single Page Web Application S.P.A Not all client side apps need to be full S.P.A’s.
  • 13. Living on the client side http://todomvc.com
  • 14. wp_localize_script( ‘some-script', 'APIdata', array( ‘wp_api_url’ => esc_url_raw( get_json_url() ), ‘wp_api2_url’ => esc_url_raw( rest_get_url_prefix() . ‘/wp/v2/’ ) 'api_nonce' => wp_create_nonce( 'wp_json' ), 'templateUrl' => get_stylesheet_directory( 'template_directory' ) ) ); Step 0: Setup Variable for WP-API url (PHP)
  • 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>
  • 21. Client WordPress for: Users
 User Authentication
 Custom Post Types
 Data Storage WP-API / S.P.A for: DOM Memory
 User Profiles
 Inline Commenting
 Inline Bookmarks
  • 23. CodeCavalry.com WordPress for: Users
 User Authentication
 Custom Post Types
 Data Storage S.P.A for: Session (CPT) Create
 Firebase - WebSocket
 User Dashboard
 User Profiles
  • 24. Awesome Resources Roy Sivan Twitter/Github - @royboy789 roysivan.com | arcctrl.com WP-API on GitHub & Repository https://github.com/WP-API/WP-API https://wordpress.org/plugins/json-rest-api/ CodeCavalry http://www.codecavalry.com My Blog, AngularJS WP Theme & Plugin http://www.roysivan.com/blog http://www.roysivan.com/angular-wordpress-theme http://www.roysivan.com/angularjs-for-wordpress
  • 25. Thank You Find me online: Twitter: @royboy789 Github: @royboy789 CodeCavalry.com/royboy789 Roy Sivan Twitter/Github - @royboy789 roysivan.com | arcctrl.com