SlideShare a Scribd company logo
1 of 22
Using WordPress as 
your application stack 
WHY AND HOW
@me 
Senior Full Stack WordPress Developer 
Plugin author of Author Avatars List http://wordpress.org/plugins/author-avatars/ 
and WP Site Verification tool http://wordpress.org/plugins/wp-site-verification-tool/ 
Slides @ http://www.slideshare.net/pbearne
Why WordPress? 
•Stable 
•Supported 
•Community 
•Scales
Why not WordPress? 
•Code debt 
•PHP 
•Has PHP global’s 
•Not sexy
23% 
OF THE SITES IN WHOLE INTERNET
34,000 
PLUG-INS
2,800 
THEMES
How 
•Actions and filters 
•JSON API 
•jQuery - Backbone 
•Template hierarchy 
•Custom post types
Filter 
add_filter(‘fliter_name’, ‘function_to_run’); 
Function function_to_run( $var ){ 
$var .= ‘hello world’; 
return $var; 
} 
http://codex.wordpress.org/Plugin_API#Filters
Action 
add_action(‘action_name’, ‘function_to_run’); 
Function function_to_run( $var = null ){ 
echo ‘hello world’; 
} 
http://codex.wordpress.org/Plugin_API#Actions
Ajax Route 
/** 
* Register a rewrite endpoint for the API. 
*/ 
function prefix_add_api_endpoints() { 
add_rewrite_tag( '%api_item_id%', '([0-9]+)' ); 
add_rewrite_rule( 'api/items/([0-9]+)/?', 
'index.php?api_item_id=$matches[1]', 'top' ); 
} 
add_action( 'init', 'prefix_add_api_endpoints' ); 
https://10up.github.io/Engineering-Best-Practices/php/#ajax-endpoints
Ajax handler 
function prefix_do_api() { 
global $wp_query; 
$item_id = $wp_query->get( 'api_item_id' ); 
if ( ! empty( $item_id ) ) { 
$response = array(); 
// Do stuff with $item_id 
wp_send_json( $response ); 
} 
} 
add_action( 'template_redirect', 'prefix_do_api' );
JSON API wordpress.com 
Part of the Jetpack plug-in 
http://developer.wordpress.com/docs/api/ 
https://developer.wordpress.com/docs/api/console/ 
End point 
https://public-api.wordpress.com/rest/v1/ 
e.g. 
https://public-api. 
wordpress.com/rest/v1/sites/authoravatars.wordpress.com/
JSON API wp.org (self host) 
Part of next version of core (currently plug-in) 
http://wp-api.org/ 
End point 
https://domain.com/wp-json/
JSON API wp-api.org/ v. WP.com 
WP.com 
Wp-api.org 
Caching 
On you server 
Little load on your servers 
Extendable 
Access to WordPress.com user and stats 
More complete 
The API’s don’t match (yet)
BackBone 
Included with WordPress  
To just load it 
wp_enqueue_script( ‘backbone’ ); 
Or better still load as a dependency of your script 
wp_enqueue_script( ‘myscript’, ‘path/to/script, array( 'backbone' ) ); 
https://github.com/tlovett1/_s_backbone
Template Hierarchy 
The order Wordpress load its template files 
http://codex.wordpress.org/Template_Hierarchy
Template Hierarchy
Custom post types 
The main logical data object 
in WordPress 
The standard types are : 
post, page, media 
add_action( 'init', 'create_post_type' ); 
function create_post_type() { 
register_post_type( 
'acme_product', 
array( 'labels' => array( 
'name' => __( 'Products' ), 
'singular_name' => __( 'Product' ) 
), 
'public' => true, 
'has_archive' => true, ) 
); 
} 
http://codex.wordpress.org/Post_Types
Custom metadata 
The data linked to a post object 
Text or serialized data 
Use CMB2 to easily create admin forms 
Hide the metadata from admin by 
starting the id with an “_” 
$meta_boxes[ 'tombstone_page_metabox' ] = array( 
'id' => __( 'tombstone_page_metabox', 
Config::get_text_domain() ), 
'title' => __( 'Tombstone Details', 
Config::get_text_domain() ), 
'object_types' => array( self::get_tombstone_post_type() ), 
https://github.com/WebDevStudios/CMB2 
// Post types 
'context' => 'normal', 
'priority' => 'high', 
'show_names' => true, // Show field names on the left 
'fields' => array( 
array( 
'name' => __( 'Tag line', Config::get_text_domain() 
), 
'desc' => __( 'Enter the pull Quote', 
Config::get_text_domain() ), 
'id' => Config::_get_prefix() . 'tagline', 
'type' => 'textarea_small', 
'attributes' => array( 
'style' => 'width:100%;', 
), 
), 
) 
);
Call external API and cache 
Use the internal 
wp_remote_get() get remote data. 
Then cache the data with a 
transients cache 
or 
tlc_transient() 
$request = wp_remote_get('http://example.com'); 
$response = wp_remote_retrieve_body( $request ); 
echo $response; 
<?php 
// Define your callback (other examples use 
this) 
function my_callback() { 
return wp_remote_retrieve_body( 
wp_remote_get( 'http://example.com/feed.xml', 
array( 'timeout' => 30 ) ) 
); 
} // Grab that feed echo 
$data = tlc_transient( 'example-feed' ) 
->updates_with( 'my_callback' ) 
->expires_in( 300 ) 
->get(); 
If( false != $data ){ 
// show data 
} 
?> 
https://github.com/markjaquith/WP-TLC-Transients
Questions? 
http://www.slideshare.net/pbearne

