SlideShare une entreprise Scribd logo
1  sur  34
Télécharger pour lire hors ligne
How to become a better WordPress
Developer
1
WPDAY - BOLOGNA - SEPTEMBER, 13 2013
DANILO ERCOLI
AGENDA
WPDAY BOLOGNA - SEPTEMBER, 13 2013
• Development Tools
• The WordPress Codex
• Coding Standards
• Data Validation
• wpshell
• Caching
• Debugging
WORDPRESS DEVELOPMENT
TOOLS
WPDAY BOLOGNA - SEPTEMBER, 13 2013
DEVELOPMENT TOOLS
• A good IDE can help you program faster and better: Sublime Text 2, PHP Storm,
Eclipse for PHP, Netbeans for PHP, Coda
•Code completion, easy WordPress function reference, project management,
database editing, file comparison, FTP, debugging facilities
•Codex and PHP Manual always loaded in the browser
•Keep a copy of WordPress core in your IDE
•Use wpshell for fast testing. Use command line interface (wp-cli)
•Install XDebug on your local/remote installation (live debugging)
WPDAY BOLOGNA - SEPTEMBER, 13 2013
THE WORDPRESS CODEX
WPDAY BOLOGNA - SEPTEMBER, 13 2013
CODEX
•The WordPress codex, and PHP Manual always under your hands.
• codex: The online manual for WordPress Developers http://codex.wordpress.org
•The Codex is a wiki, meaning anyone can edit it. It grows and thrives off of
individual contributions from people like you
•The best starting place for learning about how to develop plugins
http://codex.wordpress.org/Writing_a_Plugin
•Working with Themes https://codex.wordpress.org/Theme_Development
•WordPress Coding Standards
http://codex.wordpress.org/WordPress_Coding_Standards
General information about coding standards for WordPress development
WPDAY BOLOGNA - SEPTEMBER, 13 2013
CODEX: CODINGS STANDARDS
•Single quotes unless you need to evaluate a variable
<?php echo 'a great string'; ?>
vs
<?php $dog_name = 'Winston';
echo "my dog's name is: $dog_name"; ?>
•Naming is important
$myGreatVariable = 2; //not so much
$my_great_variable = my_function(); //Correct
WPDAY BOLOGNA - SEPTEMBER, 13 2013
CODEX: CODINGS STANDARDS
•Yoda conditions
if ( $city == 'Montreal' )
vs.
if ( 'Montreal' == $city )
•Don’t get too clever
isset( $var ) || $var = some_function();
Easier to read:
if ( ! isset( $var ) )
$var = some_function();
WPDAY BOLOGNA - SEPTEMBER, 13 2013
WPSHELL
WPDAY BOLOGNA - SEPTEMBER, 13 2013
WPSHELL
• wpshell is a command line shell suitable for any php project, includes code
indexing, searching, and displaying built-in
• It gives you a command shell that accepts native PHP code as well as all
the functionality your regular WordPress install would give you
• http://code.trac.wordpress.org/ - http://hitchhackerguide.com/2011/11/13/
wpshell-a-shell-for-wordpress/
• This is intended for advanced developers. If you don’t know what you’re
doing you can easily mess up your WordPress install. You can delete posts/
users/anything in few commands
• I would not run this on production, but only in a local development
environment. We will run it in production on WordPress.com (but rollback is
easy there)
• Example: switch_to_blog( 11719333 ); $lastposts =
get_posts( 'numberposts=1' ); var_dump( $lastposts );
WPDAY BOLOGNA - SEPTEMBER, 13 2013
DEBUGGING
WPDAY BOLOGNA - SEPTEMBER, 13 2013
DEBUGGING TECHNIQUES
• echo
The simplest approach, useful for seeing what a value is during run-time.
This just outputs the value of a variable to a page you’re working on.
• var_dump() / print_r() / var_export()
These functions displays structured information of a variable.
• console.log() / alert()
If you’re writing Javascript, then you’ll probably be using one of these
approaches. Alert will pop up a blocking dialog that you need to confirm to
close (be careful about doing this in a loop!) while console.log() will write to
your browser’s developer’s console (accessible via Web Inspector, Firebug,
etc).
• debug_backtrace
The debug_backtrace() function generates a backtrace.
WPDAY BOLOGNA - SEPTEMBER, 13 2013
DEBUGGING TECHNIQUES
• PHP “Magic Constants”
Use PHP macros in combination with your various output techniques, like
so: sprintf(	
  "%s:	
  %s",	
  __FILE__,	
  __LINE__	
  )
Spamming this down a file/function will help you figure out the path of
execution, and also the last place your script was before “stopping” It can
generate a lot of output but it’s pretty useful at times
• error_log()
Instead of outputting a value directly to a page, using this to output it to your
sandbox’s (or production) php error log file.
error_log( print_r( $results, true ) );
It’s often handy to have a Terminal window open with the following
command running, which will show you the most recent entries in the log:
tail	
  -­‐f	
  /tmp/php-­‐errors
