SlideShare a Scribd company logo
DOING THINGS THE

WordPress
             WAY


     By Matt Wiebe
  Theme Designer, Plugin Developer
Soma Design – http://somadesign.ca/
       Twitter – @mattwiebe
BRIEFLY ABOUT ME
THE ERUDITE
EVENTS CALENDAR PRO
EVENTS CALENDAR PRO
THE WP WAY
THE WP WAY
★ Loading JS/CSS
THE WP WAY
★ Loading JS/CSS
★ HTTP Requests
THE WP WAY
★ Loading JS/CSS
★ HTTP Requests
★ JSON
THE WP WAY
★ Loading JS/CSS
★ HTTP Requests
★ JSON
★ Email
THE WP WAY
★ Loading JS/CSS
★ HTTP Requests
★ JSON
★ Email
★ Query Arguments
LOADING JS/CSS
<script
type="text/javascript"
src="path/to/script.js"
/>
<link
rel="stylesheet"
href="path/to/style.css"

  type="text/css"
media="all"
/>
LOADING JS/CSS
<script
type="text/javascript"
src="path/to/script.js"
/>
<link
rel="stylesheet"
href="path/to/style.css"

  type="text/css"
media="all"
/>




    NEVER AGAIN
LOADING JS/CSS
wp_enqueue_script(
'script‐name',

'http://path/to/script.js',

array('jquery'),
'1.0',
true
);



Script ID – tells WP when to load,
helps track dependencies
LOADING JS/CSS
wp_enqueue_script(
'script‐name',

'http://path/to/script.js',

array('jquery'),
'1.0',
true
);



Script URL. Can be external.
LOADING JS/CSS
wp_enqueue_script(
'script‐name',

'http://path/to/script.js',

array('jquery'),
'1.0',
true
);



(Optional) Dependencies. Reference
the Script IDs scripts that should be
loaded before this one. (WP has many
built-in)
LOADING JS/CSS
wp_enqueue_script(
'script‐name',

'http://path/to/script.js',

array('jquery'),
'1.0',
true
);



(Optional) Version #.
LOADING JS/CSS
wp_enqueue_script(
'script‐name',

'http://path/to/script.js',

array('jquery'),
'1.0',
true
);



(Optional) Load in Footer. Defaults to
false, which loads in <head
/>
LOADING JS/CSS
//
Or,
register
first,
enqueue
later

wp_register_script(
'script‐name',

'http://path/to/script.js',

array('jquery'),
'1.0',
true
);

wp_enqueue_script(
'script‐name'
);
LOADING JS/CSS
//
Similar
for
styles