More Related Content

What's hot

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
Jeremy Kendall
 
Phpne august-2012-symfony-components-friends
Phpne august-2012-symfony-components-friendsPhpne august-2012-symfony-components-friends
Phpne august-2012-symfony-components-friends
Michael Peacock
 
Rails 3 overview
Rails 3 overviewRails 3 overview
Rails 3 overview
Yehuda Katz
 

What's hot (20)

An introduction to Laravel Passport
An introduction to Laravel PassportAn introduction to Laravel Passport
An introduction to Laravel Passport
 
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
 
REST APIs in Laravel 101
REST APIs in Laravel 101REST APIs in Laravel 101
REST APIs in Laravel 101
 
The Coolest Symfony Components you’ve never heard of - DrupalCon 2017
The Coolest Symfony Components you’ve never heard of - DrupalCon 2017The Coolest Symfony Components you’ve never heard of - DrupalCon 2017
The Coolest Symfony Components you’ve never heard of - DrupalCon 2017
 
Phpne august-2012-symfony-components-friends
Phpne august-2012-symfony-components-friendsPhpne august-2012-symfony-components-friends
Phpne august-2012-symfony-components-friends
 
Building Modern and Secure PHP Applications – Codementor Office Hours with Be...
Building Modern and Secure PHP Applications – Codementor Office Hours with Be...Building Modern and Secure PHP Applications – Codementor Office Hours with Be...
Building Modern and Secure PHP Applications – Codementor Office Hours with Be...
 
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
 
Creating REST Applications with the Slim Micro-Framework by Vikram Vaswani
Creating REST Applications with the Slim Micro-Framework by Vikram VaswaniCreating REST Applications with the Slim Micro-Framework by Vikram Vaswani
Creating REST Applications with the Slim Micro-Framework by Vikram Vaswani
 
RESTful web services
RESTful web servicesRESTful web services
RESTful web services
 
Bootstrat REST APIs with Laravel 5
Bootstrat REST APIs with Laravel 5Bootstrat REST APIs with Laravel 5
Bootstrat REST APIs with Laravel 5
 
Developing apps using Perl
Developing apps using PerlDeveloping apps using Perl
Developing apps using Perl
 
Childthemes ottawa-word camp-1919
Childthemes ottawa-word camp-1919Childthemes ottawa-word camp-1919
Childthemes ottawa-word camp-1919
 
Silex, the microframework
Silex, the microframeworkSilex, the microframework
Silex, the microframework
 
