KEMBAR78
Lean JS Deeply, but don't forget about PHP! | PDF
@royboy789
Learn JS Deeply, but
Don't Forget About PHP!
Roy Sivan | RoySivan.com | CalderaLearn.org
@royboy789
CalderaLearn.com
Hi I'm Roy
@royboy789
Senior Software Engineer | The Walt Disney Company
I teach about WordPress @calderalearn & @lynda
I am a member of The WP Crowd! @thewpcrowd
I blog @roysivan.com too!
@royboy789
What We're Covering Today
Intro to the WordPress REST API
Why JavaScript
Cake (not PHP)
Why PHP
PHP Business logic
WordPress PHP
@royboy789
What We're Covering Today
Josh Pollock and I have already covered it.
TheWPCrowd - Episode 43.
@royboy789
CalderaLearn.com
Quick Intro To The
WordPress REST API
What Is It? Why Is It Exciting? How Does It Work?
@royboy789
CalderaLabs.org
What Is The
WordPress
REST API??
@royboy789
CRUD Routes For WordPress Content
Posts
Users
Comments
Taxonomies
Sites
@royboy789
Post Routes
/wp/v2/posts
First page of posts
/wp/v2/posts/42
Post 42
/wp/v2/comments
First page of comments
@royboy789
This Is The WordPress REST API
@royboy789
@royboy789
CalderaLearn.com
Why JavaScript Good
Its yummy and nutritious!
@royboy789
“
CalderaLabs.org
“Learn JavaScript, Deeply”
- Matt M.
@royboy789
Why I JavaScript
Angular
Angular
Angular
Angular
Angular
React
@royboy789
Why I JavaScript… for reals
Headless WordPress, yas!
Create really custom UI
It is a great time to be a JS developer!
https://github.com/royboy789/Angular-Wordpress-Theme
https://github.com/WordPress-Admin-JavaScript-Boilerplate/ReactJS-Boilerplate
@royboy789
CalderaLearn.com
Time for Cake!
@royboy789
JK!!!!!!!!!!!!!! It is a pie.
The cake is a lie.
@royboy789
CalderaLearn.com
Why PHP?
@royboy789
Why PHP?
PHP isn’t going anywhere
PHP is stable
If you level up as a developer, there are just
as many PHP frameworks as good JS
frameworks
@royboy789
WordPress is PHP
@royboy789
So much PHP!
Ever notice those sneaky <?php tags?
The REST API is also built in PHP
The P in LAMP, LEMP, LNMP, LAPP, WAMP,
MAMP, XAMP(<- this one)P(<- sometimes this one)
@royboy789
“
CalderaLabs.org
“WordPress will be rebuilt in Node”
- Chief Editor of FakeWPNews.com
@royboy789
FALSE
“FALSE”
- Matt Cromwell
FALSE
FALSE
FALSE
@royboy789
WordPress & Node
For the foreseeable future, there is no reason
that WordPress will be magically rebuilt on
node.
If it is going to be rebuilt, it will stay PHP,
probably be PHP7 amazing.
@royboy789
API can be used without JS
@royboy789
API your stuff with PHP
You can use the REST API’s PHP classes to run
the functions a route does, except it is all
done server side without
wp_safe_remote_get/post
$request = new WP_REST_Request( 'GET', '/wp/v2/posts' );
@royboy789
PHP Frameworks
Just like there are JS frameworks to learn as you
become more advanced, there are PHP frameworks. You
can build advanced functionality with one of these, still
communicating to your WordPress data
Laravel, Symfony - popular, good
Phalcon, CakePHP - not as popular, still good
@royboy789
CalderaLearn.com
Ok, but seriously
I mean, you’re wearing an Angular hat.
@royboy789
Use JS for what it is good for
JavaScript is good for
Client Side Render of UI
nothing more
@royboy789
CalderaLearn.com
PHP Means Business
Don’t mess with it.
@royboy789
Business Logic Code
Business logic is the code that is,
functionality wise, the meat of your business.
Ex: If you run a Woocommerce store, the creation of the order,
payment processing, and anything else check out related that
happens before the “thank you” page- Business Logic
@royboy789
Business Logic in API
JavaScript is best used for UI
leave it that way!
JavaScript can hit the API
API will do all the logic
Send back appropriate data to modify UI
@royboy789
Business Logic in API - Example
1. Your JS checkout app sends call with data to API
2. API handles all Woo code to create order
3. API handles all Woo code to create payment
4. API handles all Woo code to finalize order
5. Data sent back is just the final success / failure, and
order ID (and associated meta)
@royboy789
Extend the API for Business Logic
As you need more business logic code, extending the API
is the way to go… and that is done (should be done) in
PHP
Create custom routes & endpoints for your business
logic
Use the REST API to create your own REST API
@royboy789
Extend the API for Business Logic
@royboy789
CalderaLearn.com
WordPress PHP
The WP Way
@royboy789
WordPress PHP
Want to learn something deeply?
Learn the WordPress way of doing things!
@royboy789
WordPress PHP
Actions & Filters
wp_enqueue_ & wp_localize_object
Create Plugins -
Stop using functions.php as a catch-all for your advanced functionality
Create Custom Themes -
Go ahead, try it
@royboy789
Questions?
@royboy789
Places To Learn More PHP
Caldera Learn.com
WordPress TV - WordPress.tv/?s=rest+api
Lynda.com
CalderaLearn.com
Caldera Learn teaches through 4-week live classroom
style webinars.
Teachers are Josh Pollock and Roy Sivan
@royboy789
CalderaLearn.com
Thank You
@royboy789
RoySivan.com
TheWPCrowd.com
CalderaLearn.com
Lynda.com/Roy-Sivan/5111285-1.htmlYou’re Welcome Matt

Lean JS Deeply, but don't forget about PHP!