SlideShare a Scribd company logo
1 of 42
WordPress for developers
 Maurizio Pelizzone




May 14, Verona 2011
About me

   35 years old
   Birth in Turin (Italy)
   Co-Founder mavida.com
   WordPress addited



   http://maurizio.mavida.com
   http://www.linkedin.com/in/mauriziopelizzone
About this speech
     About WordPress
     WordPress features overview
     Custom type and Taxonomy
     Routing and rewrite rules
     Custom query and manipulation
     Cache tips
     Debugging tools
     Links and reference
About WordPress

“WordPress is a web software you can use to create a
beautiful website or blog” *
“WordPress is a state-of-the-art publishing platform with a
focus on aesthetics, web standards, and usability. ”

      25 million people have chosen WordPress
      54 % content management system market share
      More then 14,000 plugins (May 2011)
      More then 1.300 themes (May 2011)
      32 million WordPress 3 download (February 2011)
      More then 9 million WordPress 3.1 download (May 2011)
Releases timeline history
1.2   Mingus      22 May 2004
1.5   Strayhorn   17 February 2005
2.0   Duke        31 December 2005
2.1   Ella        22 January 2007
2.2   Getz        16 May 2007
2.3   Dexter      24 September 2007
2.5   Brecker     29 March 2008
2.6   Tyner       15 July 2008
2.7   Coltrane    11 December 2008
2.8   Baker       10 June 2009
2.9   Carmen      19 December 2009
3.0   Thelonious 17 July 2010
3.1   Django      23 February 2011
3.2               30 June 2011
Is WordPress better than
    Drupal or Joomla ?
No, it’s different!!!
now some boring slides.
               sorry…
WordPress users (my expience)
    Publisher:                       > 50%
    Designers:                       < 30%
    Developers:                      ~ 15%

                               designers                  developers




                                             publishers