Inside Bokete: Web Application with Mojolicious and others
Inside Bokete:  Web Application with Mojolicious and othersInside Bokete:  Web Application with Mojolicious and others
Inside Bokete: Web Application with Mojolicious and others
 
Symfony 2
Symfony 2Symfony 2
Symfony 2
 
Mojolicious
MojoliciousMojolicious
Mojolicious
 
WordPress REST API hacking
WordPress REST API hackingWordPress REST API hacking
WordPress REST API hacking
 
Rails 4.0
Rails 4.0Rails 4.0
Rails 4.0
 
The Enterprise Wor/d/thy/Press
The Enterprise Wor/d/thy/PressThe Enterprise Wor/d/thy/Press
The Enterprise Wor/d/thy/Press
 
Rails 3 overview
Rails 3 overviewRails 3 overview
Rails 3 overview
 

Viewers also liked (7)

Daughter Themes
Daughter ThemesDaughter Themes
Daughter Themes
 
Vagrant WordCamp Hamilton
Vagrant  WordCamp HamiltonVagrant  WordCamp Hamilton
Vagrant WordCamp Hamilton
 
WordPress overloading Gravityforms using hooks, filters and extending classes
WordPress overloading Gravityforms using hooks, filters and extending classes WordPress overloading Gravityforms using hooks, filters and extending classes
WordPress overloading Gravityforms using hooks, filters and extending classes
 
Gravity Forms Hooks & Filters
Gravity Forms Hooks & FiltersGravity Forms Hooks & Filters
Gravity Forms Hooks & Filters
 
Tips and tricks for using wordpress as application platform.
Tips and tricks for using wordpress as application platform.Tips and tricks for using wordpress as application platform.
Tips and tricks for using wordpress as application platform.
 
Professional Frontend Engineering
Professional Frontend EngineeringProfessional Frontend Engineering
Professional Frontend Engineering
 
High Performance Web Sites - Tips for faster pages
High Performance Web Sites - Tips for faster pagesHigh Performance Web Sites - Tips for faster pages
High Performance Web Sites - Tips for faster pages
 

Similar to Using WordPress as your application stack

Rails 3: Dashing to the Finish
Rails 3: Dashing to the FinishRails 3: Dashing to the Finish
Rails 3: Dashing to the Finish
Yehuda Katz
 
Laying the proper foundation for plugin and theme development
Laying the proper foundation for plugin and theme developmentLaying the proper foundation for plugin and theme development
Laying the proper foundation for plugin and theme development
Tammy Hart
 
20130528 solution linux_frousseau_nopain_webdev
20130528 solution linux_frousseau_nopain_webdev20130528 solution linux_frousseau_nopain_webdev
20130528 solution linux_frousseau_nopain_webdev
Frank Rousseau
 
How Not to Build a WordPress Plugin
How Not to Build a WordPress PluginHow Not to Build a WordPress Plugin
How Not to Build a WordPress Plugin
Will Norris
 

Similar to Using WordPress as your application stack (20)

Custom post-framworks
Custom post-framworksCustom post-framworks
Custom post-framworks
 
Custom post-framworks
Custom post-framworksCustom post-framworks
Custom post-framworks
 
WordPress as the Backbone(.js)
WordPress as the Backbone(.js)WordPress as the Backbone(.js)
WordPress as the Backbone(.js)
 
Blog Hacks 2011
Blog Hacks 2011Blog Hacks 2011
Blog Hacks 2011
 
Rails 3: Dashing to the Finish
Rails 3: Dashing to the FinishRails 3: Dashing to the Finish
Rails 3: Dashing to the Finish
 
WordPress and Ajax
WordPress and AjaxWordPress and Ajax
WordPress and Ajax
 
Laying the proper foundation for plugin and theme development
Laying the proper foundation for plugin and theme developmentLaying the proper foundation for plugin and theme development
Laying the proper foundation for plugin and theme development
 
関西PHP勉強会 php5.4つまみぐい
関西PHP勉強会 php5.4つまみぐい関西PHP勉強会 php5.4つまみぐい
関西PHP勉強会 php5.4つまみぐい
 
