SlideShare una empresa de Scribd logo
1 de 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

Más contenido relacionado

La actualidad más candente

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
 

La actualidad más candente (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
 

Destacado (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 a 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 a 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
 

Más de 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
 

Último

CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
anilsa9823
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
Health
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
anilsa9823
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
mohitmore19
 

Último (20)

call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
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...
 
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-...
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 

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