sample of 143 blogs
statistics based on my personal contacts
What else?

     Strong backward compatibility
     Documentation (http://codex.wordpress.org/)
     Free themes and plugins direcory
     Super fast template manipulation
     Automattic
Main Features

     One click automatic update (core, plugins, themes)
     Core multisite implementation
     Custom post type
     Custom taxonomies
     XML-RPC interface
     Child themes

   Some other staff like: ombed, shortcode, widgets, image
      editing, automatic thumbnails, comments threading and hierarchic
      menu generator
WordPress Weeknesses
  1.   Globals variable
  2.   Not fully OO
  3.   EZSQL DB Class
  4.   Uneasy Unit Test
  5.   Need tuning and manteinance (very often)
About Custom Post Type

“Post type refers to the various structured data that is
maintained in the WordPress posts table and can represent
any type of content you want”

   Default native post type
      1. post
      2. page
      3. attachment
      4. revision
      5. nav-menu-item ( > wp 3.0)
//http://codex.wordpress.org/Function_Reference/register_post_type



add_action( 'init', 'add_post_type'   );

function add_post_type( ) {

   $args = array(        'label' => __('films'),
                         'public' => true,
                         'hierarchical' => false,
                          )

    register_post_type( 'film', $args );

   }
About Taxonomies

“Taxonomy is the practice and science of classification.” (Wikipedia)

 More simple content organization
     Books (Genre, Authors, Publisher, Edition)
     Films (Genre, Actors, Director, Year)

 Greater semantics
       http://blogname.com/film/matrix/
       http://blogname.com/genre/action/
       http://blogname.com/actors/keanu-reeves/
       http://blogname.com/director/andy-wachowsk/
//http://codex.wordpress.org/Function_Reference/register_taxonomy



add_action( 'init', 'add_taxonomies' );

function add_taxonomies( ) {

   $args = array(        'hierarchical' => true,
                         'public' => true,
                         'label' => 'Genre',
                          )

   register_taxonomy( 'genre', array('post', 'book', $args );

   }
About Routing and Rewrite

“WP_Rewrite is WordPress' class for managing the rewrite
rules that allow you to use Pretty Permalinks feature. It has
several methods that generate the rewrite rules from
values in the database.”
//http://codex.wordpress.org/Function_Reference/WP_Rewrite

add_action('generate_rewrite_rules', 'my_rewrite_rules');



function my_rewrite_rules( $wp_rewrite ) {

    $new_rules = array(

         'favorite-films' => 'index.php?post_type=films&tag=favorite',

         );

    $wp_rewrite->rules = $new_rules + $wp_rewrite->rules;



}
//http://codex.wordpress.org/Function_Reference/WP_Rewrite

add_action('generate_rewrite_rules', 'my_rewrite_rules');



function my_rewrite_rules( $wp_rewrite ) {

    $new_rules = array(

         'favorite-films/([^/]*)' => 'index.php?post_type=films&tag=favorite&genre='
                                           . $wp_rewrite->preg_index(1),

         'favorite-films' => 'index.php?post_type=films&tag=favorite',

         );

    $wp_rewrite->rules = $new_rules + $wp_rewrite->rules;



}
//http://codex.wordpress.org/Function_Reference/WP_Rewrite

add_action('generate_rewrite_rules', 'my_rewrite_rules ');
add_filter('query_vars','my_query_vars');
add_action('template_redirect', 'my_redirect' );

function my_rewrite_rules ( $wp_rewrite ) {
   $new_rules = array(
         'advanced-search' => 'index.php?custom_route=advanced-search',
         );

    $wp_rewrite->rules = $new_rules + $wp_rewrite->rules;
}

function my_query_vars($vars) {
   $vars[] = 'custom_route';
   return $vars;
}

function my_redirect() {
   if ( get_query_var('custom_route') != "" ) :
         $template = array( get_query_var('custom_route') . ".php" );
         array_push( $template, 'index.php' );
         locate_template( $template, true );
         die();
   endif;
}
//http://codex.wordpress.org/Function_Reference/WP_Rewrite

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteRule ^login /wp-login.php [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
//http://codex.wordpress.org/Function_Reference/WP_Rewrite

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteRule ^login /wp-login.php [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
About Custom Query and wpdb

“WordPress provides a class of functions for all database
manipulations. The class is called wpdb and is loosely based
on the ezSQL class written and maintained by Justin
Vincent.”
//http://codex.wordpress.org/Function_Reference/wpdb_Class

function list_last_film( $limit ) {

    global $wpdb;

    $sql_source = "SELECT ID, post_title
                  FROM $wpdb->posts
                  WHERE post_type = 'films' and post_status = 'published'
                  ORDER BY post_date
                  LIMIT %d“;

    $sql = $wpdb->prepare($sql_source ,   $limit );

    $last_films = $wpdb->get_results( $sql );



    foreach ( $last_films as $film_item) {
         echo $film_item->post_title;
         }

}
//http://codex.wordpress.org/Function_Reference/Custom_Queries

add_filter( 'pre_get_posts', 'add_films_in_home' );



function add_films_in_home( $query ) {

    if ( is_home() && !$query->query_vars['suppress_filters'] ) {
         $query->set( 'post_type', array( 'post', 'films' ) );
         }

    return $query;

}
//http://codex.wordpress.org/Function_Reference/Custom_Queries

add_filter( 'posts_join', 'my_join');
add_filter( 'posts_fields', 'my_fields');

function my_join ($join) {
   global $wpdb;

   if( is_single() && get_query_var('post_type') == 'films' ) {
        $join .= " LEFT JOIN my_table ON " .
                          $wpdb->posts . ".ID = my_table.ID ";
        }

   return $join;
   }

function my_fields( $fields   ) {
   global $wpdb,$post;

   if( is_single() && get_query_var('post_type') == 'films' ) {
        $fields .= ", my_table.* ";
        }

   return $fields;
   }
Transient API

“WordPress Transients API offers a simple and
standardized way of storing cached data in the database
temporarily by giving it a custom name and a timeframe
after which it will expire and be deleted. ”
//http://codex.wordpress.org/Function_Reference/Transients_API

function list_last_film( $limit ) {
   global $wpdb;

    $last_films = get_transient( 'last_films_' . $limit );

    if ( $last_films === false ) {
        $sql_source = "SELECT ID, post_title
                  FROM $wpdb->posts
                  WHERE post_type = 'films' and post_status = 'published'
                  ORDER BY post_date
                  LIMIT %d“;

       $sql = $wpdb->prepare($sql_source , $limit );
       $last_films = $wpdb->get_results( $sql );

       set_transient( 'last_films_' . $limit , $last_films , 60*60*2 );
       }

    foreach ( $last_films as $film_item) {
         echo $film_item->post_title;
         }

}
APC Object cache

“APC Object Cache provides a persistent memory-based
backend for the WordPress object cache.
An object cache is a place for WordPress and WordPress
extensions to store the results of complex operations. ”

http://wordpress.org/extend/plugins/apc/

Installation:
1.   Verify that you have PHP 5.2+ and a compatible APC version installed.
2.   Copy object-cache.php to your WordPress content directory (wp-content).
3.   Done!
Cache template part

“Simple custom function to store manualy a template part
on filesystem”
function cache_template_part( $file , $args = null   ) {

        $defaults = array(
                 'always' => true,
                 'rewrite' => false,
                 'cachetime' => 60*60*2,
                 'cachepath' => 'wp-content/cache/',
                 );

        $args = wp_parse_args( $args, $defaults );
        extract( $args, EXTR_SKIP );

   $cachefile = $cachepath . str_replace( "/", "-", $file);
   $cachefile_created = ((@file_exists($cachefile)) ) ? @filemtime($cachefile) : 0;

   if ( !$rewrite
        && ( time() - $cachetime < $cachefile_created )
         && ( $always || !is_user_logged_in()) ) {

        echo   file_get_contents( $cachefile );

   } else {

        ....

        }
   }
ob_start();
include($file);

if ( $always || !is_user_logged_in() ) {
   $b = ob_get_clean();
   $b = preg_replace('/[ ]+/', ' ', $b);
   $b = str_replace( array("rn", "r", "n", "t" ), '', $b);

   if ( strlen($b) > 1 ) {
        $signature = "<!-- Cached " . $cachefile
                          . " - " . date('jS F Y H:i') . " -->";

        file_put_contents( $cachefile , $signature . $b);
        }

   echo $b;

   }

ob_end_flush();
<?php get_header(); ?>

          <div id="container">
                   <div id="content" role="main">

                  <?php
                  /* Run the loop to output the post.
                   * If you want to overload this in a child theme then include a
   file
                   * called loop-single.php and that will be used instead.
                   */
                  get_template_part( 'loop', 'single' );
                  ?>

                   </div><!-- #content -->
          </div><!-- #container -->

<?php get_sidebar(); ?>
<?php get_footer(); ?>
<?php cache_template_part('header.php'); ?>

          <div id="container">
                   <div id="content" role="main">

                  <?php
                  /* Run the loop to output the post.
                   * If you want to overload this in a child theme then include a
   file
                   * called loop-single.php and that will be used instead.
                   */
                  get_template_part( 'loop', 'single' );
                  ?>

                   </div><!-- #content -->
          </div><!-- #container -->

<?php cache_template_part('sidebar.php'); ?>
<?php cache_template_part('footer.php'); ?>
add_action( 'save_post', 'clear_cache_on_save');

function clear_cache_on_save( $post_id    ) {
   global $post;

   if ( $post->post_status == "publish") {

        $cachepath = 'wp-content/cache/';

        $cachefile =   array();
        $cachefile[]   = $cachepath . "header.php";
        $cachefile[]   = $cachepath . "sidebar.php";
        $cachefile[]   = $cachepath . "footer.php";

        foreach($cachefile as $file){
                 if( file_exists( $file ) ) {
                          unlink( $file );
                          }
                 }

        }
   }
Debugging tools
  Debug query
     http://wordpress.org/extend/plugins/debug-queries/

   Debug bar
      http://wordpress.org/extend/plugins/debug-bar/


 Add this line to your wp-config.php
  define( 'WP_DEBUG', true );
  define( 'SAVEQUERIES', true );
What’s coming in WordPress 3.2
  1. Requirements Changes:
      •   PHP version 5.2 or greater (old requirement 4.3 or greater)
      •   MySQL version 5.0.15 or greater (old requirement 4.1.2 or greater)
  2. Twenty Eleven Theme
  3. Speed Improvements




  For more info:
  http://codex.wordpress.org/Version_3.2
Plugins Toolbox
   Custom post type UI
       http://wordpress.org/extend/plugins/custom-post-type-ui/
   Simple Custom Post Type Archives
       http://wordpress.org/extend/plugins/simple-custom-post-type-archives/
   Query Multiple Taxonomies
       http://wordpress.org/extend/plugins/query-multiple-taxonomies/
   Super widgets
       http://wordpress.org/extend/plugins/super-widgets/
   Widget Logic
       http://wordpress.org/extend/plugins/widget-logic/
Links Reference
  Stats
  •   http://w3techs.com/technologies/overview/content_management/all
  •   http://trends.builtwith.com/blog/WordPress
  •   http://en.wordpress.com/stats/
  •   http://wordpress.org/download/counter/
Links to follow
     http://codex.wordpress.org/
     http://wpengineer.com/
     http://www.wprecipes.com/
     http://www.wpbeginner.com/
     http://wpshout.com/
Questions?




             ?
Thanks


         Pelizzone Maurizio
         maurizio@mavida.com
         http://www.mavida.com
         http://maurizio.mavida.com

More Related Content

What's hot

Render API - Pavel Makhrinsky
Render API - Pavel MakhrinskyRender API - Pavel Makhrinsky
Render API - Pavel MakhrinskyDrupalCampDN
 
Write Less Do More
Write Less Do MoreWrite Less Do More
Write Less Do MoreRemy Sharp
 
Introducing Assetic: Asset Management for PHP 5.3
Introducing Assetic: Asset Management for PHP 5.3Introducing Assetic: Asset Management for PHP 5.3
Introducing Assetic: Asset Management for PHP 5.3Kris Wallsmith
 
jQuery and_drupal
jQuery and_drupaljQuery and_drupal
jQuery and_drupalBlackCatWeb
 
Drupal Javascript for developers
Drupal Javascript for developersDrupal Javascript for developers
Drupal Javascript for developersDream Production AG
 
Propel sfugmd
Propel sfugmdPropel sfugmd
Propel sfugmdiKlaus
 
jQuery: Nuts, Bolts and Bling
jQuery: Nuts, Bolts and BlingjQuery: Nuts, Bolts and Bling
jQuery: Nuts, Bolts and BlingDoug Neiner
 
Drupal Development (Part 2)
Drupal Development (Part 2)Drupal Development (Part 2)
Drupal Development (Part 2)Jeff Eaton
 
The Query the Whole Query and Nothing but the Query
The Query the Whole Query and Nothing but the QueryThe Query the Whole Query and Nothing but the Query
The Query the Whole Query and Nothing but the QueryChris Olbekson
 
Introduction to jQuery
Introduction to jQueryIntroduction to jQuery
Introduction to jQuerymanugoel2003
 
A Rich Web Experience with jQuery, Ajax and .NET
A Rich Web Experience with jQuery, Ajax and .NETA Rich Web Experience with jQuery, Ajax and .NET
A Rich Web Experience with jQuery, Ajax and .NETJames Johnson
 
Drupal & javascript
Drupal & javascriptDrupal & javascript
Drupal & javascriptAlmog Baku
 
Assetic (Symfony Live Paris)
Assetic (Symfony Live Paris)Assetic (Symfony Live Paris)
Assetic (Symfony Live Paris)Kris Wallsmith
 
Windows Azure Storage & Sql Azure
Windows Azure Storage & Sql AzureWindows Azure Storage & Sql Azure
Windows Azure Storage & Sql AzureMaarten Balliauw
 
Building Large jQuery Applications
Building Large jQuery ApplicationsBuilding Large jQuery Applications
Building Large jQuery ApplicationsRebecca Murphey
 
Prototype & jQuery
Prototype & jQueryPrototype & jQuery
Prototype & jQueryRemy Sharp
 

What's hot (20)

Render API - Pavel Makhrinsky
Render API - Pavel MakhrinskyRender API - Pavel Makhrinsky
Render API - Pavel Makhrinsky
 
Write Less Do More
Write Less Do MoreWrite Less Do More
Write Less Do More
 
Introducing Assetic: Asset Management for PHP 5.3
Introducing Assetic: Asset Management for PHP 5.3Introducing Assetic: Asset Management for PHP 5.3
Introducing Assetic: Asset Management for PHP 5.3
 
jQuery and_drupal
jQuery and_drupaljQuery and_drupal
jQuery and_drupal
 
jQuery
jQueryjQuery
jQuery
 
Drupal Javascript for developers
Drupal Javascript for developersDrupal Javascript for developers
Drupal Javascript for developers
 
jQuery Essentials
jQuery EssentialsjQuery Essentials
jQuery Essentials
 
Propel sfugmd
Propel sfugmdPropel sfugmd
Propel sfugmd
 
jQuery: Nuts, Bolts and Bling
jQuery: Nuts, Bolts and BlingjQuery: Nuts, Bolts and Bling
jQuery: Nuts, Bolts and Bling
 
Drupal Development (Part 2)
Drupal Development (Part 2)Drupal Development (Part 2)
Drupal Development (Part 2)
 
The Query the Whole Query and Nothing but the Query
The Query the Whole Query and Nothing but the QueryThe Query the Whole Query and Nothing but the Query
The Query the Whole Query and Nothing but the Query
 
Introduction to jQuery
Introduction to jQueryIntroduction to jQuery
Introduction to jQuery
 
A Rich Web Experience with jQuery, Ajax and .NET
A Rich Web Experience with jQuery, Ajax and .NETA Rich Web Experience with jQuery, Ajax and .NET
A Rich Web Experience with jQuery, Ajax and .NET
 
Drupal & javascript
Drupal & javascriptDrupal & javascript
Drupal & javascript
 
Assetic (Symfony Live Paris)
Assetic (Symfony Live Paris)Assetic (Symfony Live Paris)
Assetic (Symfony Live Paris)
 
Windows Azure Storage & Sql Azure
Windows Azure Storage & Sql AzureWindows Azure Storage & Sql Azure
Windows Azure Storage & Sql Azure
 
Building Large jQuery Applications
Building Large jQuery ApplicationsBuilding Large jQuery Applications
Building Large jQuery Applications
 
jQuery Essentials
jQuery EssentialsjQuery Essentials
jQuery Essentials
 
Prototype & jQuery
Prototype & jQueryPrototype & jQuery
Prototype & jQuery
 
JQuery introduction
JQuery introductionJQuery introduction
JQuery introduction
 

Similar to WordPress for developers - phpday 2011

How Not to Build a WordPress Plugin
How Not to Build a WordPress PluginHow Not to Build a WordPress Plugin
How Not to Build a WordPress PluginWill Norris
 
WordPress Café: Using WordPress as a Framework
WordPress Café: Using WordPress as a FrameworkWordPress Café: Using WordPress as a Framework
WordPress Café: Using WordPress as a FrameworkExove
 
WordPress Plugins: ur doin it wrong
WordPress Plugins: ur doin it wrongWordPress Plugins: ur doin it wrong
WordPress Plugins: ur doin it wrongWill Norris
 
WordPress Developers Israel Meetup #1
WordPress Developers Israel Meetup #1WordPress Developers Israel Meetup #1
WordPress Developers Israel Meetup #1Yoav Farhi
 
Laying the proper foundation for plugin and theme development
Laying the proper foundation for plugin and theme developmentLaying the proper foundation for plugin and theme development
Laying the proper foundation for plugin and theme developmentTammy Hart
 
Using WordPress as your application stack
Using WordPress as your application stackUsing WordPress as your application stack
Using WordPress as your application stackPaul Bearne
 
Advanced symfony Techniques
Advanced symfony TechniquesAdvanced symfony Techniques
Advanced symfony TechniquesKris Wallsmith
 
The Way to Theme Enlightenment 2017
The Way to Theme Enlightenment 2017The Way to Theme Enlightenment 2017
The Way to Theme Enlightenment 2017Amanda Giles
 
Childthemes ottawa-word camp-1919
Childthemes ottawa-word camp-1919Childthemes ottawa-word camp-1919
Childthemes ottawa-word camp-1919Paul Bearne
 
The Way to Theme Enlightenment
The Way to Theme EnlightenmentThe Way to Theme Enlightenment
The Way to Theme EnlightenmentAmanda Giles
 
Как получить чёрный пояс по WordPress?
Как получить чёрный пояс по WordPress?Как получить чёрный пояс по WordPress?
Как получить чёрный пояс по WordPress?Yevhen Kotelnytskyi
 
Resource Routing in ExpressionEngine
Resource Routing in ExpressionEngineResource Routing in ExpressionEngine
Resource Routing in ExpressionEngineMichaelRog
 
Rails 3 overview
Rails 3 overviewRails 3 overview
Rails 3 overviewYehuda Katz
 
Unit testing after Zend Framework 1.8
Unit testing after Zend Framework 1.8Unit testing after Zend Framework 1.8
Unit testing after Zend Framework 1.8Michelangelo van Dam
 

Similar to WordPress for developers - phpday 2011 (20)

How Not to Build a WordPress Plugin
How Not to Build a WordPress PluginHow Not to Build a WordPress Plugin
How Not to Build a WordPress Plugin
 
WordPress Café: Using WordPress as a Framework
WordPress Café: Using WordPress as a FrameworkWordPress Café: Using WordPress as a Framework
WordPress Café: Using WordPress as a Framework
 
WordPress Plugins: ur doin it wrong
WordPress Plugins: ur doin it wrongWordPress Plugins: ur doin it wrong
WordPress Plugins: ur doin it wrong
 
Django at the Disco
Django at the DiscoDjango at the Disco
Django at the Disco
 
Django at the Disco
Django at the DiscoDjango at the Disco
Django at the Disco
 
Django at the Disco
Django at the DiscoDjango at the Disco
Django at the Disco
 
Django at the Disco
Django at the DiscoDjango at the Disco
Django at the Disco
 
WordPress Developers Israel Meetup #1
WordPress Developers Israel Meetup #1WordPress Developers Israel Meetup #1
WordPress Developers Israel Meetup #1
 
Laying the proper foundation for plugin and theme development
Laying the proper foundation for plugin and theme developmentLaying the proper foundation for plugin and theme development
Laying the proper foundation for plugin and theme development
 
Using WordPress as your application stack
Using WordPress as your application stackUsing WordPress as your application stack
Using WordPress as your application stack
 
Advanced symfony Techniques
Advanced symfony TechniquesAdvanced symfony Techniques
Advanced symfony Techniques
 
Django at the Disco
Django at the DiscoDjango at the Disco
Django at the Disco
 
The Way to Theme Enlightenment 2017
The Way to Theme Enlightenment 2017The Way to Theme Enlightenment 2017
The Way to Theme Enlightenment 2017
 
CMS content
CMS contentCMS content
CMS content
 
Childthemes ottawa-word camp-1919
Childthemes ottawa-word camp-1919Childthemes ottawa-word camp-1919
Childthemes ottawa-word camp-1919
 
The Way to Theme Enlightenment
The Way to Theme EnlightenmentThe Way to Theme Enlightenment
The Way to Theme Enlightenment
 
Как получить чёрный пояс по WordPress?
Как получить чёрный пояс по WordPress?Как получить чёрный пояс по WordPress?
Как получить чёрный пояс по WordPress?
 
Resource Routing in ExpressionEngine
Resource Routing in ExpressionEngineResource Routing in ExpressionEngine
Resource Routing in ExpressionEngine
 
Rails 3 overview
Rails 3 overviewRails 3 overview
Rails 3 overview
 
Unit testing after Zend Framework 1.8
Unit testing after Zend Framework 1.8Unit testing after Zend Framework 1.8
Unit testing after Zend Framework 1.8
 

More from Maurizio Pelizzone

WordPress and his «almost» native page builder
WordPress and his «almost» native page builderWordPress and his «almost» native page builder
WordPress and his «almost» native page builderMaurizio Pelizzone
 
WCEU 2016 - 10 tips to sleep better at night
WCEU 2016 - 10 tips to sleep better at nightWCEU 2016 - 10 tips to sleep better at night
WCEU 2016 - 10 tips to sleep better at nightMaurizio Pelizzone
 
Professional WordPress Workflow - WPDay 2015
Professional WordPress Workflow - WPDay 2015 Professional WordPress Workflow - WPDay 2015
Professional WordPress Workflow - WPDay 2015 Maurizio Pelizzone
 
WordPress Meetup Torino Giugno 2015
WordPress Meetup Torino Giugno 2015WordPress Meetup Torino Giugno 2015
WordPress Meetup Torino Giugno 2015Maurizio Pelizzone
 
Wordpress e la gestione di progetti complessi
Wordpress e la gestione di progetti complessiWordpress e la gestione di progetti complessi
Wordpress e la gestione di progetti complessiMaurizio Pelizzone
 
Use Symfony2 components inside WordPress
Use Symfony2 components inside WordPress Use Symfony2 components inside WordPress
Use Symfony2 components inside WordPress Maurizio Pelizzone
 
WordPress: Smart Ideas for Startup - SMW torino 2012
WordPress: Smart Ideas for Startup - SMW  torino 2012 WordPress: Smart Ideas for Startup - SMW  torino 2012
WordPress: Smart Ideas for Startup - SMW torino 2012 Maurizio Pelizzone
 
Security and Performance - Italian WordPress Conference
Security and Performance - Italian WordPress ConferenceSecurity and Performance - Italian WordPress Conference
Security and Performance - Italian WordPress ConferenceMaurizio Pelizzone
 
Wordpress: «l’abc per gli sviluppatori» - PHP.TO.START [2012]
 Wordpress: «l’abc per gli sviluppatori» - PHP.TO.START [2012] Wordpress: «l’abc per gli sviluppatori» - PHP.TO.START [2012]
Wordpress: «l’abc per gli sviluppatori» - PHP.TO.START [2012]Maurizio Pelizzone
 
Poliedric WordPress - Go!WebDesign
Poliedric WordPress - Go!WebDesignPoliedric WordPress - Go!WebDesign
Poliedric WordPress - Go!WebDesignMaurizio Pelizzone
 
Custom taxonomies / Custom post type - wordcamp milano 2010
Custom taxonomies / Custom post type - wordcamp milano 2010Custom taxonomies / Custom post type - wordcamp milano 2010
Custom taxonomies / Custom post type - wordcamp milano 2010Maurizio Pelizzone
 
Ottimizzare un sito web per i motori di ricerca
Ottimizzare un sito web per i motori di ricercaOttimizzare un sito web per i motori di ricerca
Ottimizzare un sito web per i motori di ricercaMaurizio Pelizzone
 
Come funzionano i template di Wordpress
Come funzionano i template di WordpressCome funzionano i template di Wordpress
Come funzionano i template di WordpressMaurizio Pelizzone
 

More from Maurizio Pelizzone (17)

WordPress and his «almost» native page builder
WordPress and his «almost» native page builderWordPress and his «almost» native page builder
WordPress and his «almost» native page builder
 
WCEU 2016 - 10 tips to sleep better at night
WCEU 2016 - 10 tips to sleep better at nightWCEU 2016 - 10 tips to sleep better at night
WCEU 2016 - 10 tips to sleep better at night
 
Professional WordPress Workflow - WPDay 2015
Professional WordPress Workflow - WPDay 2015 Professional WordPress Workflow - WPDay 2015
Professional WordPress Workflow - WPDay 2015
 
WordPress Hardening v4
WordPress Hardening v4WordPress Hardening v4
WordPress Hardening v4
 
WordPress Meetup Torino Giugno 2015
WordPress Meetup Torino Giugno 2015WordPress Meetup Torino Giugno 2015
WordPress Meetup Torino Giugno 2015
 
Wordpress e la gestione di progetti complessi
Wordpress e la gestione di progetti complessiWordpress e la gestione di progetti complessi
Wordpress e la gestione di progetti complessi
 
WordPress Hardening
WordPress HardeningWordPress Hardening
WordPress Hardening
 
Use Symfony2 components inside WordPress
Use Symfony2 components inside WordPress Use Symfony2 components inside WordPress
Use Symfony2 components inside WordPress
 
WordPress: Smart Ideas for Startup - SMW torino 2012
WordPress: Smart Ideas for Startup - SMW  torino 2012 WordPress: Smart Ideas for Startup - SMW  torino 2012
WordPress: Smart Ideas for Startup - SMW torino 2012
 
Security and Performance - Italian WordPress Conference
Security and Performance - Italian WordPress ConferenceSecurity and Performance - Italian WordPress Conference
Security and Performance - Italian WordPress Conference
 
Wordpress: «l’abc per gli sviluppatori» - PHP.TO.START [2012]
 Wordpress: «l’abc per gli sviluppatori» - PHP.TO.START [2012] Wordpress: «l’abc per gli sviluppatori» - PHP.TO.START [2012]
Wordpress: «l’abc per gli sviluppatori» - PHP.TO.START [2012]
 
Poliedric WordPress - Go!WebDesign
Poliedric WordPress - Go!WebDesignPoliedric WordPress - Go!WebDesign
Poliedric WordPress - Go!WebDesign
 
Wordpress 3.0 - Go!WebDesign
Wordpress 3.0 - Go!WebDesignWordpress 3.0 - Go!WebDesign
Wordpress 3.0 - Go!WebDesign
 
Custom taxonomies / Custom post type - wordcamp milano 2010
Custom taxonomies / Custom post type - wordcamp milano 2010Custom taxonomies / Custom post type - wordcamp milano 2010
Custom taxonomies / Custom post type - wordcamp milano 2010
 
Ottimizzare un sito web per i motori di ricerca
Ottimizzare un sito web per i motori di ricercaOttimizzare un sito web per i motori di ricerca
Ottimizzare un sito web per i motori di ricerca
 
Casa In Rete
Casa In ReteCasa In Rete
Casa In Rete
 
Come funzionano i template di Wordpress
Come funzionano i template di WordpressCome funzionano i template di Wordpress
Come funzionano i template di Wordpress
 

Recently uploaded

Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 

Recently uploaded (20)

Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 

WordPress for developers - phpday 2011

  • 1. WordPress for developers Maurizio Pelizzone May 14, Verona 2011
  • 2. About me  35 years old  Birth in Turin (Italy)  Co-Founder mavida.com  WordPress addited  http://maurizio.mavida.com  http://www.linkedin.com/in/mauriziopelizzone
  • 3. About this speech  About WordPress  WordPress features overview  Custom type and Taxonomy  Routing and rewrite rules  Custom query and manipulation  Cache tips  Debugging tools  Links and reference
  • 4. About WordPress “WordPress is a web software you can use to create a beautiful website or blog” * “WordPress is a state-of-the-art publishing platform with a focus on aesthetics, web standards, and usability. ”  25 million people have chosen WordPress  54 % content management system market share  More then 14,000 plugins (May 2011)  More then 1.300 themes (May 2011)  32 million WordPress 3 download (February 2011)  More then 9 million WordPress 3.1 download (May 2011)
  • 5. Releases timeline history 1.2 Mingus 22 May 2004 1.5 Strayhorn 17 February 2005 2.0 Duke 31 December 2005 2.1 Ella 22 January 2007 2.2 Getz 16 May 2007 2.3 Dexter 24 September 2007 2.5 Brecker 29 March 2008 2.6 Tyner 15 July 2008 2.7 Coltrane 11 December 2008 2.8 Baker 10 June 2009 2.9 Carmen 19 December 2009 3.0 Thelonious 17 July 2010 3.1 Django 23 February 2011 3.2 30 June 2011
  • 6. Is WordPress better than Drupal or Joomla ?
  • 8. now some boring slides. sorry…
  • 9. WordPress users (my expience) Publisher: > 50% Designers: < 30% Developers: ~ 15% designers developers publishers sample of 143 blogs statistics based on my personal contacts
  • 10. What else?  Strong backward compatibility  Documentation (http://codex.wordpress.org/)  Free themes and plugins direcory  Super fast template manipulation  Automattic
  • 11. Main Features  One click automatic update (core, plugins, themes)  Core multisite implementation  Custom post type  Custom taxonomies  XML-RPC interface  Child themes  Some other staff like: ombed, shortcode, widgets, image editing, automatic thumbnails, comments threading and hierarchic menu generator
  • 12. WordPress Weeknesses 1. Globals variable 2. Not fully OO 3. EZSQL DB Class 4. Uneasy Unit Test 5. Need tuning and manteinance (very often)
  • 13. About Custom Post Type “Post type refers to the various structured data that is maintained in the WordPress posts table and can represent any type of content you want” Default native post type 1. post 2. page 3. attachment 4. revision 5. nav-menu-item ( > wp 3.0)
  • 14. //http://codex.wordpress.org/Function_Reference/register_post_type add_action( 'init', 'add_post_type' ); function add_post_type( ) { $args = array( 'label' => __('films'), 'public' => true, 'hierarchical' => false, ) register_post_type( 'film', $args ); }
  • 15. About Taxonomies “Taxonomy is the practice and science of classification.” (Wikipedia)  More simple content organization  Books (Genre, Authors, Publisher, Edition)  Films (Genre, Actors, Director, Year)  Greater semantics  http://blogname.com/film/matrix/  http://blogname.com/genre/action/  http://blogname.com/actors/keanu-reeves/  http://blogname.com/director/andy-wachowsk/
  • 16. //http://codex.wordpress.org/Function_Reference/register_taxonomy add_action( 'init', 'add_taxonomies' ); function add_taxonomies( ) { $args = array( 'hierarchical' => true, 'public' => true, 'label' => 'Genre', ) register_taxonomy( 'genre', array('post', 'book', $args ); }
  • 17. About Routing and Rewrite “WP_Rewrite is WordPress' class for managing the rewrite rules that allow you to use Pretty Permalinks feature. It has several methods that generate the rewrite rules from values in the database.”
  • 18. //http://codex.wordpress.org/Function_Reference/WP_Rewrite add_action('generate_rewrite_rules', 'my_rewrite_rules'); function my_rewrite_rules( $wp_rewrite ) { $new_rules = array( 'favorite-films' => 'index.php?post_type=films&tag=favorite', ); $wp_rewrite->rules = $new_rules + $wp_rewrite->rules; }
  • 19. //http://codex.wordpress.org/Function_Reference/WP_Rewrite add_action('generate_rewrite_rules', 'my_rewrite_rules'); function my_rewrite_rules( $wp_rewrite ) { $new_rules = array( 'favorite-films/([^/]*)' => 'index.php?post_type=films&tag=favorite&genre=' . $wp_rewrite->preg_index(1), 'favorite-films' => 'index.php?post_type=films&tag=favorite', ); $wp_rewrite->rules = $new_rules + $wp_rewrite->rules; }
  • 20. //http://codex.wordpress.org/Function_Reference/WP_Rewrite add_action('generate_rewrite_rules', 'my_rewrite_rules '); add_filter('query_vars','my_query_vars'); add_action('template_redirect', 'my_redirect' ); function my_rewrite_rules ( $wp_rewrite ) { $new_rules = array( 'advanced-search' => 'index.php?custom_route=advanced-search', ); $wp_rewrite->rules = $new_rules + $wp_rewrite->rules; } function my_query_vars($vars) { $vars[] = 'custom_route'; return $vars; } function my_redirect() { if ( get_query_var('custom_route') != "" ) : $template = array( get_query_var('custom_route') . ".php" ); array_push( $template, 'index.php' ); locate_template( $template, true ); die(); endif; }
  • 21. //http://codex.wordpress.org/Function_Reference/WP_Rewrite <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^index.php$ - [L] RewriteRule ^login /wp-login.php [QSA,L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule>
  • 22. //http://codex.wordpress.org/Function_Reference/WP_Rewrite <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^index.php$ - [L] RewriteRule ^login /wp-login.php [QSA,L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule>
  • 23. About Custom Query and wpdb “WordPress provides a class of functions for all database manipulations. The class is called wpdb and is loosely based on the ezSQL class written and maintained by Justin Vincent.”
  • 24. //http://codex.wordpress.org/Function_Reference/wpdb_Class function list_last_film( $limit ) { global $wpdb; $sql_source = "SELECT ID, post_title FROM $wpdb->posts WHERE post_type = 'films' and post_status = 'published' ORDER BY post_date LIMIT %d“; $sql = $wpdb->prepare($sql_source , $limit ); $last_films = $wpdb->get_results( $sql ); foreach ( $last_films as $film_item) { echo $film_item->post_title; } }
  • 25. //http://codex.wordpress.org/Function_Reference/Custom_Queries add_filter( 'pre_get_posts', 'add_films_in_home' ); function add_films_in_home( $query ) { if ( is_home() && !$query->query_vars['suppress_filters'] ) { $query->set( 'post_type', array( 'post', 'films' ) ); } return $query; }
  • 26. //http://codex.wordpress.org/Function_Reference/Custom_Queries add_filter( 'posts_join', 'my_join'); add_filter( 'posts_fields', 'my_fields'); function my_join ($join) { global $wpdb; if( is_single() && get_query_var('post_type') == 'films' ) { $join .= " LEFT JOIN my_table ON " . $wpdb->posts . ".ID = my_table.ID "; } return $join; } function my_fields( $fields ) { global $wpdb,$post; if( is_single() && get_query_var('post_type') == 'films' ) { $fields .= ", my_table.* "; } return $fields; }
  • 27. Transient API “WordPress Transients API offers a simple and standardized way of storing cached data in the database temporarily by giving it a custom name and a timeframe after which it will expire and be deleted. ”
  • 28. //http://codex.wordpress.org/Function_Reference/Transients_API function list_last_film( $limit ) { global $wpdb; $last_films = get_transient( 'last_films_' . $limit ); if ( $last_films === false ) { $sql_source = "SELECT ID, post_title FROM $wpdb->posts WHERE post_type = 'films' and post_status = 'published' ORDER BY post_date LIMIT %d“; $sql = $wpdb->prepare($sql_source , $limit ); $last_films = $wpdb->get_results( $sql ); set_transient( 'last_films_' . $limit , $last_films , 60*60*2 ); } foreach ( $last_films as $film_item) { echo $film_item->post_title; } }
  • 29. APC Object cache “APC Object Cache provides a persistent memory-based backend for the WordPress object cache. An object cache is a place for WordPress and WordPress extensions to store the results of complex operations. ” http://wordpress.org/extend/plugins/apc/ Installation: 1. Verify that you have PHP 5.2+ and a compatible APC version installed. 2. Copy object-cache.php to your WordPress content directory (wp-content). 3. Done!
  • 30. Cache template part “Simple custom function to store manualy a template part on filesystem”
  • 31. function cache_template_part( $file , $args = null ) { $defaults = array( 'always' => true, 'rewrite' => false, 'cachetime' => 60*60*2, 'cachepath' => 'wp-content/cache/', ); $args = wp_parse_args( $args, $defaults ); extract( $args, EXTR_SKIP ); $cachefile = $cachepath . str_replace( "/", "-", $file); $cachefile_created = ((@file_exists($cachefile)) ) ? @filemtime($cachefile) : 0; if ( !$rewrite && ( time() - $cachetime < $cachefile_created ) && ( $always || !is_user_logged_in()) ) { echo file_get_contents( $cachefile ); } else { .... } }
  • 32. ob_start(); include($file); if ( $always || !is_user_logged_in() ) { $b = ob_get_clean(); $b = preg_replace('/[ ]+/', ' ', $b); $b = str_replace( array("rn", "r", "n", "t" ), '', $b); if ( strlen($b) > 1 ) { $signature = "<!-- Cached " . $cachefile . " - " . date('jS F Y H:i') . " -->"; file_put_contents( $cachefile , $signature . $b); } echo $b; } ob_end_flush();
  • 33. <?php get_header(); ?> <div id="container"> <div id="content" role="main"> <?php /* Run the loop to output the post. * If you want to overload this in a child theme then include a file * called loop-single.php and that will be used instead. */ get_template_part( 'loop', 'single' ); ?> </div><!-- #content --> </div><!-- #container --> <?php get_sidebar(); ?> <?php get_footer(); ?>
  • 34. <?php cache_template_part('header.php'); ?> <div id="container"> <div id="content" role="main"> <?php /* Run the loop to output the post. * If you want to overload this in a child theme then include a file * called loop-single.php and that will be used instead. */ get_template_part( 'loop', 'single' ); ?> </div><!-- #content --> </div><!-- #container --> <?php cache_template_part('sidebar.php'); ?> <?php cache_template_part('footer.php'); ?>
  • 35. add_action( 'save_post', 'clear_cache_on_save'); function clear_cache_on_save( $post_id ) { global $post; if ( $post->post_status == "publish") { $cachepath = 'wp-content/cache/'; $cachefile = array(); $cachefile[] = $cachepath . "header.php"; $cachefile[] = $cachepath . "sidebar.php"; $cachefile[] = $cachepath . "footer.php"; foreach($cachefile as $file){ if( file_exists( $file ) ) { unlink( $file ); } } } }
  • 36. Debugging tools  Debug query http://wordpress.org/extend/plugins/debug-queries/  Debug bar http://wordpress.org/extend/plugins/debug-bar/ Add this line to your wp-config.php  define( 'WP_DEBUG', true );  define( 'SAVEQUERIES', true );
  • 37. What’s coming in WordPress 3.2 1. Requirements Changes: • PHP version 5.2 or greater (old requirement 4.3 or greater) • MySQL version 5.0.15 or greater (old requirement 4.1.2 or greater) 2. Twenty Eleven Theme 3. Speed Improvements For more info: http://codex.wordpress.org/Version_3.2
  • 38. Plugins Toolbox  Custom post type UI http://wordpress.org/extend/plugins/custom-post-type-ui/  Simple Custom Post Type Archives http://wordpress.org/extend/plugins/simple-custom-post-type-archives/  Query Multiple Taxonomies http://wordpress.org/extend/plugins/query-multiple-taxonomies/  Super widgets http://wordpress.org/extend/plugins/super-widgets/  Widget Logic http://wordpress.org/extend/plugins/widget-logic/
  • 39. Links Reference Stats • http://w3techs.com/technologies/overview/content_management/all • http://trends.builtwith.com/blog/WordPress • http://en.wordpress.com/stats/ • http://wordpress.org/download/counter/
  • 40. Links to follow  http://codex.wordpress.org/  http://wpengineer.com/  http://www.wprecipes.com/  http://www.wpbeginner.com/  http://wpshout.com/
  • 42. Thanks Pelizzone Maurizio maurizio@mavida.com http://www.mavida.com http://maurizio.mavida.com