Using and scaling Rack and Rack-based middleware
Using and scaling Rack and Rack-based middlewareUsing and scaling Rack and Rack-based middleware
Using and scaling Rack and Rack-based middleware
 
WordPress Plugin development
WordPress Plugin developmentWordPress Plugin development
WordPress Plugin development
 
Caldera Learn - LoopConf WP API + Angular FTW Workshop
Caldera Learn - LoopConf WP API + Angular FTW WorkshopCaldera Learn - LoopConf WP API + Angular FTW Workshop
Caldera Learn - LoopConf WP API + Angular FTW Workshop
 
Silex Cheat Sheet
Silex Cheat SheetSilex Cheat Sheet
Silex Cheat Sheet
 
Silex Cheat Sheet
Silex Cheat SheetSilex Cheat Sheet
Silex Cheat Sheet
 
WordPress for developers - phpday 2011
WordPress for developers -  phpday 2011WordPress for developers -  phpday 2011
WordPress for developers - phpday 2011
 
Digging into WordPress custom fields - WordCamp Brno 2017
Digging into WordPress custom fields - WordCamp Brno 2017Digging into WordPress custom fields - WordCamp Brno 2017
Digging into WordPress custom fields - WordCamp Brno 2017
 
CodeIgniter PHP MVC Framework
CodeIgniter PHP MVC FrameworkCodeIgniter PHP MVC Framework
CodeIgniter PHP MVC Framework
 
Developing Plugins For WordPress
Developing Plugins For WordPressDeveloping Plugins For WordPress
Developing Plugins For WordPress
 
20130528 solution linux_frousseau_nopain_webdev
20130528 solution linux_frousseau_nopain_webdev20130528 solution linux_frousseau_nopain_webdev
20130528 solution linux_frousseau_nopain_webdev
 
How Not to Build a WordPress Plugin
How Not to Build a WordPress PluginHow Not to Build a WordPress Plugin
How Not to Build a WordPress Plugin
 
Introduction to backbone presentation
Introduction to backbone presentationIntroduction to backbone presentation
Introduction to backbone presentation
 

More from Paul Bearne (6)

WP json api
WP json apiWP json api
WP json api
 
Unit tests with vagrant
Unit tests with vagrantUnit tests with vagrant
Unit tests with vagrant
 
How To Set a Vagrant Development System
How To Set a Vagrant Development SystemHow To Set a Vagrant Development System
How To Set a Vagrant Development System
 
HirshHorn theme: how I created it
HirshHorn theme: how I created itHirshHorn theme: how I created it
HirshHorn theme: how I created it
 
WortdPress Child themes: Why and How
WortdPress Child themes: Why and HowWortdPress Child themes: Why and How
WortdPress Child themes: Why and How
 
Author Avatars List demo slides
Author Avatars List demo slidesAuthor Avatars List demo slides
Author Avatars List demo slides
 

Recently uploaded

Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
masabamasaba
 
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
masabamasaba
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
masabamasaba
 

Recently uploaded (20)

%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the past
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
 
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
 
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptx
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare
 
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go Platformless
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
 