WPDAY BOLOGNA - SEPTEMBER, 13 2013
DEBUGGING TECHNIQUES
• My favorite logging combo
error_log( "Request headers : nn".var_export( my_get_request_headers(), true ) );
error_log( "backtrace: n" . print_r( debug_backtrace( DEBUG_BACKTRACE_PROVIDE_OBJECT, 2 ), 1 ) );
Request headers :
array (
'x-forwarded-for' => '151.28.191.79',
'x-ip-trail' => '151.28.191.79',
'x-forwarded-port' => '443',
'x-forwarded-proto' => 'https',
'host' => 'public-api.wordpress.com',
'connection' => 'close',
'authorization' => 'Bearer tra-lallero-trallalà-XXXX',
'accept' => '/',
'accept-encoding' => 'gzip, deflate',
'accept-language' => 'en;q=1, fr;q=0.9, de;q=0.8, ja;q=0.7, nl;q=0.6, it;q=0.5',
'content-type' => 'application/x-www-form-urlencoded; charset=utf-8',
'cookie' => 'wordpress_test_cookie=WP+Cookie+check',
'content-length' => '188',
'user-agent' => 'wp-iphone/3.7.1 (iPhone OS 6.1, iPhone Simulator) Mobile',
)
WPDAY BOLOGNA - SEPTEMBER, 13 2013
DEBUGGING TECHNIQUES
debug_backtrace:
Array
(
[0] => Array
(
[file] => /home/wpcom/public_html/wp-content/mu-plugins/push-notifications.php
[line] => 244
[function] => xmmp_log
[class] => Mobile_Push_Notifications
[object] => Mobile_Push_Notifications Object
(
[log_recipients:Mobile_Push_Notifications:private] => Array
(
[0] => daniloercoli@im.wordpress.com
)
[log_target_users:Mobile_Push_Notifications:private] => Array
(
[0] => eritreocazzulati
[1] => 7272jean
)
)
[type] => ->
[args] => Array
WPDAY BOLOGNA - SEPTEMBER, 13 2013
DEBUGGING TECHNIQUES
• Email!!
Email isn’t dead! You can send debugging information directly to an email
account using something like this:
mail(	
  'you@gmail.com',	
  'Really	
  Important	
  Debugging	
  Information',	
  print_r(	
  $important_data,	
  true	
  ),	
  'From:	
  
you@automattic.com'	
  );
Note that I like to use my direct @gmail.com address to get the fastest
possible delivery, and setting a From address can help avoid getting these
things sent to your spam folder.
•XDebug
If you’d like to connect to your ( remote | local ) server from your local
machine and use xdebug to get very detailed debug info, breakpoints, etc.
WPDAY BOLOGNA - SEPTEMBER, 13 2013
DEBUG PLUGINS
• Debug Bar
http://wordpress.org/extend/plugins/debug-bar/
Adds a debug menu to the admin bar that shows query, cache, and other
helpful debugging information.
• Debug-Bar-Extender
http://wordpress.org/extend/plugins/debug-bar-extender/
Extends the debug-bar plugin with additional tabs to measure runtimes
between checkpoints and lookup variable content. (Do not use in a
production site).
• Debug Bar Console
http://wordpress.org/extend/plugins/debug-bar-console/
Adds a PHP/MySQL console to the debug bar. Requires the debug bar
plugin.
WPDAY BOLOGNA - SEPTEMBER, 13 2013
CACHING
WPDAY BOLOGNA - SEPTEMBER, 13 2013
DIFFERENT TYPES OF CACHING
Full page caching
•WP Super Cache
•Batcache
•W3 Total Cache
Object level caching with native caching APIs
•W3 Total Cache
•WP File Cache
•APC
•Memcached Object Cache
WPDAY BOLOGNA - SEPTEMBER, 13 2013
FULL PAGE CACHE: BATCACHE
What is Batcache?
Batcache is a plugin to store and serve cached versions of rendered pages.
• Batcache uses memcached as its storage and is aimed at preventing a flood of
traffic from breaking your site. It does this by serving old pages to new users.
• This reduces the demand on the web server CPU and the database. It also
means some people may see a page that is up to 5 minutes old.
• Development testing showed a 40x reduction in page generation times: pages
generated in 200ms were served from the cache in 5ms.
• Traffic simulations with Siege demonstrate that WordPress can handle up to
twenty times more traffic with Batcache installed.
WPDAY BOLOGNA - SEPTEMBER, 13 2013
PAGE CACHE: BATCACHE
Who receives a cached pageview?
• By default, all new users receive a cached pageview.
• New users are defined as anybody who hasn’t interacted with your domain —
once they’ve left a comment or logged in, their cookies will ensure they get
fresh pages.
• Note that URLs with query strings are automatically exempt from Batcache.
$batcache['max_age'] = 300; // Expire batcache items aged this many
seconds (zero to disable it)
$batcache['times'] = 4; // Only batcache a page after it is accessed
this many times.
WPDAY BOLOGNA - SEPTEMBER, 13 2013
PAGE CACHE: BATCACHE
Because Batcache caches fully rendered pages, per-user interactions on
the server-side can be problematic.
This means usage of objects/functions like $_COOKIE, setcookie,
$_SERVER['HTTP_USER_AGENT'], and anything that’s unique to an
individual user cannot be relied on as the values may be cached and cross-
pollution can occur.
In most cases, any user-level interactions should be moved to client-side using
JavaScript.
In some cases, we can help you set up Batcache variants if you’re limiting your
interactions to a small set of distinct groups.
(e.g. serve different content for users depending on whether the cookie
“customer-type” is set, or equals “paid” or “pending”). Please get in touch if this
something you’re interested in setting up.
WPDAY BOLOGNA - SEPTEMBER, 13 2013
PAGE CACHE: BATCACHE
if ( Jetpack_User_Agent_Info::is_blackbeberry() ) {
! $batcache['unique']['mobile'] = 'blackberry';
} elseif ( Jetpack_User_Agent_Info::is_WindowsPhone7() ) {
! ! $batcache['unique']['mobile'] = 'windows-phone7';!
} elseif ( Jetpack_User_Agent_Info::is_S60_OSSBrowser() ) {
! $batcache['unique']['mobile'] = 'dumb';
} elseif ( in_array( jetpack_is_mobile( 'smart', true ), array( 'iphone' ) ) ) {
! $batcache['unique']['mobile'] = 'iphone';
} elseif ( jetpack_is_mobile( 'dumb' ) ) {
! $batcache['unique']['mobile'] = 'dumb';
}
Batcache Variants
WPDAY BOLOGNA - SEPTEMBER, 13 2013
WORDPRESS NATIVE CACHING APIS
Transients
• Persistent out of the box
• Stored in wp_options: _transient_{key}
• WordPress uses for certain internal functions
• set_, get_, and delete_transient()
Object Cache
•Not persistent without a plugin, such as W3 Total Cache or Memcached Object
Cache
•Storage depends on server's and plugin's capabilities
•Used extensively within WordPress Cache objects can be grouped
wp_cache_add(), _set, _get, _delete
WPDAY BOLOGNA - SEPTEMBER, 13 2013
DATA VALIDATION
WPDAY BOLOGNA - SEPTEMBER, 13 2013
PROPERLY VALIDATE, SANITIZE, AND ESCAPE YOUR DATA
Your code works, but is it safe?
Rule No. 1: Trust Nobody
The idea is that you should not assume that any data entered by the user is
safe. Nor should you assume that the data you’ve retrieved from the database
is safe – even if you had made it ‘safe’ prior to inserting it there.
•In fact, whether data can be considered ‘safe’ makes no sense without context.
•Sometimes the same data may be used in multiple contexts on the same page.
Rule No. 2: Validate on Input, Escape on Output
To escape is to take the data you may already have and help secure it prior to
rendering it for the end user
WPDAY BOLOGNA - SEPTEMBER, 13 2013
DATA VALIDATION
A must-read for WordPress contributors. Describes the functions used by
WordPress to validate and sanitize data. Developers should be familiar with these
functions and ideas
http://codex.wordpress.org/Data_Validation
WPDAY BOLOGNA - SEPTEMBER, 13 2013
VALIDATING: CHECKING USER INPUT
To validate is to ensure the data you’ve requested of the user matches what
they’ve submitted.
There are several core methods you can use for input validation; usage
obviously depends on the type of fields you’d like to validate.
http://codex.wordpress.org/Data_Validation#Input_Validation
Let’s take a look at an example.
<input id="my-zipcode" type="text" maxlength="5" name="my-zipcode" />
We’ve limited the input to five characters of input, but there’s no limitation on what
they can input. They could enter “11221″ or “eval(“. Or even more characters if they
change the HTML.
WPDAY BOLOGNA - SEPTEMBER, 13 2013
VALIDATING: CHECKING USER INPUT
1	
  $safe_zipcode	
  =	
  intval(	
  $_POST['my-­‐zipcode']	
  );
2	
  if	
  (	
  !	
  $safe_zipcode	
  )
3	
  	
  	
  $safe_zipcode	
  =	
  '';
4	
  update_post_meta(	
  $post-­‐>ID,	
  'my_zipcode',	
  $safe_zipcode	
  );
The intval() function casts user input as an integer, and defaults to zero if the
input was a non-numeric value.
We then check to see if the value ended up as zero. If it did, we’ll save an empty
value to the database. Otherwise, we’ll save the properly validated zipcode.
WPDAY BOLOGNA - SEPTEMBER, 13 2013
SANITIZING: CLEANING USER INPUT
Whereas validation is concerned with making sure data is valid – data
sanitization is about making it safe. Even ‘valid’ data might be unsafe in certain
contexts.
You cannot ask “How do I make this data safe?”. Instead you should ask, “How
do I make this data safe for using it in X”.
<input	
  id="title"	
  type="text"	
  name="title"	
  />
Tex$title	
  =	
  sanitize_text_field(	
  $_POST['title']	
  );
2
update_post_meta(	
  $post-­‐>ID,	
  'title',	
  $title	
  );
t
We could sanitize the data with the sanitize_text_field() function:
WPDAY BOLOGNA - SEPTEMBER, 13 2013
SANITIZING: CLEANING USER INPUT
Behinds the scenes, the function does the following:
• Checks for invalid UTF-8
• Converts single < characters to entity
• Strips all tags
• Remove line breaks, tabs and extra white space
• Strip octets
The sanitize_*() class of helper functions are super nice for us, as they ensure
we’re ending up with safe data and require minimal effort on our part.
WPDAY BOLOGNA - SEPTEMBER, 13 2013
ESCAPING: SECURING OUTPUT
For security on the other end of the spectrum, we have escaping.
To escape is to take the data you may already have and help secure it prior to
rendering it for the end user.
WordPress thankfully has a few helper functions we can use for most of what
we’ll commonly need to do:
esc_html() we should use anytime our HTML element encloses a section of
data we’re outputting.
</pre>
<h4><!-­‐-­‐?php	
  echo	
  esc_html(	
  $title	
  );	
  ?-­‐-­‐></h4>
<pre>
esc_url() should be used on all URLs, including those in the ‘src’ and ‘href’
attributes of an HTML element.
<img	
  alt=""	
  src="<?php	
  echo	
  esc_url(	
  $great_user_picture_url	
  );	
  ?>"	
  />
WPDAY BOLOGNA - SEPTEMBER, 13 2013
ESCAPING: SECURING OUTPUT
esc_js() is intended for inline JavaScript.
var	
  value	
  =	
  '<?php	
  echo	
  esc_js(	
  $value	
  );	
  ?>';
esc_attr() can be used on everything else that’s printed into an HTML
element’s attribute.
<ul	
  class="<?php	
  echo	
  esc_attr(	
  $stored_class	
  );	
  ?>">
It’s important to note that most WordPress functions properly prepare the
data for output, and you don’t need to escape again.
<h4><?php	
  the_title();	
  ?></h4>
WPDAY BOLOGNA - SEPTEMBER, 13 2013
Danilo Ercoli
Automattic Inc.
http://daniloercoli.com
RELATORE
Danilo ha più di 10 anni di esperienza nello sviluppo di soluzioni software per il web e per il mobile.
Ha lavorato con i più disparati linguaggi di programmazione, dall’assembler a SmallTalk, dal C all’
Object-C passando per Lisp, Java e PHP. Sviluppatore certificato PHP e Java2 SE. Molto tempo fa
ha anche scritto un compilatore per il linguaggio Tiger. Attualmente lavora in WordPress.com
passando gran parte del tempo sviluppando le soluzioni mobili offerte da WordPress e sviluppando
componenti server a supporto del mobile. Lead Developer di WordPress for BlackBerry and
PlayBook.
BIO
WPDAY BOLOGNA - SEPTEMBER, 13 2013

Contenu connexe

Tendances

Take Command of WordPress With WP-CLI
Take Command of WordPress With WP-CLITake Command of WordPress With WP-CLI
Take Command of WordPress With WP-CLIDiana Thompson
 
10 things every developer should know about their database to run word press ...
10 things every developer should know about their database to run word press ...10 things every developer should know about their database to run word press ...
10 things every developer should know about their database to run word press ...Otto Kekäläinen
 
Creating a full stack web app with python, npm, webpack and react
Creating a full stack web app with python, npm, webpack and reactCreating a full stack web app with python, npm, webpack and react
Creating a full stack web app with python, npm, webpack and reactAngela Kristine Juvet Branaes
 
Take Command of WordPress With WP-CLI at WordCamp Long Beach
Take Command of WordPress With WP-CLI at WordCamp Long BeachTake Command of WordPress With WP-CLI at WordCamp Long Beach
Take Command of WordPress With WP-CLI at WordCamp Long BeachDiana Thompson
 
PHP SA 2014 - Releasing Your Open Source Project
PHP SA 2014 - Releasing Your Open Source ProjectPHP SA 2014 - Releasing Your Open Source Project
PHP SA 2014 - Releasing Your Open Source Projectxsist10
 
Anthony Somerset - Site Speed = Success!
Anthony Somerset - Site Speed = Success!Anthony Somerset - Site Speed = Success!
Anthony Somerset - Site Speed = Success!WordCamp Cape Town
 
Improving WordPress performance (xdebug and profiling)
Improving WordPress performance (xdebug and profiling)Improving WordPress performance (xdebug and profiling)
Improving WordPress performance (xdebug and profiling)Otto Kekäläinen
 
Here Be Dragons - Debugging WordPress
Here Be Dragons - Debugging WordPressHere Be Dragons - Debugging WordPress
Here Be Dragons - Debugging WordPressRami Sayar
 
WordCamp Finland 2015 - WordPress Security
WordCamp Finland 2015 - WordPress SecurityWordCamp Finland 2015 - WordPress Security
WordCamp Finland 2015 - WordPress SecurityTiia Rantanen
 
Take Command of WordPress With WP-CLI
Take Command of WordPress With WP-CLITake Command of WordPress With WP-CLI
Take Command of WordPress With WP-CLIDiana Thompson
 
Node JS Express : Steps to Create Restful Web App
Node JS Express : Steps to Create Restful Web AppNode JS Express : Steps to Create Restful Web App
Node JS Express : Steps to Create Restful Web AppEdureka!
 
Building Realtime Apps with Ember.js and WebSockets
Building Realtime Apps with Ember.js and WebSocketsBuilding Realtime Apps with Ember.js and WebSockets
Building Realtime Apps with Ember.js and WebSocketsBen Limmer
 
Running and Scaling Magento on AWS
Running and Scaling Magento on AWSRunning and Scaling Magento on AWS
Running and Scaling Magento on AWSAOE
 
Automatic testing and quality assurance for WordPress plugins and themes
Automatic testing and quality assurance for WordPress plugins and themesAutomatic testing and quality assurance for WordPress plugins and themes
Automatic testing and quality assurance for WordPress plugins and themesOtto Kekäläinen
 
Creating Your First WordPress Plugin
Creating Your First WordPress PluginCreating Your First WordPress Plugin
Creating Your First WordPress PluginBrad Williams
 
Front end performance optimization
Front end performance optimizationFront end performance optimization
Front end performance optimizationStevie T
 
Making the HTML5 Video element interactive
Making the HTML5 Video element interactiveMaking the HTML5 Video element interactive
Making the HTML5 Video element interactiveCharles Hudson
 
D installation manual
D installation manualD installation manual
D installation manualFaheem Akbar
 

Tendances (20)

Take Command of WordPress With WP-CLI
Take Command of WordPress With WP-CLITake Command of WordPress With WP-CLI
Take Command of WordPress With WP-CLI
 
10 things every developer should know about their database to run word press ...
10 things every developer should know about their database to run word press ...10 things every developer should know about their database to run word press ...
10 things every developer should know about their database to run word press ...
 
Creating a full stack web app with python, npm, webpack and react
Creating a full stack web app with python, npm, webpack and reactCreating a full stack web app with python, npm, webpack and react
Creating a full stack web app with python, npm, webpack and react
 
Take Command of WordPress With WP-CLI at WordCamp Long Beach
Take Command of WordPress With WP-CLI at WordCamp Long BeachTake Command of WordPress With WP-CLI at WordCamp Long Beach
Take Command of WordPress With WP-CLI at WordCamp Long Beach
 
PHP SA 2014 - Releasing Your Open Source Project
PHP SA 2014 - Releasing Your Open Source ProjectPHP SA 2014 - Releasing Your Open Source Project
PHP SA 2014 - Releasing Your Open Source Project
 
Anthony Somerset - Site Speed = Success!
Anthony Somerset - Site Speed = Success!Anthony Somerset - Site Speed = Success!
Anthony Somerset - Site Speed = Success!
 
Improving WordPress performance (xdebug and profiling)
Improving WordPress performance (xdebug and profiling)Improving WordPress performance (xdebug and profiling)
Improving WordPress performance (xdebug and profiling)
 
Scaling Django
Scaling DjangoScaling Django
Scaling Django
 
Here Be Dragons - Debugging WordPress
Here Be Dragons - Debugging WordPressHere Be Dragons - Debugging WordPress
Here Be Dragons - Debugging WordPress
 
WordCamp Finland 2015 - WordPress Security
WordCamp Finland 2015 - WordPress SecurityWordCamp Finland 2015 - WordPress Security
WordCamp Finland 2015 - WordPress Security
 
Take Command of WordPress With WP-CLI
Take Command of WordPress With WP-CLITake Command of WordPress With WP-CLI
Take Command of WordPress With WP-CLI
 
Node JS Express : Steps to Create Restful Web App
Node JS Express : Steps to Create Restful Web AppNode JS Express : Steps to Create Restful Web App
Node JS Express : Steps to Create Restful Web App
 
Django in the Real World
Django in the Real WorldDjango in the Real World
Django in the Real World
 
Building Realtime Apps with Ember.js and WebSockets
Building Realtime Apps with Ember.js and WebSocketsBuilding Realtime Apps with Ember.js and WebSockets
Building Realtime Apps with Ember.js and WebSockets
 
Running and Scaling Magento on AWS
Running and Scaling Magento on AWSRunning and Scaling Magento on AWS
Running and Scaling Magento on AWS
 
Automatic testing and quality assurance for WordPress plugins and themes
Automatic testing and quality assurance for WordPress plugins and themesAutomatic testing and quality assurance for WordPress plugins and themes
Automatic testing and quality assurance for WordPress plugins and themes
 
Creating Your First WordPress Plugin
Creating Your First WordPress PluginCreating Your First WordPress Plugin
Creating Your First WordPress Plugin
 
Front end performance optimization
Front end performance optimizationFront end performance optimization
Front end performance optimization
 
Making the HTML5 Video element interactive
Making the HTML5 Video element interactiveMaking the HTML5 Video element interactive
Making the HTML5 Video element interactive
 
D installation manual
D installation manualD installation manual
D installation manual
 

Similaire à WPDay Bologna 2013

WordPress Development Tools and Best Practices
WordPress Development Tools and Best PracticesWordPress Development Tools and Best Practices
WordPress Development Tools and Best PracticesDanilo Ercoli
 
How to? Drupal developer toolkit. Dennis Povshedny.
How to? Drupal developer toolkit. Dennis Povshedny.How to? Drupal developer toolkit. Dennis Povshedny.
How to? Drupal developer toolkit. Dennis Povshedny.DrupalCampDN
 
Mastering WordPress Vol.1
Mastering WordPress Vol.1Mastering WordPress Vol.1
Mastering WordPress Vol.1Wataru OKAMOTO
 
Vagrant WordCamp Hamilton
Vagrant  WordCamp HamiltonVagrant  WordCamp Hamilton
Vagrant WordCamp HamiltonPaul Bearne
 
5 年後還是新手 - WordPress Plugin 開發大冒險 - GOTY
5 年後還是新手 - WordPress Plugin 開發大冒險 - GOTY5 年後還是新手 - WordPress Plugin 開發大冒險 - GOTY
5 年後還是新手 - WordPress Plugin 開發大冒險 - GOTYWilliam Chong
 
Profiling PHP with Xdebug / Webgrind
Profiling PHP with Xdebug / WebgrindProfiling PHP with Xdebug / Webgrind
Profiling PHP with Xdebug / WebgrindSam Keen
 
WordPress Plugin Development- Rich Media Institute Workshop
WordPress Plugin Development- Rich Media Institute WorkshopWordPress Plugin Development- Rich Media Institute Workshop
WordPress Plugin Development- Rich Media Institute WorkshopBrendan Sera-Shriar
 
WordCamp Belfast DevOps for Beginners
WordCamp Belfast DevOps for BeginnersWordCamp Belfast DevOps for Beginners
WordCamp Belfast DevOps for BeginnersStewart Ritchie
 
Wordpress development: A Modern Approach
Wordpress development:  A Modern ApproachWordpress development:  A Modern Approach
Wordpress development: A Modern ApproachAlessandro Fiore
 
WordCamp SF 2011: Debugging in WordPress
WordCamp SF 2011: Debugging in WordPressWordCamp SF 2011: Debugging in WordPress
WordCamp SF 2011: Debugging in WordPressandrewnacin
 
Making the Most of Plug-ins - WordCamp Toronto 2008
Making the Most of Plug-ins - WordCamp Toronto 2008Making the Most of Plug-ins - WordCamp Toronto 2008
Making the Most of Plug-ins - WordCamp Toronto 2008Brendan Sera-Shriar
 
Hardening WordPress - SAScon Manchester 2013 (WordPress Security)
Hardening WordPress - SAScon Manchester 2013 (WordPress Security)Hardening WordPress - SAScon Manchester 2013 (WordPress Security)
Hardening WordPress - SAScon Manchester 2013 (WordPress Security)Bastian Grimm
 
Rapidly prototyping web applications using BackPress
Rapidly prototyping web applications using BackPressRapidly prototyping web applications using BackPress
Rapidly prototyping web applications using BackPressNathaniel Taintor
 
PyCon AU 2010 - Getting Started With Apache/mod_wsgi.
PyCon AU 2010 - Getting Started With Apache/mod_wsgi.PyCon AU 2010 - Getting Started With Apache/mod_wsgi.
PyCon AU 2010 - Getting Started With Apache/mod_wsgi.Graham Dumpleton
 
WP-CLI Workshop at WordPress Meetup Cluj-Napoca
WP-CLI Workshop at WordPress Meetup Cluj-NapocaWP-CLI Workshop at WordPress Meetup Cluj-Napoca
WP-CLI Workshop at WordPress Meetup Cluj-Napoca4nd4p0p
 
Security, more important than ever!
Security, more important than ever!Security, more important than ever!
Security, more important than ever!Marko Heijnen
 
It's a Mod World - A Practical Guide to Rocking Modernizr
It's a Mod World - A Practical Guide to Rocking ModernizrIt's a Mod World - A Practical Guide to Rocking Modernizr
It's a Mod World - A Practical Guide to Rocking ModernizrMichael Enslow
 
WordPress Plugin Development 201
WordPress Plugin Development 201WordPress Plugin Development 201
WordPress Plugin Development 201ylefebvre
 
Exploring pwa for shopware
Exploring pwa for shopwareExploring pwa for shopware
Exploring pwa for shopwareSander Mangel
 

Similaire à WPDay Bologna 2013 (20)

WordPress Development Tools and Best Practices
WordPress Development Tools and Best PracticesWordPress Development Tools and Best Practices
WordPress Development Tools and Best Practices
 
How to? Drupal developer toolkit. Dennis Povshedny.
How to? Drupal developer toolkit. Dennis Povshedny.How to? Drupal developer toolkit. Dennis Povshedny.
How to? Drupal developer toolkit. Dennis Povshedny.
 
Mastering WordPress Vol.1
Mastering WordPress Vol.1Mastering WordPress Vol.1
Mastering WordPress Vol.1
 
Vagrant WordCamp Hamilton
Vagrant  WordCamp HamiltonVagrant  WordCamp Hamilton
Vagrant WordCamp Hamilton
 
5 年後還是新手 - WordPress Plugin 開發大冒險 - GOTY
5 年後還是新手 - WordPress Plugin 開發大冒險 - GOTY5 年後還是新手 - WordPress Plugin 開發大冒險 - GOTY
5 年後還是新手 - WordPress Plugin 開發大冒險 - GOTY
 
Profiling PHP with Xdebug / Webgrind
Profiling PHP with Xdebug / WebgrindProfiling PHP with Xdebug / Webgrind
Profiling PHP with Xdebug / Webgrind
 
WordPress Plugin Development- Rich Media Institute Workshop
WordPress Plugin Development- Rich Media Institute WorkshopWordPress Plugin Development- Rich Media Institute Workshop
WordPress Plugin Development- Rich Media Institute Workshop
 
Drupal development
Drupal development Drupal development
Drupal development
 
WordCamp Belfast DevOps for Beginners
WordCamp Belfast DevOps for BeginnersWordCamp Belfast DevOps for Beginners
WordCamp Belfast DevOps for Beginners
 
Wordpress development: A Modern Approach
Wordpress development:  A Modern ApproachWordpress development:  A Modern Approach
Wordpress development: A Modern Approach
 
WordCamp SF 2011: Debugging in WordPress
WordCamp SF 2011: Debugging in WordPressWordCamp SF 2011: Debugging in WordPress
WordCamp SF 2011: Debugging in WordPress
 
Making the Most of Plug-ins - WordCamp Toronto 2008
Making the Most of Plug-ins - WordCamp Toronto 2008Making the Most of Plug-ins - WordCamp Toronto 2008
Making the Most of Plug-ins - WordCamp Toronto 2008
 
Hardening WordPress - SAScon Manchester 2013 (WordPress Security)
Hardening WordPress - SAScon Manchester 2013 (WordPress Security)Hardening WordPress - SAScon Manchester 2013 (WordPress Security)
Hardening WordPress - SAScon Manchester 2013 (WordPress Security)
 
Rapidly prototyping web applications using BackPress
Rapidly prototyping web applications using BackPressRapidly prototyping web applications using BackPress
Rapidly prototyping web applications using BackPress
 
PyCon AU 2010 - Getting Started With Apache/mod_wsgi.
PyCon AU 2010 - Getting Started With Apache/mod_wsgi.PyCon AU 2010 - Getting Started With Apache/mod_wsgi.
PyCon AU 2010 - Getting Started With Apache/mod_wsgi.
 
WP-CLI Workshop at WordPress Meetup Cluj-Napoca
WP-CLI Workshop at WordPress Meetup Cluj-NapocaWP-CLI Workshop at WordPress Meetup Cluj-Napoca
WP-CLI Workshop at WordPress Meetup Cluj-Napoca
 
Security, more important than ever!
Security, more important than ever!Security, more important than ever!
Security, more important than ever!
 
It's a Mod World - A Practical Guide to Rocking Modernizr
It's a Mod World - A Practical Guide to Rocking ModernizrIt's a Mod World - A Practical Guide to Rocking Modernizr
It's a Mod World - A Practical Guide to Rocking Modernizr
 
WordPress Plugin Development 201
WordPress Plugin Development 201WordPress Plugin Development 201
WordPress Plugin Development 201
 
Exploring pwa for shopware
Exploring pwa for shopwareExploring pwa for shopware
Exploring pwa for shopware
 

Dernier

Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024The Digital Insurer
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Principled Technologies
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 

Dernier (20)

Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 

WPDay Bologna 2013

  • 1. How to become a better WordPress Developer 1 WPDAY - BOLOGNA - SEPTEMBER, 13 2013 DANILO ERCOLI
  • 2. AGENDA WPDAY BOLOGNA - SEPTEMBER, 13 2013 • Development Tools • The WordPress Codex • Coding Standards • Data Validation • wpshell • Caching • Debugging
  • 4. DEVELOPMENT TOOLS • A good IDE can help you program faster and better: Sublime Text 2, PHP Storm, Eclipse for PHP, Netbeans for PHP, Coda •Code completion, easy WordPress function reference, project management, database editing, file comparison, FTP, debugging facilities •Codex and PHP Manual always loaded in the browser •Keep a copy of WordPress core in your IDE •Use wpshell for fast testing. Use command line interface (wp-cli) •Install XDebug on your local/remote installation (live debugging) WPDAY BOLOGNA - SEPTEMBER, 13 2013
  • 5. THE WORDPRESS CODEX WPDAY BOLOGNA - SEPTEMBER, 13 2013
  • 6. CODEX •The WordPress codex, and PHP Manual always under your hands. • codex: The online manual for WordPress Developers http://codex.wordpress.org •The Codex is a wiki, meaning anyone can edit it. It grows and thrives off of individual contributions from people like you •The best starting place for learning about how to develop plugins http://codex.wordpress.org/Writing_a_Plugin •Working with Themes https://codex.wordpress.org/Theme_Development •WordPress Coding Standards http://codex.wordpress.org/WordPress_Coding_Standards General information about coding standards for WordPress development WPDAY BOLOGNA - SEPTEMBER, 13 2013
  • 7. CODEX: CODINGS STANDARDS •Single quotes unless you need to evaluate a variable <?php echo 'a great string'; ?> vs <?php $dog_name = 'Winston'; echo "my dog's name is: $dog_name"; ?> •Naming is important $myGreatVariable = 2; //not so much $my_great_variable = my_function(); //Correct WPDAY BOLOGNA - SEPTEMBER, 13 2013
  • 8. CODEX: CODINGS STANDARDS •Yoda conditions if ( $city == 'Montreal' ) vs. if ( 'Montreal' == $city ) •Don’t get too clever isset( $var ) || $var = some_function(); Easier to read: if ( ! isset( $var ) ) $var = some_function(); WPDAY BOLOGNA - SEPTEMBER, 13 2013
  • 9. WPSHELL WPDAY BOLOGNA - SEPTEMBER, 13 2013
  • 10. WPSHELL • wpshell is a command line shell suitable for any php project, includes code indexing, searching, and displaying built-in • It gives you a command shell that accepts native PHP code as well as all the functionality your regular WordPress install would give you • http://code.trac.wordpress.org/ - http://hitchhackerguide.com/2011/11/13/ wpshell-a-shell-for-wordpress/ • This is intended for advanced developers. If you don’t know what you’re doing you can easily mess up your WordPress install. You can delete posts/ users/anything in few commands • I would not run this on production, but only in a local development environment. We will run it in production on WordPress.com (but rollback is easy there) • Example: switch_to_blog( 11719333 ); $lastposts = get_posts( 'numberposts=1' ); var_dump( $lastposts ); WPDAY BOLOGNA - SEPTEMBER, 13 2013
  • 11. DEBUGGING WPDAY BOLOGNA - SEPTEMBER, 13 2013
  • 12. DEBUGGING TECHNIQUES • echo The simplest approach, useful for seeing what a value is during run-time. This just outputs the value of a variable to a page you’re working on. • var_dump() / print_r() / var_export() These functions displays structured information of a variable. • console.log() / alert() If you’re writing Javascript, then you’ll probably be using one of these approaches. Alert will pop up a blocking dialog that you need to confirm to close (be careful about doing this in a loop!) while console.log() will write to your browser’s developer’s console (accessible via Web Inspector, Firebug, etc). • debug_backtrace The debug_backtrace() function generates a backtrace. WPDAY BOLOGNA - SEPTEMBER, 13 2013
  • 13. DEBUGGING TECHNIQUES • PHP “Magic Constants” Use PHP macros in combination with your various output techniques, like so: sprintf(  "%s:  %s",  __FILE__,  __LINE__  ) Spamming this down a file/function will help you figure out the path of execution, and also the last place your script was before “stopping” It can generate a lot of output but it’s pretty useful at times • error_log() Instead of outputting a value directly to a page, using this to output it to your sandbox’s (or production) php error log file. error_log( print_r( $results, true ) ); It’s often handy to have a Terminal window open with the following command running, which will show you the most recent entries in the log: tail  -­‐f  /tmp/php-­‐errors WPDAY BOLOGNA - SEPTEMBER, 13 2013
  • 14. DEBUGGING TECHNIQUES • My favorite logging combo error_log( "Request headers : nn".var_export( my_get_request_headers(), true ) ); error_log( "backtrace: n" . print_r( debug_backtrace( DEBUG_BACKTRACE_PROVIDE_OBJECT, 2 ), 1 ) ); Request headers : array ( 'x-forwarded-for' => '151.28.191.79', 'x-ip-trail' => '151.28.191.79', 'x-forwarded-port' => '443', 'x-forwarded-proto' => 'https', 'host' => 'public-api.wordpress.com', 'connection' => 'close', 'authorization' => 'Bearer tra-lallero-trallalà-XXXX', 'accept' => '/', 'accept-encoding' => 'gzip, deflate', 'accept-language' => 'en;q=1, fr;q=0.9, de;q=0.8, ja;q=0.7, nl;q=0.6, it;q=0.5', 'content-type' => 'application/x-www-form-urlencoded; charset=utf-8', 'cookie' => 'wordpress_test_cookie=WP+Cookie+check', 'content-length' => '188', 'user-agent' => 'wp-iphone/3.7.1 (iPhone OS 6.1, iPhone Simulator) Mobile', ) WPDAY BOLOGNA - SEPTEMBER, 13 2013
  • 15. DEBUGGING TECHNIQUES debug_backtrace: Array ( [0] => Array ( [file] => /home/wpcom/public_html/wp-content/mu-plugins/push-notifications.php [line] => 244 [function] => xmmp_log [class] => Mobile_Push_Notifications [object] => Mobile_Push_Notifications Object ( [log_recipients:Mobile_Push_Notifications:private] => Array ( [0] => daniloercoli@im.wordpress.com ) [log_target_users:Mobile_Push_Notifications:private] => Array ( [0] => eritreocazzulati [1] => 7272jean ) ) [type] => -> [args] => Array WPDAY BOLOGNA - SEPTEMBER, 13 2013
  • 16. DEBUGGING TECHNIQUES • Email!! Email isn’t dead! You can send debugging information directly to an email account using something like this: mail(  'you@gmail.com',  'Really  Important  Debugging  Information',  print_r(  $important_data,  true  ),  'From:   you@automattic.com'  ); Note that I like to use my direct @gmail.com address to get the fastest possible delivery, and setting a From address can help avoid getting these things sent to your spam folder. •XDebug If you’d like to connect to your ( remote | local ) server from your local machine and use xdebug to get very detailed debug info, breakpoints, etc. WPDAY BOLOGNA - SEPTEMBER, 13 2013
  • 17. DEBUG PLUGINS • Debug Bar http://wordpress.org/extend/plugins/debug-bar/ Adds a debug menu to the admin bar that shows query, cache, and other helpful debugging information. • Debug-Bar-Extender http://wordpress.org/extend/plugins/debug-bar-extender/ Extends the debug-bar plugin with additional tabs to measure runtimes between checkpoints and lookup variable content. (Do not use in a production site). • Debug Bar Console http://wordpress.org/extend/plugins/debug-bar-console/ Adds a PHP/MySQL console to the debug bar. Requires the debug bar plugin. WPDAY BOLOGNA - SEPTEMBER, 13 2013
  • 18. CACHING WPDAY BOLOGNA - SEPTEMBER, 13 2013
  • 19. DIFFERENT TYPES OF CACHING Full page caching •WP Super Cache •Batcache •W3 Total Cache Object level caching with native caching APIs •W3 Total Cache •WP File Cache •APC •Memcached Object Cache WPDAY BOLOGNA - SEPTEMBER, 13 2013
  • 20. FULL PAGE CACHE: BATCACHE What is Batcache? Batcache is a plugin to store and serve cached versions of rendered pages. • Batcache uses memcached as its storage and is aimed at preventing a flood of traffic from breaking your site. It does this by serving old pages to new users. • This reduces the demand on the web server CPU and the database. It also means some people may see a page that is up to 5 minutes old. • Development testing showed a 40x reduction in page generation times: pages generated in 200ms were served from the cache in 5ms. • Traffic simulations with Siege demonstrate that WordPress can handle up to twenty times more traffic with Batcache installed. WPDAY BOLOGNA - SEPTEMBER, 13 2013
  • 21. PAGE CACHE: BATCACHE Who receives a cached pageview? • By default, all new users receive a cached pageview. • New users are defined as anybody who hasn’t interacted with your domain — once they’ve left a comment or logged in, their cookies will ensure they get fresh pages. • Note that URLs with query strings are automatically exempt from Batcache. $batcache['max_age'] = 300; // Expire batcache items aged this many seconds (zero to disable it) $batcache['times'] = 4; // Only batcache a page after it is accessed this many times. WPDAY BOLOGNA - SEPTEMBER, 13 2013
  • 22. PAGE CACHE: BATCACHE Because Batcache caches fully rendered pages, per-user interactions on the server-side can be problematic. This means usage of objects/functions like $_COOKIE, setcookie, $_SERVER['HTTP_USER_AGENT'], and anything that’s unique to an individual user cannot be relied on as the values may be cached and cross- pollution can occur. In most cases, any user-level interactions should be moved to client-side using JavaScript. In some cases, we can help you set up Batcache variants if you’re limiting your interactions to a small set of distinct groups. (e.g. serve different content for users depending on whether the cookie “customer-type” is set, or equals “paid” or “pending”). Please get in touch if this something you’re interested in setting up. WPDAY BOLOGNA - SEPTEMBER, 13 2013
  • 23. PAGE CACHE: BATCACHE if ( Jetpack_User_Agent_Info::is_blackbeberry() ) { ! $batcache['unique']['mobile'] = 'blackberry'; } elseif ( Jetpack_User_Agent_Info::is_WindowsPhone7() ) { ! ! $batcache['unique']['mobile'] = 'windows-phone7';! } elseif ( Jetpack_User_Agent_Info::is_S60_OSSBrowser() ) { ! $batcache['unique']['mobile'] = 'dumb'; } elseif ( in_array( jetpack_is_mobile( 'smart', true ), array( 'iphone' ) ) ) { ! $batcache['unique']['mobile'] = 'iphone'; } elseif ( jetpack_is_mobile( 'dumb' ) ) { ! $batcache['unique']['mobile'] = 'dumb'; } Batcache Variants WPDAY BOLOGNA - SEPTEMBER, 13 2013
  • 24. WORDPRESS NATIVE CACHING APIS Transients • Persistent out of the box • Stored in wp_options: _transient_{key} • WordPress uses for certain internal functions • set_, get_, and delete_transient() Object Cache •Not persistent without a plugin, such as W3 Total Cache or Memcached Object Cache •Storage depends on server's and plugin's capabilities •Used extensively within WordPress Cache objects can be grouped wp_cache_add(), _set, _get, _delete WPDAY BOLOGNA - SEPTEMBER, 13 2013
  • 25. DATA VALIDATION WPDAY BOLOGNA - SEPTEMBER, 13 2013
  • 26. PROPERLY VALIDATE, SANITIZE, AND ESCAPE YOUR DATA Your code works, but is it safe? Rule No. 1: Trust Nobody The idea is that you should not assume that any data entered by the user is safe. Nor should you assume that the data you’ve retrieved from the database is safe – even if you had made it ‘safe’ prior to inserting it there. •In fact, whether data can be considered ‘safe’ makes no sense without context. •Sometimes the same data may be used in multiple contexts on the same page. Rule No. 2: Validate on Input, Escape on Output To escape is to take the data you may already have and help secure it prior to rendering it for the end user WPDAY BOLOGNA - SEPTEMBER, 13 2013
  • 27. DATA VALIDATION A must-read for WordPress contributors. Describes the functions used by WordPress to validate and sanitize data. Developers should be familiar with these functions and ideas http://codex.wordpress.org/Data_Validation WPDAY BOLOGNA - SEPTEMBER, 13 2013
  • 28. VALIDATING: CHECKING USER INPUT To validate is to ensure the data you’ve requested of the user matches what they’ve submitted. There are several core methods you can use for input validation; usage obviously depends on the type of fields you’d like to validate. http://codex.wordpress.org/Data_Validation#Input_Validation Let’s take a look at an example. <input id="my-zipcode" type="text" maxlength="5" name="my-zipcode" /> We’ve limited the input to five characters of input, but there’s no limitation on what they can input. They could enter “11221″ or “eval(“. Or even more characters if they change the HTML. WPDAY BOLOGNA - SEPTEMBER, 13 2013
  • 29. VALIDATING: CHECKING USER INPUT 1  $safe_zipcode  =  intval(  $_POST['my-­‐zipcode']  ); 2  if  (  !  $safe_zipcode  ) 3      $safe_zipcode  =  ''; 4  update_post_meta(  $post-­‐>ID,  'my_zipcode',  $safe_zipcode  ); The intval() function casts user input as an integer, and defaults to zero if the input was a non-numeric value. We then check to see if the value ended up as zero. If it did, we’ll save an empty value to the database. Otherwise, we’ll save the properly validated zipcode. WPDAY BOLOGNA - SEPTEMBER, 13 2013
  • 30. SANITIZING: CLEANING USER INPUT Whereas validation is concerned with making sure data is valid – data sanitization is about making it safe. Even ‘valid’ data might be unsafe in certain contexts. You cannot ask “How do I make this data safe?”. Instead you should ask, “How do I make this data safe for using it in X”. <input  id="title"  type="text"  name="title"  /> Tex$title  =  sanitize_text_field(  $_POST['title']  ); 2 update_post_meta(  $post-­‐>ID,  'title',  $title  ); t We could sanitize the data with the sanitize_text_field() function: WPDAY BOLOGNA - SEPTEMBER, 13 2013
  • 31. SANITIZING: CLEANING USER INPUT Behinds the scenes, the function does the following: • Checks for invalid UTF-8 • Converts single < characters to entity • Strips all tags • Remove line breaks, tabs and extra white space • Strip octets The sanitize_*() class of helper functions are super nice for us, as they ensure we’re ending up with safe data and require minimal effort on our part. WPDAY BOLOGNA - SEPTEMBER, 13 2013
  • 32. ESCAPING: SECURING OUTPUT For security on the other end of the spectrum, we have escaping. To escape is to take the data you may already have and help secure it prior to rendering it for the end user. WordPress thankfully has a few helper functions we can use for most of what we’ll commonly need to do: esc_html() we should use anytime our HTML element encloses a section of data we’re outputting. </pre> <h4><!-­‐-­‐?php  echo  esc_html(  $title  );  ?-­‐-­‐></h4> <pre> esc_url() should be used on all URLs, including those in the ‘src’ and ‘href’ attributes of an HTML element. <img  alt=""  src="<?php  echo  esc_url(  $great_user_picture_url  );  ?>"  /> WPDAY BOLOGNA - SEPTEMBER, 13 2013
  • 33. ESCAPING: SECURING OUTPUT esc_js() is intended for inline JavaScript. var  value  =  '<?php  echo  esc_js(  $value  );  ?>'; esc_attr() can be used on everything else that’s printed into an HTML element’s attribute. <ul  class="<?php  echo  esc_attr(  $stored_class  );  ?>"> It’s important to note that most WordPress functions properly prepare the data for output, and you don’t need to escape again. <h4><?php  the_title();  ?></h4> WPDAY BOLOGNA - SEPTEMBER, 13 2013
  • 34. Danilo Ercoli Automattic Inc. http://daniloercoli.com RELATORE Danilo ha più di 10 anni di esperienza nello sviluppo di soluzioni software per il web e per il mobile. Ha lavorato con i più disparati linguaggi di programmazione, dall’assembler a SmallTalk, dal C all’ Object-C passando per Lisp, Java e PHP. Sviluppatore certificato PHP e Java2 SE. Molto tempo fa ha anche scritto un compilatore per il linguaggio Tiger. Attualmente lavora in WordPress.com passando gran parte del tempo sviluppando le soluzioni mobili offerte da WordPress e sviluppando componenti server a supporto del mobile. Lead Developer di WordPress for BlackBerry and PlayBook. BIO WPDAY BOLOGNA - SEPTEMBER, 13 2013