SlideShare a Scribd company logo
WordPress
as an
Application
Framework
Dustin Filippini
Developer @ WebDevStudios
@dustyf
dustyf.com
WWhat Makes a Framework Good?
• Easy
• Well Supported
• Extensible
EASY
It does work
for you
Well
Supported
We are here to help!
Extensible
Add on More Dogs
A Real World Example
Create a billing/invoicing system using WordPress!
Think… FreshBooks
“I need an easy,
reusable way to
store, access,
and categorize
structured data”
Custom Post Types &
Custom Taxonomies.
function register_invoice() {
$args = array(
'public' => true,
'label' => 'Invoices'
);
register_post_type( 'invoice',$args );
}
add_action(‘init','register_invoice');
function create_invoice_status() {
register_taxonomy(
'status',
'invoice',
array(
'label' => ‘Invoice Status',
'rewrite' => array( 'slug' =>
‘invoice_status' ),
'hierarchical' => false,
)
);
}
add_action( 'init',
‘create_invoice_status' );
“I need to store
data related to
my structured
data and users.”
Post Meta and User Meta.
update_post_meta( $post_id,
‘purchase_order_number’, $value );
update_user_meta( $user_id, ‘job_title’,
$value );
“I need users to
be able to access
data and limit
access to
different users”
Create users and assign
roles and capabilities to
access different parts of
your application.
Built-in User Management panel and
ability to manipulate through your code.
ADD A NEW ROLE
add_role(
‘client',
‘Client',
array(
'read' => true,
'edit_posts' => true,
)
);
ADD A CAPABILITY TO THE ROLE
$role = get_role( ‘client' );
$role->add_cap( ‘view_invoices’ );
RESTRICT ACTION
if ( current_user_can( ‘view_invoices’ )
{
// Do Something
}
“I need to create
custom views
for different
types of data"
Templating through
WordPress Theme API.
Allows you to define different
templates for different types
of content and views.
BASIC WORDPRESS PAGE LOOP
get_header();
if (have_posts()) :
while (have_posts()) :
the_post();
the_content();
endwhile;
endif;
get_sidebar();
get_footer();
TEMPLATE FILE NAMING
single-invoices.php - Single Invoice
View
archive-invoices.php - Archive of
Invoices
LOADING CUSTOM TEMPLATES
get_template_part( 'loop', 'index' );
will do a PHP require() for the first
file that exists among these, in this
priority:
wp-content/themes/themename/loop-
index.php
wp-content/themes/themename/loop.php
“I need to
customize
default actions
of my app”
WordPress has hooks for nearly
everything that happens.
Use ‘add_action’ to do execute
custom code at a certain time.
Use ‘add_filter’ to change
default values.
function email_invoice( $post_id ) {
$to = ‘dusty@dustyf.com’;
$subject = get_the_title( $post_id );
$message =
get_the_permalink( $post_id );
wp_mail( $to, $subject, $message );
}
add_action(‘save_post’,‘email_invoice’);
function mod_title( $title, $post_id ) {
if (
‘invoice’ == get_post_type($post_id) &&
has_term( ‘paid’,
‘invoice_status’, $post_id
) {
$title = ‘PAID: ‘ . $title;
}
return $title;
}
add_filter( ‘the title’, ‘mod_title’,
10, 2 );
“I need easy,
secure, access
to the
database”
The wpdb class provides
easy, secure database
interaction for those times
you need it.
global $wpdb;
$results = $wpdb->get_results( 'SELECT *
FROM wp_options WHERE option_id = 1');
$wpdb->insert(
‘payments_made',
array(
'client' => 'Apple',
‘invoice_num' => 123
),
array(
'%s',
'%d'
)
);
// PROTECT FROM SQL INJECTION
$metakey = ‘purchase_order_num’;
$metavalue = ‘12345’;
$wpdb->query( $wpdb->prepare(
"INSERT INTO $wpdb->postmeta
( post_id, meta_key, meta_value )
VALUES ( %d, %s, %s )",
10,
$metakey,
$metavalue
) );
“I need to have
a reliable way
to rewrite
URLs”
WordPress rewrites posts,
pages, taxonomies, and
custom post types by
default. But, you can use
the Rewrite API to make
custom rules.
function custom_rewrite() {
add_rewrite_rule('^invoice/
([0-9]+)/?',
'index.php?page_id=$matches[1]',
'top');
}
add_action(‘init','custom_rewrite');
Now, you can access the same page as
http://example.com/invoice/95
“Different app
instances for
different users/
clients/
companies.”
WordPress multisite allows
you to create multiple site/
app instances. Each can
share or have different
functionality, views, settings,
userbases, and more.
Add the following to your wp-config.php
and follow the instructions in wp-admin
under Settings > Network Setup
define( 'WP_ALLOW_MULTISITE', true );
Use Case: Each company using this
invoice system can have their own
instance at their own url…
google.example.com or example.com/google
“I need to be
able to connect
with third-party
services”
Built in HTTP API supports
multiple transport methods
for your HTTP requests
because different hosting
environments support
different things.
$response = wp_remote_post( $url, array(
'method' => 'POST',
'timeout' => 45,
'redirection' => 5,
'httpversion' => '1.0',
'blocking' => true,
'headers' => array(),
'body' => array( 'username' =>
'bob', 'password' => '1234xyz' ),
'cookies' => array()
)
);
$response returns a nice array
AlSO:
wp_remote_request()
wp_remote_get()
wp_remote_post()
wp_remote_head()
wp_remote_retrieve_body()
wp_remote_retrieve_header()
wp_remote_retrieve_headers()
wp_remote_retrieve_response_code()
wp_remote_retrieve_response_message()
“I need to
improve
performance by
limiting requests”
Transients allow you quickly
store data with an expiration
for quick access.
Get more in depth with
caching plugins.
set_transient(
‘special_query’,
$special_query,
60*60*12
);
get_transient( 'special_query' );
//EXAMPLE
if ( false === ( $special_query =
get_transient( 'special_query' ) ) ) {
$special_query_results = new WP_Query(
'cat=5&order=random&tag=tech&post_met
a_key=thumbnail'
);
set_transient(
'special_query',
$special_query,
4 * HOUR_IN_SECONDS
);
}
- get_transient
- set_transient
- wp_cache_set
- wp_cache_get
“I need to be
able to open
my application
to third parties”
Create an API for your app
using the XML-RPC API or
the new JSON REST API
JSON REST API will be in WP Core soon,
but is now available in a stable plugin.
Out of the box provides:
• Endpoints for retrieving, creating,
editing, and deleting all built-in post
types and registered custom post types

• Also, media, users, taxonomies and meta

• Can be extended to support your other
types of data
“I don’t want to
create things that
have been done
hundreds of times
before”
Thousands of WordPress
Plugins both free and
premium. Also, feel free to
use other PHP Libraries.
35,000+ Free Plugins at wordpress.org/
plugins/ and many great premium plugins.
BuddyPress - Social Network
BBPress - Forums
BadgeOS - Award Achievements
CMB2 - Custom Fields and Metaboxes
Gravity Forms - Form Building
Posts 2 Posts - Relational post linking
WooCommerce - eCommerce
Events Calendar Pro - Calendar
Or build your own to use over and over
(or to share or sell!)
MOAR

EXAMPLES
WordPress is being used as
an application framework all
over the web.
Reactor by AppPresser
(http://reactor.apppresser.com/)
WP Powered application that builds
mobile applications from your WP site.
DesktopServer 4.0
(http://serverpress.com/)
Desktop application to create local
development sites.
ManageWP
(http://managewp.com/)
Upgrade, perform backups, monitor, track
statistics, and manage multiple WP
sites.
YMCA Y-MVP App
(http://www.ymcanyc.org/association/
pages/y-mvp)
iPad application used as a kiosk at YMCA
to allow members to scan card and log
exercise activities.
Frito-Lay Project Management
(http://liftux.com/portfolio/frito-lay-
creative-project-management-app/)
Custom project management app.
Easy
Well
Supported
Extensible
Go Forth
& Create Apps
Dustin Filippini
dusty@dustyf.com
@dustyf
dustyf.com
webdevstudios.com

More Related Content

What's hot

Dependency Injection with PHP and PHP 5.3
Dependency Injection with PHP and PHP 5.3Dependency Injection with PHP and PHP 5.3
Dependency Injection with PHP and PHP 5.3
Fabien Potencier
 
Decouple Your Code For Reusability (International PHP Conference / IPC 2008)
Decouple Your Code For Reusability (International PHP Conference / IPC 2008)Decouple Your Code For Reusability (International PHP Conference / IPC 2008)
Decouple Your Code For Reusability (International PHP Conference / IPC 2008)
Fabien Potencier
 
Система рендеринга в Magento
Система рендеринга в MagentoСистема рендеринга в Magento
Система рендеринга в Magento
Magecom Ukraine
 

What's hot (20)

Doctrine 2
Doctrine 2Doctrine 2
Doctrine 2
 
Be lazy, be ESI: HTTP caching and Symfony2 @ PHPDay 2011 05-13-2011
 Be lazy, be ESI: HTTP caching and Symfony2 @ PHPDay 2011 05-13-2011 Be lazy, be ESI: HTTP caching and Symfony2 @ PHPDay 2011 05-13-2011
Be lazy, be ESI: HTTP caching and Symfony2 @ PHPDay 2011 05-13-2011
 
Symfony2, creare bundle e valore per il cliente
Symfony2, creare bundle e valore per il clienteSymfony2, creare bundle e valore per il cliente
Symfony2, creare bundle e valore per il cliente
 
Advanced php testing in action
Advanced php testing in actionAdvanced php testing in action
Advanced php testing in action
 
Moving a high traffic ZF1 Enterprise Application to SF2 - Lessons learned
Moving a high traffic ZF1 Enterprise Application to SF2 - Lessons learnedMoving a high traffic ZF1 Enterprise Application to SF2 - Lessons learned
Moving a high traffic ZF1 Enterprise Application to SF2 - Lessons learned
 
Intro to advanced caching in WordPress
Intro to advanced caching in WordPressIntro to advanced caching in WordPress
Intro to advanced caching in WordPress
 
Dependency Injection with PHP and PHP 5.3
Dependency Injection with PHP and PHP 5.3Dependency Injection with PHP and PHP 5.3
Dependency Injection with PHP and PHP 5.3
 
Decouple Your Code For Reusability (International PHP Conference / IPC 2008)
Decouple Your Code For Reusability (International PHP Conference / IPC 2008)Decouple Your Code For Reusability (International PHP Conference / IPC 2008)
Decouple Your Code For Reusability (International PHP Conference / IPC 2008)
 
Perl object ?
Perl object ?Perl object ?
Perl object ?
 
Dependency Injection in Laravel
Dependency Injection in LaravelDependency Injection in Laravel
Dependency Injection in Laravel
 
PHPUnit でよりよくテストを書くために
PHPUnit でよりよくテストを書くためにPHPUnit でよりよくテストを書くために
PHPUnit でよりよくテストを書くために
 
Separation of concerns - DPC12
Separation of concerns - DPC12Separation of concerns - DPC12
Separation of concerns - DPC12
 
“Writing code that lasts” … or writing code you won’t hate tomorrow. - PHPKonf
“Writing code that lasts” … or writing code you won’t hate tomorrow. - PHPKonf“Writing code that lasts” … or writing code you won’t hate tomorrow. - PHPKonf
“Writing code that lasts” … or writing code you won’t hate tomorrow. - PHPKonf
 
Daily notes
Daily notesDaily notes
Daily notes
 
Command Bus To Awesome Town
Command Bus To Awesome TownCommand Bus To Awesome Town
Command Bus To Awesome Town
 
Система рендеринга в Magento
Система рендеринга в MagentoСистема рендеринга в Magento
Система рендеринга в Magento
 
WooCommerce CRUD and Data Store by Akeda Bagus
WooCommerce CRUD and Data Store by Akeda BagusWooCommerce CRUD and Data Store by Akeda Bagus
WooCommerce CRUD and Data Store by Akeda Bagus
 
Design how your objects talk through mocking
Design how your objects talk through mockingDesign how your objects talk through mocking
Design how your objects talk through mocking
 
Command-Oriented Architecture
Command-Oriented ArchitectureCommand-Oriented Architecture
Command-Oriented Architecture
 
Adding Dependency Injection to Legacy Applications
Adding Dependency Injection to Legacy ApplicationsAdding Dependency Injection to Legacy Applications
Adding Dependency Injection to Legacy Applications
 

Viewers also liked

Untitled Presentation
Untitled PresentationUntitled Presentation
Untitled Presentation
MMM GLOBAL
 
K5 kepelbagaian budaya
K5 kepelbagaian budayaK5 kepelbagaian budaya
K5 kepelbagaian budaya
normazua
 

Viewers also liked (13)

Vritti Product pictures
Vritti Product picturesVritti Product pictures
Vritti Product pictures
 
how can we control our self???
how can we control our self???how can we control our self???
how can we control our self???
 
SoPact-Social Impact
SoPact-Social ImpactSoPact-Social Impact
SoPact-Social Impact
 
Ética empresarial
Ética empresarialÉtica empresarial
Ética empresarial
 
Evaluation-Codes and Conventions
Evaluation-Codes and ConventionsEvaluation-Codes and Conventions
Evaluation-Codes and Conventions
 
Untitled Presentation
Untitled PresentationUntitled Presentation
Untitled Presentation
 
Батрак А.В.
Батрак А.В.Батрак А.В.
Батрак А.В.
 
Degree
DegreeDegree
Degree
 
Research Week 2014: CIHR: Opportunities, Eligibility, and Strategies for Success
Research Week 2014: CIHR: Opportunities, Eligibility, and Strategies for SuccessResearch Week 2014: CIHR: Opportunities, Eligibility, and Strategies for Success
Research Week 2014: CIHR: Opportunities, Eligibility, and Strategies for Success
 
K5 kepelbagaian budaya
K5 kepelbagaian budayaK5 kepelbagaian budaya
K5 kepelbagaian budaya
 
Performance Audit of CanIUse by PerfAudit
Performance Audit of CanIUse by PerfAuditPerformance Audit of CanIUse by PerfAudit
Performance Audit of CanIUse by PerfAudit
 
Innovations in Analytics for Academic Publishing and Research Networking
Innovations in Analytics for Academic Publishing and Research NetworkingInnovations in Analytics for Academic Publishing and Research Networking
Innovations in Analytics for Academic Publishing and Research Networking
 
K11 stres
K11 stresK11 stres
K11 stres
 

Similar to WordPress as an application framework

DrupalCamp Foz - Novas APIs Drupal 7
DrupalCamp Foz - Novas APIs Drupal 7DrupalCamp Foz - Novas APIs Drupal 7
DrupalCamp Foz - Novas APIs Drupal 7
chuvainc
 
Gail villanueva add muscle to your wordpress site
Gail villanueva   add muscle to your wordpress siteGail villanueva   add muscle to your wordpress site
Gail villanueva add muscle to your wordpress site
references
 
How to Create Login and Registration API in PHP.pdf
How to Create Login and Registration API in PHP.pdfHow to Create Login and Registration API in PHP.pdf
How to Create Login and Registration API in PHP.pdf
Appweb Coders
 

Similar to WordPress as an application framework (20)

WordPress REST API hacking
WordPress REST API hackingWordPress REST API hacking
WordPress REST API hacking
 
laravel tricks in 50minutes
laravel tricks in 50minuteslaravel tricks in 50minutes
laravel tricks in 50minutes
 
Doctrine For Beginners
Doctrine For BeginnersDoctrine For Beginners
Doctrine For Beginners
 
WordPress Kitchen 2014 - Александр Стриха: Кеширование в WordPress
WordPress Kitchen 2014 - Александр Стриха: Кеширование в WordPress WordPress Kitchen 2014 - Александр Стриха: Кеширование в WordPress
WordPress Kitchen 2014 - Александр Стриха: Кеширование в WordPress
 
The Zen of Lithium
The Zen of LithiumThe Zen of Lithium
The Zen of Lithium
 
CakePHP workshop
CakePHP workshopCakePHP workshop
CakePHP workshop
 
Unit testing zend framework apps
Unit testing zend framework appsUnit testing zend framework apps
Unit testing zend framework apps
 
[WLDN] Supercharging word press development in 2018
[WLDN] Supercharging word press development in 2018[WLDN] Supercharging word press development in 2018
[WLDN] Supercharging word press development in 2018
 
Dependency Injection
Dependency InjectionDependency Injection
Dependency Injection
 
Introduction to Zend Framework web services
Introduction to Zend Framework web servicesIntroduction to Zend Framework web services
Introduction to Zend Framework web services
 
Как получить чёрный пояс по WordPress?
Как получить чёрный пояс по WordPress?Как получить чёрный пояс по WordPress?
Как получить чёрный пояс по WordPress?
 
Speed Things Up with Transients
Speed Things Up with TransientsSpeed Things Up with Transients
Speed Things Up with Transients
 
DrupalCamp Foz - Novas APIs Drupal 7
DrupalCamp Foz - Novas APIs Drupal 7DrupalCamp Foz - Novas APIs Drupal 7
DrupalCamp Foz - Novas APIs Drupal 7
 
PHPSpec - the only Design Tool you need - 4Developers
PHPSpec - the only Design Tool you need - 4DevelopersPHPSpec - the only Design Tool you need - 4Developers
PHPSpec - the only Design Tool you need - 4Developers
 
You Don't Know Query (WordCamp Netherlands 2012)
You Don't Know Query (WordCamp Netherlands 2012)You Don't Know Query (WordCamp Netherlands 2012)
You Don't Know Query (WordCamp Netherlands 2012)
 
Zend framework service
Zend framework serviceZend framework service
Zend framework service
 
Zend framework service
Zend framework serviceZend framework service
Zend framework service
 
Gail villanueva add muscle to your wordpress site
Gail villanueva   add muscle to your wordpress siteGail villanueva   add muscle to your wordpress site
Gail villanueva add muscle to your wordpress site
 
You code sucks, let's fix it
You code sucks, let's fix itYou code sucks, let's fix it
You code sucks, let's fix it
 
How to Create Login and Registration API in PHP.pdf
How to Create Login and Registration API in PHP.pdfHow to Create Login and Registration API in PHP.pdf
How to Create Login and Registration API in PHP.pdf
 

Recently uploaded

Recently uploaded (20)

Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
 
UiPath Test Automation using UiPath Test Suite series, part 2
UiPath Test Automation using UiPath Test Suite series, part 2UiPath Test Automation using UiPath Test Suite series, part 2
UiPath Test Automation using UiPath Test Suite series, part 2
 
10 Differences between Sales Cloud and CPQ, Blanka Doktorová
10 Differences between Sales Cloud and CPQ, Blanka Doktorová10 Differences between Sales Cloud and CPQ, Blanka Doktorová
10 Differences between Sales Cloud and CPQ, Blanka Doktorová
 
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptxUnpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
 
Free and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
Free and Effective: Making Flows Publicly Accessible, Yumi IbrahimzadeFree and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
Free and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
 
In-Depth Performance Testing Guide for IT Professionals
In-Depth Performance Testing Guide for IT ProfessionalsIn-Depth Performance Testing Guide for IT Professionals
In-Depth Performance Testing Guide for IT Professionals
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
 
UiPath Test Automation using UiPath Test Suite series, part 1
UiPath Test Automation using UiPath Test Suite series, part 1UiPath Test Automation using UiPath Test Suite series, part 1
UiPath Test Automation using UiPath Test Suite series, part 1
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
 
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
 
Introduction to Open Source RAG and RAG Evaluation
Introduction to Open Source RAG and RAG EvaluationIntroduction to Open Source RAG and RAG Evaluation
Introduction to Open Source RAG and RAG Evaluation
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
 
IoT Analytics Company Presentation May 2024
IoT Analytics Company Presentation May 2024IoT Analytics Company Presentation May 2024
IoT Analytics Company Presentation May 2024
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
 
Exploring UiPath Orchestrator API: updates and limits in 2024 🚀
Exploring UiPath Orchestrator API: updates and limits in 2024 🚀Exploring UiPath Orchestrator API: updates and limits in 2024 🚀
Exploring UiPath Orchestrator API: updates and limits in 2024 🚀
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
 

WordPress as an application framework

  • 2.
  • 3.
  • 4.
  • 5. WWhat Makes a Framework Good? • Easy • Well Supported • Extensible
  • 9. A Real World Example Create a billing/invoicing system using WordPress! Think… FreshBooks
  • 10. “I need an easy, reusable way to store, access, and categorize structured data” Custom Post Types & Custom Taxonomies. function register_invoice() { $args = array( 'public' => true, 'label' => 'Invoices' ); register_post_type( 'invoice',$args ); } add_action(‘init','register_invoice'); function create_invoice_status() { register_taxonomy( 'status', 'invoice', array( 'label' => ‘Invoice Status', 'rewrite' => array( 'slug' => ‘invoice_status' ), 'hierarchical' => false, ) ); } add_action( 'init', ‘create_invoice_status' );
  • 11. “I need to store data related to my structured data and users.” Post Meta and User Meta. update_post_meta( $post_id, ‘purchase_order_number’, $value ); update_user_meta( $user_id, ‘job_title’, $value );
  • 12. “I need users to be able to access data and limit access to different users” Create users and assign roles and capabilities to access different parts of your application. Built-in User Management panel and ability to manipulate through your code. ADD A NEW ROLE add_role( ‘client', ‘Client', array( 'read' => true, 'edit_posts' => true, ) ); ADD A CAPABILITY TO THE ROLE $role = get_role( ‘client' ); $role->add_cap( ‘view_invoices’ ); RESTRICT ACTION if ( current_user_can( ‘view_invoices’ ) { // Do Something }
  • 13. “I need to create custom views for different types of data" Templating through WordPress Theme API. Allows you to define different templates for different types of content and views. BASIC WORDPRESS PAGE LOOP get_header(); if (have_posts()) : while (have_posts()) : the_post(); the_content(); endwhile; endif; get_sidebar(); get_footer(); TEMPLATE FILE NAMING single-invoices.php - Single Invoice View archive-invoices.php - Archive of Invoices LOADING CUSTOM TEMPLATES get_template_part( 'loop', 'index' ); will do a PHP require() for the first file that exists among these, in this priority: wp-content/themes/themename/loop- index.php wp-content/themes/themename/loop.php
  • 14. “I need to customize default actions of my app” WordPress has hooks for nearly everything that happens. Use ‘add_action’ to do execute custom code at a certain time. Use ‘add_filter’ to change default values. function email_invoice( $post_id ) { $to = ‘dusty@dustyf.com’; $subject = get_the_title( $post_id ); $message = get_the_permalink( $post_id ); wp_mail( $to, $subject, $message ); } add_action(‘save_post’,‘email_invoice’); function mod_title( $title, $post_id ) { if ( ‘invoice’ == get_post_type($post_id) && has_term( ‘paid’, ‘invoice_status’, $post_id ) { $title = ‘PAID: ‘ . $title; } return $title; } add_filter( ‘the title’, ‘mod_title’, 10, 2 );
  • 15. “I need easy, secure, access to the database” The wpdb class provides easy, secure database interaction for those times you need it. global $wpdb; $results = $wpdb->get_results( 'SELECT * FROM wp_options WHERE option_id = 1'); $wpdb->insert( ‘payments_made', array( 'client' => 'Apple', ‘invoice_num' => 123 ), array( '%s', '%d' ) ); // PROTECT FROM SQL INJECTION $metakey = ‘purchase_order_num’; $metavalue = ‘12345’; $wpdb->query( $wpdb->prepare( "INSERT INTO $wpdb->postmeta ( post_id, meta_key, meta_value ) VALUES ( %d, %s, %s )", 10, $metakey, $metavalue ) );
  • 16. “I need to have a reliable way to rewrite URLs” WordPress rewrites posts, pages, taxonomies, and custom post types by default. But, you can use the Rewrite API to make custom rules. function custom_rewrite() { add_rewrite_rule('^invoice/ ([0-9]+)/?', 'index.php?page_id=$matches[1]', 'top'); } add_action(‘init','custom_rewrite'); Now, you can access the same page as http://example.com/invoice/95
  • 17. “Different app instances for different users/ clients/ companies.” WordPress multisite allows you to create multiple site/ app instances. Each can share or have different functionality, views, settings, userbases, and more. Add the following to your wp-config.php and follow the instructions in wp-admin under Settings > Network Setup define( 'WP_ALLOW_MULTISITE', true ); Use Case: Each company using this invoice system can have their own instance at their own url… google.example.com or example.com/google
  • 18. “I need to be able to connect with third-party services” Built in HTTP API supports multiple transport methods for your HTTP requests because different hosting environments support different things. $response = wp_remote_post( $url, array( 'method' => 'POST', 'timeout' => 45, 'redirection' => 5, 'httpversion' => '1.0', 'blocking' => true, 'headers' => array(), 'body' => array( 'username' => 'bob', 'password' => '1234xyz' ), 'cookies' => array() ) ); $response returns a nice array AlSO: wp_remote_request() wp_remote_get() wp_remote_post() wp_remote_head() wp_remote_retrieve_body() wp_remote_retrieve_header() wp_remote_retrieve_headers() wp_remote_retrieve_response_code() wp_remote_retrieve_response_message()
  • 19. “I need to improve performance by limiting requests” Transients allow you quickly store data with an expiration for quick access. Get more in depth with caching plugins. set_transient( ‘special_query’, $special_query, 60*60*12 ); get_transient( 'special_query' ); //EXAMPLE if ( false === ( $special_query = get_transient( 'special_query' ) ) ) { $special_query_results = new WP_Query( 'cat=5&order=random&tag=tech&post_met a_key=thumbnail' ); set_transient( 'special_query', $special_query, 4 * HOUR_IN_SECONDS ); } - get_transient - set_transient - wp_cache_set - wp_cache_get
  • 20. “I need to be able to open my application to third parties” Create an API for your app using the XML-RPC API or the new JSON REST API JSON REST API will be in WP Core soon, but is now available in a stable plugin. Out of the box provides: • Endpoints for retrieving, creating, editing, and deleting all built-in post types and registered custom post types
 • Also, media, users, taxonomies and meta
 • Can be extended to support your other types of data
  • 21. “I don’t want to create things that have been done hundreds of times before” Thousands of WordPress Plugins both free and premium. Also, feel free to use other PHP Libraries. 35,000+ Free Plugins at wordpress.org/ plugins/ and many great premium plugins. BuddyPress - Social Network BBPress - Forums BadgeOS - Award Achievements CMB2 - Custom Fields and Metaboxes Gravity Forms - Form Building Posts 2 Posts - Relational post linking WooCommerce - eCommerce Events Calendar Pro - Calendar Or build your own to use over and over (or to share or sell!)
  • 22. MOAR
 EXAMPLES WordPress is being used as an application framework all over the web. Reactor by AppPresser (http://reactor.apppresser.com/) WP Powered application that builds mobile applications from your WP site. DesktopServer 4.0 (http://serverpress.com/) Desktop application to create local development sites. ManageWP (http://managewp.com/) Upgrade, perform backups, monitor, track statistics, and manage multiple WP sites. YMCA Y-MVP App (http://www.ymcanyc.org/association/ pages/y-mvp) iPad application used as a kiosk at YMCA to allow members to scan card and log exercise activities. Frito-Lay Project Management (http://liftux.com/portfolio/frito-lay- creative-project-management-app/) Custom project management app.
  • 23. Easy
  • 26. Go Forth & Create Apps Dustin Filippini dusty@dustyf.com @dustyf dustyf.com webdevstudios.com