Using WordPress as your application stack

  • 1. Using WordPress as your application stack WHY AND HOW
  • 2. @me Senior Full Stack WordPress Developer Plugin author of Author Avatars List http://wordpress.org/plugins/author-avatars/ and WP Site Verification tool http://wordpress.org/plugins/wp-site-verification-tool/ Slides @ http://www.slideshare.net/pbearne
  • 3. Why WordPress? •Stable •Supported •Community •Scales
  • 4. Why not WordPress? •Code debt •PHP •Has PHP global’s •Not sexy
  • 5. 23% OF THE SITES IN WHOLE INTERNET
  • 8. How •Actions and filters •JSON API •jQuery - Backbone •Template hierarchy •Custom post types
  • 9. Filter add_filter(‘fliter_name’, ‘function_to_run’); Function function_to_run( $var ){ $var .= ‘hello world’; return $var; } http://codex.wordpress.org/Plugin_API#Filters
  • 10. Action add_action(‘action_name’, ‘function_to_run’); Function function_to_run( $var = null ){ echo ‘hello world’; } http://codex.wordpress.org/Plugin_API#Actions
  • 11. Ajax Route /** * Register a rewrite endpoint for the API. */ function prefix_add_api_endpoints() { add_rewrite_tag( '%api_item_id%', '([0-9]+)' ); add_rewrite_rule( 'api/items/([0-9]+)/?', 'index.php?api_item_id=$matches[1]', 'top' ); } add_action( 'init', 'prefix_add_api_endpoints' ); https://10up.github.io/Engineering-Best-Practices/php/#ajax-endpoints
  • 12. Ajax handler function prefix_do_api() { global $wp_query; $item_id = $wp_query->get( 'api_item_id' ); if ( ! empty( $item_id ) ) { $response = array(); // Do stuff with $item_id wp_send_json( $response ); } } add_action( 'template_redirect', 'prefix_do_api' );
  • 13. JSON API wordpress.com Part of the Jetpack plug-in http://developer.wordpress.com/docs/api/ https://developer.wordpress.com/docs/api/console/ End point https://public-api.wordpress.com/rest/v1/ e.g. https://public-api. wordpress.com/rest/v1/sites/authoravatars.wordpress.com/
  • 14. JSON API wp.org (self host) Part of next version of core (currently plug-in) http://wp-api.org/ End point https://domain.com/wp-json/
  • 15. JSON API wp-api.org/ v. WP.com WP.com Wp-api.org Caching On you server Little load on your servers Extendable Access to WordPress.com user and stats More complete The API’s don’t match (yet)
  • 16. BackBone Included with WordPress  To just load it wp_enqueue_script( ‘backbone’ ); Or better still load as a dependency of your script wp_enqueue_script( ‘myscript’, ‘path/to/script, array( 'backbone' ) ); https://github.com/tlovett1/_s_backbone
  • 17. Template Hierarchy The order Wordpress load its template files http://codex.wordpress.org/Template_Hierarchy
  • 19. Custom post types The main logical data object in WordPress The standard types are : post, page, media add_action( 'init', 'create_post_type' ); function create_post_type() { register_post_type( 'acme_product', array( 'labels' => array( 'name' => __( 'Products' ), 'singular_name' => __( 'Product' ) ), 'public' => true, 'has_archive' => true, ) ); } http://codex.wordpress.org/Post_Types
  • 20. Custom metadata The data linked to a post object Text or serialized data Use CMB2 to easily create admin forms Hide the metadata from admin by starting the id with an “_” $meta_boxes[ 'tombstone_page_metabox' ] = array( 'id' => __( 'tombstone_page_metabox', Config::get_text_domain() ), 'title' => __( 'Tombstone Details', Config::get_text_domain() ), 'object_types' => array( self::get_tombstone_post_type() ), https://github.com/WebDevStudios/CMB2 // Post types 'context' => 'normal', 'priority' => 'high', 'show_names' => true, // Show field names on the left 'fields' => array( array( 'name' => __( 'Tag line', Config::get_text_domain() ), 'desc' => __( 'Enter the pull Quote', Config::get_text_domain() ), 'id' => Config::_get_prefix() . 'tagline', 'type' => 'textarea_small', 'attributes' => array( 'style' => 'width:100%;', ), ), ) );
  • 21. Call external API and cache Use the internal wp_remote_get() get remote data. Then cache the data with a transients cache or tlc_transient() $request = wp_remote_get('http://example.com'); $response = wp_remote_retrieve_body( $request ); echo $response; <?php // Define your callback (other examples use this) function my_callback() { return wp_remote_retrieve_body( wp_remote_get( 'http://example.com/feed.xml', array( 'timeout' => 30 ) ) ); } // Grab that feed echo $data = tlc_transient( 'example-feed' ) ->updates_with( 'my_callback' ) ->expires_in( 300 ) ->get(); If( false != $data ){ // show data } ?> https://github.com/markjaquith/WP-TLC-Transients