wp_enqueue_style(
'style‐name',
'http://
path/to/style.css',
array('deps'),
'1.0',

'media
type');
HTTP REQUESTS
//
How
does
this
curl
$h|†
work
again?
HTTP REQUESTS
//
How
does
this
curl
$h|†
work
again?

$c
=
curl_init();
curl_setop('ohcrapicantremember');
HTTP REQUESTS
//
How
does
this
curl
$h|†
work
again?

$c
=
curl_init();
curl_setop('ohcrapicantremember');

//
Screw
it
HTTP REQUESTS

★ Not all PHP environments have
cURL installed
HTTP REQUESTS

★ Not all PHP environments have
cURL installed
★ The WP_Http class Standardizes the
HTTP requests for WordPress. Handles
cookies, gzip encoding and decoding,
chunk decoding…
HTTP REQUESTS

★ Not all PHP environments have
cURL installed
★ The WP_Http class Standardizes the
HTTP requests for WordPress. Handles
cookies, gzip encoding and decoding,
chunk decoding…
★ wp_remote_* functions provided
HTTP REQUESTS
//
HTTP
GET
request
$get
=
wp_remote_get($url);
HTTP REQUESTS
//
HTTP
GET
request
$get
=
wp_remote_get($url);

//
HTTP
POST
request
$post
=
wp_remote_post($url,
$args);
HTTP REQUESTS
//
HTTP
GET
request
$get
=
wp_remote_get($url);

//
HTTP
POST
request
$post
=
wp_remote_post($url,
$args);

//
Just
the
response
body
$body
=
wp_remote_retrieve_body(
$get
);
HTTP REQUESTS
//
HTTP
GET
request
$get
=
wp_remote_get($url);

//
HTTP
POST
request
$post
=
wp_remote_post($url,
$args);

//
Just
the
response
body
$body
=
wp_remote_retrieve_body(
$get
);

//
Just
the
response
header
$h
=
wp_remote_retrieve_header(
$get
);
JSON
JSON
★ JSON (JavaScript Object Notation)
is the preferred way to exchange data
JSON
★ JSON (JavaScript Object Notation)
is the preferred way to exchange data
★ PHP 5.2 has json_encode() and
json_decode() functions
JSON
★ JSON (JavaScript Object Notation)
is the preferred way to exchange data
★ PHP 5.2 has json_encode() and
json_decode() functions
★ Many WP users are on earlier
versions of PHP
JSON
★ JSON (JavaScript Object Notation)
is the preferred way to exchange data
★ PHP 5.2 has json_encode() and
json_decode() functions
★ Many WP users are on earlier
versions of PHP
★ WP has a backwards compatibility
layer for PHP < 5.2 (since 2.9)
EMAIL
EMAIL
★ Sending email sucks
EMAIL
★ Sending email sucks
★ WP's mail sending functionality
makes it suck less
EMAIL
★ Sending email sucks
★ WP's mail sending functionality
makes it suck less
★ Centralizes all email so that it can
be overridden/manipulated by plugins
EMAIL
/**

*
$to
email
address(es)
to
send
to.

*
$subject
Email
subject

*
$message
Message
contents

*
$headers
Optional.
Additional
headers.

*
$attachments
Optional.
Files
to

*
attach.

*/

$success
=
wp_mail(
$to,
$subject,

$message,
$headers,
$attachments
);
QUERY ARGUMENTS
QUERY ARGUMENTS
//
already
have
$some_url
defined
//
want
to
add
a
query
string
QUERY ARGUMENTS
//
already
have
$some_url
defined
//
want
to
add
a
query
string

$some_url
.=
"?get=something+awesome";
QUERY ARGUMENTS
//
already
have
$some_url
defined
//
want
to
add
a
query
string

$some_url
.=
"?get=something+awesome";

//
what
if
$some_url
already
had
a
"?"
?
QUERY ARGUMENTS
//
already
have
$some_url
defined
//
want
to
add
a
query
string

$some_url
.=
"?get=something+awesome";

//
what
if
$some_url
already
had
a
"?"
?
//
add_query_arg()
to
the
rescue

$some_url
=
add_query_arg(
"get",

"something
awesome",
$some_url
);
QUERY ARGUMENTS
//
awesomer
syntax
QUERY ARGUMENTS
//
awesomer
syntax
$params
=
array(
 "get"
=>
"something
awesome",
 "for"
=>
"Matt",
 "because"
=>
"He's
awesome"
);
QUERY ARGUMENTS
//
awesomer
syntax
$params
=
array(
 "get"
=>
"something
awesome",
 "for"
=>
"Matt",
 "because"
=>
"He's
awesome"
);

$url
=
add_query_arg(
$params,
$url
);
QUERY ARGUMENTS
//
awesomer
syntax
$params
=
array(
 "get"
=>
"something
awesome",
 "for"
=>
"Matt",
 "because"
=>
"He's
awesome"
);

$url
=
add_query_arg(
$params,
$url
);

//
http://amazon.com/?get=something
+awesome&for=Matt&because=He's+awesome
BONUS ROUND
//
can't
remember
if
your
URL
has
//
a
slash
at
the
end?

$slashed_url
=
trailingslashit($url);

//
No
slashes

$unslashed_url
=
untrailingslashit($url);
BONUS ROUND
/**


*
merging
arguments
and
defaults?

*
$defaults
array
of
defaults

*
$args
accepts
an
array
or
query

*
string.
eg
cat_name=moo&tag=cow

*
@return
an
array
*/

$args
=
wp_parse_args(
$defaults,
$args);
BONUS ROUND
//
Override
WP's
jQuery
with
Google
CDN


add_action(
'wp_enqueue_scripts',

   'sd_google_cdn');
function
sd_google_cdn()
{
   wp_deregister_script(
'jquery'
);

    wp_enqueue_script(
'jquery',
'http://
    ajax.googleapis.com/ajax/libs/jquery/
    1.4.4/jquery.min.js',
array(),

    '1.4.4',
true
);
}
NOW YOU’LL DO THINGS THE

WordPress WAY
THANKS!
     By Matt Wiebe
  Theme Designer, Plugin Developer
Soma Design – http://somadesign.ca/
       Twitter – @mattwiebe

More Related Content

PPTX
WordPress Structure and Best Practices
PDF
The wp config.php
PDF
Write your first WordPress plugin
PDF
Cloud Automation with Opscode Chef
PDF
JSON REST API for WordPress
PDF
Intro to WordPress Plugin Development
PDF
Creating Your First WordPress Plugin
PDF
Installing And Configuration for your Wordpress blog
WordPress Structure and Best Practices
The wp config.php
Write your first WordPress plugin
Cloud Automation with Opscode Chef
JSON REST API for WordPress
Intro to WordPress Plugin Development
Creating Your First WordPress Plugin
Installing And Configuration for your Wordpress blog

What's hot (20)

PDF
WordCamp Finland 2015 - WordPress Security
PDF
Extending the WordPress REST API - Josh Pollock
PPTX
Take Command of WordPress With WP-CLI at WordCamp Long Beach
PPTX
Take Command of WordPress With WP-CLI
PDF
Mastering WordPress Vol.1
PPTX
WordPress Plugin development
PPTX
Worcamp2012 make a wordpress multisite in 20mins
PDF
You Don't Know Query - WordCamp Portland 2011
PDF
Chandra Prakash Thapa: Make a WordPress Multisite in 20 mins
PDF
WordCamp San Francisco 2011: Transients, Caching, and the Complexities of Mul...
PPTX
Saving Time with WP-CLI
PDF
WordCamp SF 2011: Debugging in WordPress
KEY
CSI: WordPress -- Getting Into the Guts
PPSX
Extending WordPress
PDF
Using composer with WordPress
PDF
Installing AtoM with Ansible
PDF
Jumping Into WordPress Plugin Programming
ODP
Pyramid Lighter/Faster/Better web apps
ODP
The Future Of WordPress Presentation
PDF
Theming 101
WordCamp Finland 2015 - WordPress Security
Extending the WordPress REST API - Josh Pollock
Take Command of WordPress With WP-CLI at WordCamp Long Beach
Take Command of WordPress With WP-CLI
Mastering WordPress Vol.1
WordPress Plugin development
Worcamp2012 make a wordpress multisite in 20mins
You Don't Know Query - WordCamp Portland 2011
Chandra Prakash Thapa: Make a WordPress Multisite in 20 mins
WordCamp San Francisco 2011: Transients, Caching, and the Complexities of Mul...
Saving Time with WP-CLI
WordCamp SF 2011: Debugging in WordPress
CSI: WordPress -- Getting Into the Guts
Extending WordPress
Using composer with WordPress
Installing AtoM with Ansible
Jumping Into WordPress Plugin Programming
Pyramid Lighter/Faster/Better web apps
The Future Of WordPress Presentation
Theming 101
Ad

Viewers also liked (17)

PPTX
Ithemes presentation
PDF
Managing_WordPress_Projects_wcstl 2015_Lucas_Lima
PPTX
Speeding Up WordPress sites
PDF
Launching a WordPress Site 101 (Cincinnati WordPress, August 2015)
PDF
Wordpress as a Backend
PDF
WordPress Custom Post Types
PPTX
Getting to Know Underscores
PPTX
Teresa Lane - Content Modeling - WordCamp St. Louis 2016
PPTX
Building a Simple Project Plan for WordPress Projects
PDF
Passwords, Attakcks, and Security, oh my!
PDF
Ryan Markel - WordCamp StL 2016 - Code Review
PDF
How to Make the Most out of Yoast SEO
PPTX
Creating Dynamic Sidebars & Widgets in WordPress
PPTX
(( Lucas lima )) Managing WordPress Projects - STL Meetup August 2015
KEY
Exploring WordPress Multisite
PPTX
Automating WordPress Plugin Development with Gulp
PDF
How to Become a Thought Leader in Your Niche
Ithemes presentation
Managing_WordPress_Projects_wcstl 2015_Lucas_Lima
Speeding Up WordPress sites
Launching a WordPress Site 101 (Cincinnati WordPress, August 2015)
Wordpress as a Backend
WordPress Custom Post Types
Getting to Know Underscores
Teresa Lane - Content Modeling - WordCamp St. Louis 2016
Building a Simple Project Plan for WordPress Projects
Passwords, Attakcks, and Security, oh my!
Ryan Markel - WordCamp StL 2016 - Code Review
How to Make the Most out of Yoast SEO
Creating Dynamic Sidebars & Widgets in WordPress
(( Lucas lima )) Managing WordPress Projects - STL Meetup August 2015
Exploring WordPress Multisite
Automating WordPress Plugin Development with Gulp
How to Become a Thought Leader in Your Niche
Ad

Similar to Doing Things the WordPress Way (20)

PPTX
Using WordPress as your application stack
PDF
WP HTTP API
PPT
Advanced and Hidden WordPress APIs
PPTX
From WordPress With Love
PDF
So, You Wanna Dev? Join the Team! - WordCamp Raleigh 2017
PPTX
Introduction to Plugin Programming, WordCamp Miami 2011
PDF
Getting Started with WP-CLI
KEY
WordPress - Open Source Overview Presentation
PDF
Building Web Apps with WordPress WordPress as an Application Framework Brian ...
PPTX
WordPress Themes 101 - PSUWeb13 Workshop
PPTX
WordPress Themes 101 - dotEduGuru Summit 2013
PDF
Laying the proper foundation for plugin and theme development
PDF
WordCamp Birmingham 2016 - WP API, What is it good for? Absolutely Everything!
PPTX
Integrating External APIs with WordPress
KEY
WordPress Developers Israel Meetup #1
PDF
Creating native apps with WordPress
KEY
&lt;?php + WordPress
PDF
WordCamp Raleigh 2016 - WP API, What is it good for? Absolutely Everything!
KEY
Intro to WordPress Plugins
PDF
eMusic: WordPress in the Enterprise
Using WordPress as your application stack
WP HTTP API
Advanced and Hidden WordPress APIs
From WordPress With Love
So, You Wanna Dev? Join the Team! - WordCamp Raleigh 2017
Introduction to Plugin Programming, WordCamp Miami 2011
Getting Started with WP-CLI
WordPress - Open Source Overview Presentation
Building Web Apps with WordPress WordPress as an Application Framework Brian ...
WordPress Themes 101 - PSUWeb13 Workshop
WordPress Themes 101 - dotEduGuru Summit 2013
Laying the proper foundation for plugin and theme development
WordCamp Birmingham 2016 - WP API, What is it good for? Absolutely Everything!
Integrating External APIs with WordPress
WordPress Developers Israel Meetup #1
Creating native apps with WordPress
&lt;?php + WordPress
WordCamp Raleigh 2016 - WP API, What is it good for? Absolutely Everything!
Intro to WordPress Plugins
eMusic: WordPress in the Enterprise

Recently uploaded (20)

PDF
Advanced Soft Computing BINUS July 2025.pdf
PDF
GDG Cloud Iasi [PUBLIC] Florian Blaga - Unveiling the Evolution of Cybersecur...
PDF
KodekX | Application Modernization Development
PDF
Approach and Philosophy of On baking technology
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
[발표본] 너의 과제는 클라우드에 있어_KTDS_김동현_20250524.pdf
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PDF
Machine learning based COVID-19 study performance prediction
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
solutions_manual_-_materials___processing_in_manufacturing__demargo_.pdf
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
NewMind AI Monthly Chronicles - July 2025
PDF
Modernizing your data center with Dell and AMD
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PPT
Teaching material agriculture food technology
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PPTX
Cloud computing and distributed systems.
Advanced Soft Computing BINUS July 2025.pdf
GDG Cloud Iasi [PUBLIC] Florian Blaga - Unveiling the Evolution of Cybersecur...
KodekX | Application Modernization Development
Approach and Philosophy of On baking technology
Unlocking AI with Model Context Protocol (MCP)
[발표본] 너의 과제는 클라우드에 있어_KTDS_김동현_20250524.pdf
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
Machine learning based COVID-19 study performance prediction
Diabetes mellitus diagnosis method based random forest with bat algorithm
solutions_manual_-_materials___processing_in_manufacturing__demargo_.pdf
Reach Out and Touch Someone: Haptics and Empathic Computing
CIFDAQ's Market Insight: SEC Turns Pro Crypto
The AUB Centre for AI in Media Proposal.docx
NewMind AI Monthly Chronicles - July 2025
Modernizing your data center with Dell and AMD
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Teaching material agriculture food technology
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Understanding_Digital_Forensics_Presentation.pptx
Cloud computing and distributed systems.

Doing Things the WordPress Way