SlideShare a Scribd company logo
Use Symfony2 components inside WordPress

             (…and live happily)
Walter Dal Mut
   Cofounder at Corley S.r.l.
   First level degree Electronic Engineering
   Ungraduated student of Computer Science




Maurizio Pelizzone
   Cofounfer at Mavida S.n.c
   WordPress Lover
Use Symfony2 components inside WordPress
Use Symfony2 components inside WordPress
Symfony2 is a reusable set of standalone,
decoupled, and cohesive PHP
components that solve common web
development problems

Fabien Potencier
http://fabien.potencier.org/article/49/what-is-symfony2
Use Composer autoload in your theme
WordPress & Monolog
Monolog is a logging library for PHP 5.3
used by Symfony2. It is inspired by the
Python LogBook library.
Get Monolog
Website: https://github.com/Seldaek/monolog

Using Monolog:
Create a new composer.json file

{
    "require": {
      "monolog/monolog": "1.1.*"
    }
}

curl -s http://getcomposer.org/installer | php
php composer.phar install
wrap inside WordPress…
Use Symfony2 components inside WordPress
… and use in your theme
Use Symfony2 components inside WordPress
Use Symfony2 components inside WordPress
WordPress & Assetic
Assetic is an asset management
framework for PHP.
Assetic is based on the Python webassets
library
Get Assetic
Website: https://github.com/kriswallsmith/assetic

Using Assetic:
Create a new composer.json file

{
    "require": {
      "kriswallsmith/assetic": "v1.0.4"
    }
}

curl -s http://getcomposer.org/installer | php
php composer.phar install
GOAL: Merge, Minimize and Compile all
javascript loaded through WordPress
Use Symfony2 components inside WordPress
Use Symfony2 components inside WordPress
Use Symfony2 components inside WordPress
Code example:
https://github.com/miziomon/symfonyday
WordPress & Twig
Twig: the flexible, fast, and secure
template engine for PHP.

Twig uses a syntax similar to the
Django and Jinja template
languages which inspired the Twig
runtime environment.
Why using a Template Engine ?
PHP doesn't support many features modern
template languages should have nowadays

       o Concision
       o Template oriented Syntax
       o Reusability
       o "Security" by default
                 I'll explain in the next slides
                 Read more on dedicated webpages.

Read more at: http://fabien.potencier.org/article/34/templating-engines-in-php
Concision
PHP                                                    TWIG

<?php echo $name ?>                                    {{name}}
<?php echo                                             {{name|escape}}
  htmlspecialchars(
  $name,
  ENT_QUOTES,
                                                       No short version it's
  'UTF-8')                                              already the short
?>
Short tags
                                                        version.
<?=$name?>
Using short tags could creates problems. You have to
    enable the short tags that are disabled by
    default.
Template oriented Syntax
PHP                                     TWIG

<?php if ($items): ?>                   {% for item in items %}
 <?php foreach ($items as $item): ?>     * {{ item }}
  * <?php echo $item ?>                 {% else %}
 <?php endforeach; ?>                    No item has been found.
<?php else: ?>                          {% endfor %}
 No item has been found. <?php endif;
   ?>
                                        It's more clear and use
                                           a new syntax.
Reusability
<!-- base.html -->                              <!-- index.html -->
<html                                           {% extends "base.html" %}
     xmlns="http://www.w3.org/1999/xhtml"
     xml:lang="en" lang="en">                   {% block head %}
 <head>                                          {{ block.super }}
  {% block head %}                               <link rel="stylesheet" href="main.css" />
    <link rel="stylesheet" href="main.css" />   {% endblock %}
  {% endblock %}
 </head>                                        {% block content %}
 <body>                                          Index content
  {% block content %}{% endblock %}             {% endblock %}
 </body>
</html>
Security
" I'm not saying PHP is not a secure language, far from it. But needless to say that
escaping a variable in a template is just a nightmare.

" Sometimes, security should be enabled by default, especially for templates written
by non-developers who are not necessarily aware of the common web threats like XSS
or CSRF.
                                                                              @fabpot

PHP                                            TWIG
                                               Output is escaped by default.
<?php echo
 htmlspecialchars(                             {% autoescape off %}
 $var,                                          {{ object.as_html }}
 ENT_QUOTES,                                   {% endautoescape %}
 'UTF-8') ?>
                                               I'm well aware of the automatic output
                                                   escaping problems.
Get Twig
Website: http://twig.sensiolabs.org
Twig C Extensions: https://github.com/derickr/twig-ext.git

Using composer:
Create a new composer.json file

{
    "require": {
      "twig/twig": "1.*"
    }
}

curl -s http://getcomposer.org/installer | php
php composer.phar install
Twig & WordPress
Using Twig into a wordpress plugin/theme could
  simplify and improve the development.

• Plugin development (views)
• Theme development
Integrating Twig into a Plugin
Just initialize Twig and use it. Using a static
  reference to share the Twig instance (simple
  way).

function get_twig()
{
  static $twig;
  if (!$twig) {
     $loader = new Twig_Loader_Filesystem(__DIR__ . '/templates');
     $twig = new Twig_Environment($loader, array('cache' => false));
  }

    return $twig;
}
Render a template
During the Twig initialization we specify the view
 location ("templates" folder). Now you can
 create a Twig view and save it. Into your plugin
 just link to it:

$template = get_twig()->loadTemplate('tweets.twig');
echo $template->render(array('elements' => $unpack));


In this example we load the "tweets.twig" view
  and pass the elements variable.
WP Plugin Example
You can checkout an example at:

•   https://github.com/wdalmut/wp-simple-tweets

In this example we add a widget into the admin dashboard that
   shows tweets of @CorleyCloud account.
Make a template using Twig
WordPress is designed to use PHP as template engine. We can force to integrate Twig
  as the default templating system. You can find an example of integration at:

https://github.com/wdalmut/wp-twig-theme

This example realize a simple blank template with some WP functionalities (sidebars,
    posts, pages, archives).
Making a Twig Proxy
WordPress uses a lot of functions to generate pieces of html. To
  speedup the Twig integration we can create a simple proxy
  that enable WP functions into a Twig template.

class TwigProxy {
    public function __call($function, $arguments) {
        if (!function_exists($function)) {
            throw new Exception("{$function} not
   exists.");
            return NULL;
        }
        return call_user_func_array($function,
   $arguments);
    }
}
Using the Twig Proxy
This proxy allows us to call WordPress functions
  into a view.

<div id="sidebar">
    {% if not wp.dynamic_sidebar("Sidebar Widgets") %}

    {{ wp.get_search_form }}
<!-- continue -->
</div>


"dynamic_sidebar" and
 "get_search_form" are WP functions.
Load Twig templates instead PHPs
We can use WordPress hooking system to override the default
  template loading.
•  add_filter
    o home_template
    o single_template
    o page_template
    o 404_template
    o archive_template
    o Etc, etc...
•  add_action
    o template_include
        Engage Twig and prepare data to view.
Layout management
Instead of use get_header and get_footer that break HTML we
   can use template inheritance of Twig.


{% extends "base.twig" %}

{% block title %}
  {{ parent() }} | Page Not Found
{% endblock %}

{% block content %}
<h2>Error 404 - Page Not Found</h2>
{% endblock %}
Enjoy with Twig
Twig is extremely simple and powerful, you can
  play and enjoy with this great template engine
  and get more power during your wp
  development.



                Have a nice day
?
Thank you!

             Walter Dal Mut
             walter.dalmut@gmail.com
             @wdalmut


             Maurizio Pelizzone
             maurizio@mavida.com
             @miziomon

More Related Content

What's hot

WordPress Structure and Best Practices
WordPress Structure and Best PracticesWordPress Structure and Best Practices
WordPress Structure and Best Practices
markparolisi
 
How to Get Started Theming Plone
How to Get Started Theming PloneHow to Get Started Theming Plone
How to Get Started Theming Plone
cdw9
 
WordPress mit Composer und Git verwalten
WordPress mit Composer und Git verwaltenWordPress mit Composer und Git verwalten
WordPress mit Composer und Git verwalten
Walter Ebert
 
Pyramid Lighter/Faster/Better web apps
Pyramid Lighter/Faster/Better web appsPyramid Lighter/Faster/Better web apps
Pyramid Lighter/Faster/Better web apps
Dylan Jay
 
Write your first WordPress plugin
Write your first WordPress pluginWrite your first WordPress plugin
Write your first WordPress plugin
Anthony Montalbano
 
Mehr Performance für WordPress - WordCamp Köln
Mehr Performance für WordPress - WordCamp KölnMehr Performance für WordPress - WordCamp Köln
Mehr Performance für WordPress - WordCamp Köln
Walter Ebert
 
Doing Things the WordPress Way
Doing Things the WordPress WayDoing Things the WordPress Way
Doing Things the WordPress Way
Matt Wiebe
 
Advanced Thesis Techniques and Tricks
Advanced Thesis Techniques and TricksAdvanced Thesis Techniques and Tricks
Advanced Thesis Techniques and Tricks
Brad Williams
 
Don't sh** in the Pool
Don't sh** in the PoolDon't sh** in the Pool
Don't sh** in the Pool
Chris Jean
 
JavaScript Performance (at SFJS)
JavaScript Performance (at SFJS)JavaScript Performance (at SFJS)
JavaScript Performance (at SFJS)
Steve Souders
 
The 5 most common reasons for a slow WordPress site and how to fix them – ext...
The 5 most common reasons for a slow WordPress site and how to fix them – ext...The 5 most common reasons for a slow WordPress site and how to fix them – ext...
The 5 most common reasons for a slow WordPress site and how to fix them – ext...
Otto Kekäläinen
 
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
Diana Thompson
 
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
Diana Thompson
 
Wordpress development: A Modern Approach
Wordpress development:  A Modern ApproachWordpress development:  A Modern Approach
Wordpress development: A Modern Approach
Alessandro Fiore
 
The wp config.php
The wp config.phpThe wp config.php
The wp config.php
Anthony Montalbano
 
Creating Your First WordPress Plugin
Creating Your First WordPress PluginCreating Your First WordPress Plugin
Creating Your First WordPress Plugin
Brad Williams
 
Profiling PHP with Xdebug / Webgrind
Profiling PHP with Xdebug / WebgrindProfiling PHP with Xdebug / Webgrind
Profiling PHP with Xdebug / Webgrind
Sam Keen
 
Using composer with WordPress
Using composer with WordPressUsing composer with WordPress
Using composer with WordPress
Micah Wood
 
SocketStream
SocketStreamSocketStream
SocketStream
Paul Jensen
 
State of the resource timing api
State of the resource timing apiState of the resource timing api
State of the resource timing api
Aaron Peters
 

What's hot (20)

WordPress Structure and Best Practices
WordPress Structure and Best PracticesWordPress Structure and Best Practices
WordPress Structure and Best Practices
 
How to Get Started Theming Plone
How to Get Started Theming PloneHow to Get Started Theming Plone
How to Get Started Theming Plone
 
WordPress mit Composer und Git verwalten
WordPress mit Composer und Git verwaltenWordPress mit Composer und Git verwalten
WordPress mit Composer und Git verwalten
 
Pyramid Lighter/Faster/Better web apps
Pyramid Lighter/Faster/Better web appsPyramid Lighter/Faster/Better web apps
Pyramid Lighter/Faster/Better web apps
 
Write your first WordPress plugin
Write your first WordPress pluginWrite your first WordPress plugin
Write your first WordPress plugin
 
Mehr Performance für WordPress - WordCamp Köln
Mehr Performance für WordPress - WordCamp KölnMehr Performance für WordPress - WordCamp Köln
Mehr Performance für WordPress - WordCamp Köln
 
Doing Things the WordPress Way
Doing Things the WordPress WayDoing Things the WordPress Way
Doing Things the WordPress Way
 
Advanced Thesis Techniques and Tricks
Advanced Thesis Techniques and TricksAdvanced Thesis Techniques and Tricks
Advanced Thesis Techniques and Tricks
 
Don't sh** in the Pool
Don't sh** in the PoolDon't sh** in the Pool
Don't sh** in the Pool
 
JavaScript Performance (at SFJS)
JavaScript Performance (at SFJS)JavaScript Performance (at SFJS)
JavaScript Performance (at SFJS)
 
The 5 most common reasons for a slow WordPress site and how to fix them – ext...
The 5 most common reasons for a slow WordPress site and how to fix them – ext...The 5 most common reasons for a slow WordPress site and how to fix them – ext...
The 5 most common reasons for a slow WordPress site and how to fix them – ext...
 
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
 
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
 
Wordpress development: A Modern Approach
Wordpress development:  A Modern ApproachWordpress development:  A Modern Approach
Wordpress development: A Modern Approach
 
The wp config.php
The wp config.phpThe wp config.php
The wp config.php
 
Creating Your First WordPress Plugin
Creating Your First WordPress PluginCreating Your First WordPress Plugin
Creating Your First WordPress Plugin
 
Profiling PHP with Xdebug / Webgrind
Profiling PHP with Xdebug / WebgrindProfiling PHP with Xdebug / Webgrind
Profiling PHP with Xdebug / Webgrind
 
Using composer with WordPress
Using composer with WordPressUsing composer with WordPress
Using composer with WordPress
 
SocketStream
SocketStreamSocketStream
SocketStream
 
State of the resource timing api
State of the resource timing apiState of the resource timing api
State of the resource timing api
 

Similar to Use Symfony2 components inside WordPress

Twig, the flexible, fast, and secure template language for PHP
Twig, the flexible, fast, and secure template language for PHPTwig, the flexible, fast, and secure template language for PHP
Twig, the flexible, fast, and secure template language for PHP
Fabien Potencier
 
Twig for Drupal @ Frontendunited Amsterdam 2012
Twig for Drupal @ Frontendunited Amsterdam 2012Twig for Drupal @ Frontendunited Amsterdam 2012
Twig for Drupal @ Frontendunited Amsterdam 2012
Rene Bakx
 
Geek Moot '09 -- Smarty 101
Geek Moot '09 -- Smarty 101Geek Moot '09 -- Smarty 101
Geek Moot '09 -- Smarty 101
Ted Kulp
 
Build powerfull and smart web applications with Symfony2
Build powerfull and smart web applications with Symfony2Build powerfull and smart web applications with Symfony2
Build powerfull and smart web applications with Symfony2
Hugo Hamon
 
Living With Legacy Code
Living With Legacy CodeLiving With Legacy Code
Living With Legacy Code
Rowan Merewood
 
Effizientere WordPress-Plugin-Entwicklung mit Softwaretests
Effizientere WordPress-Plugin-Entwicklung mit SoftwaretestsEffizientere WordPress-Plugin-Entwicklung mit Softwaretests
Effizientere WordPress-Plugin-Entwicklung mit Softwaretests
DECK36
 
Building Potent WordPress Websites
Building Potent WordPress WebsitesBuilding Potent WordPress Websites
Building Potent WordPress Websites
Kyle Cearley
 
Implement rich snippets in your webshop
Implement rich snippets in your webshopImplement rich snippets in your webshop
Implement rich snippets in your webshop
Arjen Miedema
 
Getting started with WordPress development
Getting started with WordPress developmentGetting started with WordPress development
Getting started with WordPress development
Steve Mortiboy
 
Symfony Components
Symfony ComponentsSymfony Components
Symfony Components
Nuuktal Consulting
 
PHPConf-TW 2012 # Twig
PHPConf-TW 2012 # TwigPHPConf-TW 2012 # Twig
PHPConf-TW 2012 # Twig
Wake Liu
 
Various Ways of Using WordPress
Various Ways of Using WordPressVarious Ways of Using WordPress
Various Ways of Using WordPress
Nick La
 
Seven deadly theming sins
Seven deadly theming sinsSeven deadly theming sins
Seven deadly theming sins
George Stephanis
 
PSD to WordPress
PSD to WordPressPSD to WordPress
PSD to WordPress
Nile Flores
 
Twig: Friendly Curly Braces Invade Your Templates!
Twig: Friendly Curly Braces Invade Your Templates!Twig: Friendly Curly Braces Invade Your Templates!
Twig: Friendly Curly Braces Invade Your Templates!
Ryan Weaver
 
Revoke-Obfuscation
Revoke-ObfuscationRevoke-Obfuscation
Revoke-Obfuscation
Daniel Bohannon
 
Twig Brief, Tips&Tricks
Twig Brief, Tips&TricksTwig Brief, Tips&Tricks
Twig Brief, Tips&Tricks
Andrei Burian
 
TurboGears2 Pluggable Applications
TurboGears2 Pluggable ApplicationsTurboGears2 Pluggable Applications
TurboGears2 Pluggable Applications
Alessandro Molina
 
Symfony2 revealed
Symfony2 revealedSymfony2 revealed
Symfony2 revealed
Fabien Potencier
 
Quick flask an intro to flask
Quick flask   an intro to flaskQuick flask   an intro to flask
Quick flask an intro to flask
juzten
 

Similar to Use Symfony2 components inside WordPress (20)

Twig, the flexible, fast, and secure template language for PHP
Twig, the flexible, fast, and secure template language for PHPTwig, the flexible, fast, and secure template language for PHP
Twig, the flexible, fast, and secure template language for PHP
 
Twig for Drupal @ Frontendunited Amsterdam 2012
Twig for Drupal @ Frontendunited Amsterdam 2012Twig for Drupal @ Frontendunited Amsterdam 2012
Twig for Drupal @ Frontendunited Amsterdam 2012
 
Geek Moot '09 -- Smarty 101
Geek Moot '09 -- Smarty 101Geek Moot '09 -- Smarty 101
Geek Moot '09 -- Smarty 101
 
Build powerfull and smart web applications with Symfony2
Build powerfull and smart web applications with Symfony2Build powerfull and smart web applications with Symfony2
Build powerfull and smart web applications with Symfony2
 
Living With Legacy Code
Living With Legacy CodeLiving With Legacy Code
Living With Legacy Code
 
Effizientere WordPress-Plugin-Entwicklung mit Softwaretests
Effizientere WordPress-Plugin-Entwicklung mit SoftwaretestsEffizientere WordPress-Plugin-Entwicklung mit Softwaretests
Effizientere WordPress-Plugin-Entwicklung mit Softwaretests
 
Building Potent WordPress Websites
Building Potent WordPress WebsitesBuilding Potent WordPress Websites
Building Potent WordPress Websites
 
Implement rich snippets in your webshop
Implement rich snippets in your webshopImplement rich snippets in your webshop
Implement rich snippets in your webshop
 
Getting started with WordPress development
Getting started with WordPress developmentGetting started with WordPress development
Getting started with WordPress development
 
Symfony Components
Symfony ComponentsSymfony Components
Symfony Components
 
PHPConf-TW 2012 # Twig
PHPConf-TW 2012 # TwigPHPConf-TW 2012 # Twig
PHPConf-TW 2012 # Twig
 
Various Ways of Using WordPress
Various Ways of Using WordPressVarious Ways of Using WordPress
Various Ways of Using WordPress
 
Seven deadly theming sins
Seven deadly theming sinsSeven deadly theming sins
Seven deadly theming sins
 
PSD to WordPress
PSD to WordPressPSD to WordPress
PSD to WordPress
 
Twig: Friendly Curly Braces Invade Your Templates!
Twig: Friendly Curly Braces Invade Your Templates!Twig: Friendly Curly Braces Invade Your Templates!
Twig: Friendly Curly Braces Invade Your Templates!
 
Revoke-Obfuscation
Revoke-ObfuscationRevoke-Obfuscation
Revoke-Obfuscation
 
Twig Brief, Tips&Tricks
Twig Brief, Tips&TricksTwig Brief, Tips&Tricks
Twig Brief, Tips&Tricks
 
TurboGears2 Pluggable Applications
TurboGears2 Pluggable ApplicationsTurboGears2 Pluggable Applications
TurboGears2 Pluggable Applications
 
Symfony2 revealed
Symfony2 revealedSymfony2 revealed
Symfony2 revealed
 
Quick flask an intro to flask
Quick flask   an intro to flaskQuick flask   an intro to flask
Quick flask an intro to flask
 

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 builder
Maurizio 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 night
Maurizio Pelizzone
 
Professional WordPress Workflow - WPDay 2015
Professional WordPress Workflow - WPDay 2015 Professional WordPress Workflow - WPDay 2015
Professional WordPress Workflow - WPDay 2015
Maurizio Pelizzone
 
WordPress Hardening v4
WordPress Hardening v4WordPress Hardening v4
WordPress Hardening v4
Maurizio Pelizzone
 
WordPress Meetup Torino Giugno 2015
WordPress Meetup Torino Giugno 2015WordPress Meetup Torino Giugno 2015
WordPress Meetup Torino Giugno 2015
Maurizio 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 complessi
Maurizio Pelizzone
 
WordPress Hardening
WordPress HardeningWordPress Hardening
WordPress Hardening
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 Conference
Maurizio Pelizzone
 
WordPress for developers - phpday 2011
WordPress for developers -  phpday 2011WordPress for developers -  phpday 2011
WordPress for developers - phpday 2011
Maurizio 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!WebDesign
Maurizio Pelizzone
 
Wordpress 3.0 - Go!WebDesign
Wordpress 3.0 - Go!WebDesignWordpress 3.0 - Go!WebDesign
Wordpress 3.0 - Go!WebDesign
Maurizio 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 2010
Maurizio 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 ricerca
Maurizio Pelizzone
 
Casa In Rete
Casa In ReteCasa In Rete
Casa In Rete
Maurizio Pelizzone
 
Come funzionano i template di Wordpress
Come funzionano i template di WordpressCome funzionano i template di Wordpress
Come funzionano i template di Wordpress
Maurizio 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
 
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 for developers - phpday 2011
WordPress for developers -  phpday 2011WordPress for developers -  phpday 2011
WordPress for developers - phpday 2011
 
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

Data Integration Basics: Merging & Joining Data
Data Integration Basics: Merging & Joining DataData Integration Basics: Merging & Joining Data
Data Integration Basics: Merging & Joining Data
Safe Software
 
Girls call Kolkata 👀 XXXXXXXXXXX 👀 Rs.9.5 K Cash Payment With Room Delivery
Girls call Kolkata 👀 XXXXXXXXXXX 👀 Rs.9.5 K Cash Payment With Room Delivery Girls call Kolkata 👀 XXXXXXXXXXX 👀 Rs.9.5 K Cash Payment With Room Delivery
Girls call Kolkata 👀 XXXXXXXXXXX 👀 Rs.9.5 K Cash Payment With Room Delivery
sunilverma7884
 
Litestack talk at Brighton 2024 (Unleashing the power of SQLite for Ruby apps)
Litestack talk at Brighton 2024 (Unleashing the power of SQLite for Ruby apps)Litestack talk at Brighton 2024 (Unleashing the power of SQLite for Ruby apps)
Litestack talk at Brighton 2024 (Unleashing the power of SQLite for Ruby apps)
Muhammad Ali
 
RPA In Healthcare Benefits, Use Case, Trend And Challenges 2024.pptx
RPA In Healthcare Benefits, Use Case, Trend And Challenges 2024.pptxRPA In Healthcare Benefits, Use Case, Trend And Challenges 2024.pptx
RPA In Healthcare Benefits, Use Case, Trend And Challenges 2024.pptx
SynapseIndia
 
CHAPTER-8 COMPONENTS OF COMPUTER SYSTEM CLASS 9 CBSE
CHAPTER-8 COMPONENTS OF COMPUTER SYSTEM CLASS 9 CBSECHAPTER-8 COMPONENTS OF COMPUTER SYSTEM CLASS 9 CBSE
CHAPTER-8 COMPONENTS OF COMPUTER SYSTEM CLASS 9 CBSE
kumarjarun2010
 
Feature sql server terbaru performance.pptx
Feature sql server terbaru performance.pptxFeature sql server terbaru performance.pptx
Feature sql server terbaru performance.pptx
ssuser1915fe1
 
Girls Call Churchgate 9910780858 Provide Best And Top Girl Service And No1 in...
Girls Call Churchgate 9910780858 Provide Best And Top Girl Service And No1 in...Girls Call Churchgate 9910780858 Provide Best And Top Girl Service And No1 in...
Girls Call Churchgate 9910780858 Provide Best And Top Girl Service And No1 in...
maigasapphire
 
How to build a generative AI solution A step-by-step guide (2).pdf
How to build a generative AI solution A step-by-step guide (2).pdfHow to build a generative AI solution A step-by-step guide (2).pdf
How to build a generative AI solution A step-by-step guide (2).pdf
ChristopherTHyatt
 
WhatsApp Spy Online Trackers and Monitoring Apps
WhatsApp Spy Online Trackers and Monitoring AppsWhatsApp Spy Online Trackers and Monitoring Apps
WhatsApp Spy Online Trackers and Monitoring Apps
HackersList
 
High Profile Girls Call ServiCe Hyderabad 0000000000 Tanisha Best High Class ...
High Profile Girls Call ServiCe Hyderabad 0000000000 Tanisha Best High Class ...High Profile Girls Call ServiCe Hyderabad 0000000000 Tanisha Best High Class ...
High Profile Girls Call ServiCe Hyderabad 0000000000 Tanisha Best High Class ...
aslasdfmkhan4750
 
Tirana Tech Meetup - Agentic RAG with Milvus, Llama3 and Ollama
Tirana Tech Meetup - Agentic RAG with Milvus, Llama3 and OllamaTirana Tech Meetup - Agentic RAG with Milvus, Llama3 and Ollama
Tirana Tech Meetup - Agentic RAG with Milvus, Llama3 and Ollama
Zilliz
 
[Talk] Moving Beyond Spaghetti Infrastructure [AOTB] 2024-07-04.pdf
[Talk] Moving Beyond Spaghetti Infrastructure [AOTB] 2024-07-04.pdf[Talk] Moving Beyond Spaghetti Infrastructure [AOTB] 2024-07-04.pdf
[Talk] Moving Beyond Spaghetti Infrastructure [AOTB] 2024-07-04.pdf
Kief Morris
 
The Rise of AI in Cybersecurity How Machine Learning Will Shape Threat Detect...
The Rise of AI in Cybersecurity How Machine Learning Will Shape Threat Detect...The Rise of AI in Cybersecurity How Machine Learning Will Shape Threat Detect...
The Rise of AI in Cybersecurity How Machine Learning Will Shape Threat Detect...
digitalxplive
 
Acumatica vs. Sage Intacct vs. NetSuite _ NOW CFO.pdf
Acumatica vs. Sage Intacct vs. NetSuite _ NOW CFO.pdfAcumatica vs. Sage Intacct vs. NetSuite _ NOW CFO.pdf
Acumatica vs. Sage Intacct vs. NetSuite _ NOW CFO.pdf
BrainSell Technologies
 
Scaling Connections in PostgreSQL Postgres Bangalore(PGBLR) Meetup-2 - Mydbops
Scaling Connections in PostgreSQL Postgres Bangalore(PGBLR) Meetup-2 - MydbopsScaling Connections in PostgreSQL Postgres Bangalore(PGBLR) Meetup-2 - Mydbops
Scaling Connections in PostgreSQL Postgres Bangalore(PGBLR) Meetup-2 - Mydbops
Mydbops
 
Salesforce AI & Einstein Copilot Workshop
Salesforce AI & Einstein Copilot WorkshopSalesforce AI & Einstein Copilot Workshop
Salesforce AI & Einstein Copilot Workshop
CEPTES Software Inc
 
How RPA Help in the Transportation and Logistics Industry.pptx
How RPA Help in the Transportation and Logistics Industry.pptxHow RPA Help in the Transportation and Logistics Industry.pptx
How RPA Help in the Transportation and Logistics Industry.pptx
SynapseIndia
 
Google I/O Extended Harare Merged Slides
Google I/O Extended Harare Merged SlidesGoogle I/O Extended Harare Merged Slides
Google I/O Extended Harare Merged Slides
Google Developer Group - Harare
 
Using LLM Agents with Llama 3, LangGraph and Milvus
Using LLM Agents with Llama 3, LangGraph and MilvusUsing LLM Agents with Llama 3, LangGraph and Milvus
Using LLM Agents with Llama 3, LangGraph and Milvus
Zilliz
 
CiscoIconsLibrary cours de réseau VLAN.ppt
CiscoIconsLibrary cours de réseau VLAN.pptCiscoIconsLibrary cours de réseau VLAN.ppt
CiscoIconsLibrary cours de réseau VLAN.ppt
moinahousna
 

Recently uploaded (20)

Data Integration Basics: Merging & Joining Data
Data Integration Basics: Merging & Joining DataData Integration Basics: Merging & Joining Data
Data Integration Basics: Merging & Joining Data
 
Girls call Kolkata 👀 XXXXXXXXXXX 👀 Rs.9.5 K Cash Payment With Room Delivery
Girls call Kolkata 👀 XXXXXXXXXXX 👀 Rs.9.5 K Cash Payment With Room Delivery Girls call Kolkata 👀 XXXXXXXXXXX 👀 Rs.9.5 K Cash Payment With Room Delivery
Girls call Kolkata 👀 XXXXXXXXXXX 👀 Rs.9.5 K Cash Payment With Room Delivery
 
Litestack talk at Brighton 2024 (Unleashing the power of SQLite for Ruby apps)
Litestack talk at Brighton 2024 (Unleashing the power of SQLite for Ruby apps)Litestack talk at Brighton 2024 (Unleashing the power of SQLite for Ruby apps)
Litestack talk at Brighton 2024 (Unleashing the power of SQLite for Ruby apps)
 
RPA In Healthcare Benefits, Use Case, Trend And Challenges 2024.pptx
RPA In Healthcare Benefits, Use Case, Trend And Challenges 2024.pptxRPA In Healthcare Benefits, Use Case, Trend And Challenges 2024.pptx
RPA In Healthcare Benefits, Use Case, Trend And Challenges 2024.pptx
 
CHAPTER-8 COMPONENTS OF COMPUTER SYSTEM CLASS 9 CBSE
CHAPTER-8 COMPONENTS OF COMPUTER SYSTEM CLASS 9 CBSECHAPTER-8 COMPONENTS OF COMPUTER SYSTEM CLASS 9 CBSE
CHAPTER-8 COMPONENTS OF COMPUTER SYSTEM CLASS 9 CBSE
 
Feature sql server terbaru performance.pptx
Feature sql server terbaru performance.pptxFeature sql server terbaru performance.pptx
Feature sql server terbaru performance.pptx
 
Girls Call Churchgate 9910780858 Provide Best And Top Girl Service And No1 in...
Girls Call Churchgate 9910780858 Provide Best And Top Girl Service And No1 in...Girls Call Churchgate 9910780858 Provide Best And Top Girl Service And No1 in...
Girls Call Churchgate 9910780858 Provide Best And Top Girl Service And No1 in...
 
How to build a generative AI solution A step-by-step guide (2).pdf
How to build a generative AI solution A step-by-step guide (2).pdfHow to build a generative AI solution A step-by-step guide (2).pdf
How to build a generative AI solution A step-by-step guide (2).pdf
 
WhatsApp Spy Online Trackers and Monitoring Apps
WhatsApp Spy Online Trackers and Monitoring AppsWhatsApp Spy Online Trackers and Monitoring Apps
WhatsApp Spy Online Trackers and Monitoring Apps
 
High Profile Girls Call ServiCe Hyderabad 0000000000 Tanisha Best High Class ...
High Profile Girls Call ServiCe Hyderabad 0000000000 Tanisha Best High Class ...High Profile Girls Call ServiCe Hyderabad 0000000000 Tanisha Best High Class ...
High Profile Girls Call ServiCe Hyderabad 0000000000 Tanisha Best High Class ...
 
Tirana Tech Meetup - Agentic RAG with Milvus, Llama3 and Ollama
Tirana Tech Meetup - Agentic RAG with Milvus, Llama3 and OllamaTirana Tech Meetup - Agentic RAG with Milvus, Llama3 and Ollama
Tirana Tech Meetup - Agentic RAG with Milvus, Llama3 and Ollama
 
[Talk] Moving Beyond Spaghetti Infrastructure [AOTB] 2024-07-04.pdf
[Talk] Moving Beyond Spaghetti Infrastructure [AOTB] 2024-07-04.pdf[Talk] Moving Beyond Spaghetti Infrastructure [AOTB] 2024-07-04.pdf
[Talk] Moving Beyond Spaghetti Infrastructure [AOTB] 2024-07-04.pdf
 
The Rise of AI in Cybersecurity How Machine Learning Will Shape Threat Detect...
The Rise of AI in Cybersecurity How Machine Learning Will Shape Threat Detect...The Rise of AI in Cybersecurity How Machine Learning Will Shape Threat Detect...
The Rise of AI in Cybersecurity How Machine Learning Will Shape Threat Detect...
 
Acumatica vs. Sage Intacct vs. NetSuite _ NOW CFO.pdf
Acumatica vs. Sage Intacct vs. NetSuite _ NOW CFO.pdfAcumatica vs. Sage Intacct vs. NetSuite _ NOW CFO.pdf
Acumatica vs. Sage Intacct vs. NetSuite _ NOW CFO.pdf
 
Scaling Connections in PostgreSQL Postgres Bangalore(PGBLR) Meetup-2 - Mydbops
Scaling Connections in PostgreSQL Postgres Bangalore(PGBLR) Meetup-2 - MydbopsScaling Connections in PostgreSQL Postgres Bangalore(PGBLR) Meetup-2 - Mydbops
Scaling Connections in PostgreSQL Postgres Bangalore(PGBLR) Meetup-2 - Mydbops
 
Salesforce AI & Einstein Copilot Workshop
Salesforce AI & Einstein Copilot WorkshopSalesforce AI & Einstein Copilot Workshop
Salesforce AI & Einstein Copilot Workshop
 
How RPA Help in the Transportation and Logistics Industry.pptx
How RPA Help in the Transportation and Logistics Industry.pptxHow RPA Help in the Transportation and Logistics Industry.pptx
How RPA Help in the Transportation and Logistics Industry.pptx
 
Google I/O Extended Harare Merged Slides
Google I/O Extended Harare Merged SlidesGoogle I/O Extended Harare Merged Slides
Google I/O Extended Harare Merged Slides
 
Using LLM Agents with Llama 3, LangGraph and Milvus
Using LLM Agents with Llama 3, LangGraph and MilvusUsing LLM Agents with Llama 3, LangGraph and Milvus
Using LLM Agents with Llama 3, LangGraph and Milvus
 
CiscoIconsLibrary cours de réseau VLAN.ppt
CiscoIconsLibrary cours de réseau VLAN.pptCiscoIconsLibrary cours de réseau VLAN.ppt
CiscoIconsLibrary cours de réseau VLAN.ppt
 

Use Symfony2 components inside WordPress

  • 1. Use Symfony2 components inside WordPress (…and live happily)
  • 2. Walter Dal Mut  Cofounder at Corley S.r.l.  First level degree Electronic Engineering  Ungraduated student of Computer Science Maurizio Pelizzone  Cofounfer at Mavida S.n.c  WordPress Lover
  • 5. Symfony2 is a reusable set of standalone, decoupled, and cohesive PHP components that solve common web development problems Fabien Potencier http://fabien.potencier.org/article/49/what-is-symfony2
  • 6. Use Composer autoload in your theme
  • 8. Monolog is a logging library for PHP 5.3 used by Symfony2. It is inspired by the Python LogBook library.
  • 9. Get Monolog Website: https://github.com/Seldaek/monolog Using Monolog: Create a new composer.json file { "require": { "monolog/monolog": "1.1.*" } } curl -s http://getcomposer.org/installer | php php composer.phar install
  • 12. … and use in your theme
  • 16. Assetic is an asset management framework for PHP. Assetic is based on the Python webassets library
  • 17. Get Assetic Website: https://github.com/kriswallsmith/assetic Using Assetic: Create a new composer.json file { "require": { "kriswallsmith/assetic": "v1.0.4" } } curl -s http://getcomposer.org/installer | php php composer.phar install
  • 18. GOAL: Merge, Minimize and Compile all javascript loaded through WordPress
  • 24. Twig: the flexible, fast, and secure template engine for PHP. Twig uses a syntax similar to the Django and Jinja template languages which inspired the Twig runtime environment.
  • 25. Why using a Template Engine ?
  • 26. PHP doesn't support many features modern template languages should have nowadays o Concision o Template oriented Syntax o Reusability o "Security" by default  I'll explain in the next slides  Read more on dedicated webpages. Read more at: http://fabien.potencier.org/article/34/templating-engines-in-php
  • 27. Concision PHP TWIG <?php echo $name ?> {{name}} <?php echo {{name|escape}} htmlspecialchars( $name, ENT_QUOTES, No short version it's 'UTF-8') already the short ?> Short tags version. <?=$name?> Using short tags could creates problems. You have to enable the short tags that are disabled by default.
  • 28. Template oriented Syntax PHP TWIG <?php if ($items): ?> {% for item in items %} <?php foreach ($items as $item): ?> * {{ item }} * <?php echo $item ?> {% else %} <?php endforeach; ?> No item has been found. <?php else: ?> {% endfor %} No item has been found. <?php endif; ?> It's more clear and use a new syntax.
  • 29. Reusability <!-- base.html --> <!-- index.html --> <html {% extends "base.html" %} xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> {% block head %} <head> {{ block.super }} {% block head %} <link rel="stylesheet" href="main.css" /> <link rel="stylesheet" href="main.css" /> {% endblock %} {% endblock %} </head> {% block content %} <body> Index content {% block content %}{% endblock %} {% endblock %} </body> </html>
  • 30. Security " I'm not saying PHP is not a secure language, far from it. But needless to say that escaping a variable in a template is just a nightmare. " Sometimes, security should be enabled by default, especially for templates written by non-developers who are not necessarily aware of the common web threats like XSS or CSRF. @fabpot PHP TWIG Output is escaped by default. <?php echo htmlspecialchars( {% autoescape off %} $var, {{ object.as_html }} ENT_QUOTES, {% endautoescape %} 'UTF-8') ?> I'm well aware of the automatic output escaping problems.
  • 31. Get Twig Website: http://twig.sensiolabs.org Twig C Extensions: https://github.com/derickr/twig-ext.git Using composer: Create a new composer.json file { "require": { "twig/twig": "1.*" } } curl -s http://getcomposer.org/installer | php php composer.phar install
  • 32. Twig & WordPress Using Twig into a wordpress plugin/theme could simplify and improve the development. • Plugin development (views) • Theme development
  • 33. Integrating Twig into a Plugin Just initialize Twig and use it. Using a static reference to share the Twig instance (simple way). function get_twig() { static $twig; if (!$twig) { $loader = new Twig_Loader_Filesystem(__DIR__ . '/templates'); $twig = new Twig_Environment($loader, array('cache' => false)); } return $twig; }
  • 34. Render a template During the Twig initialization we specify the view location ("templates" folder). Now you can create a Twig view and save it. Into your plugin just link to it: $template = get_twig()->loadTemplate('tweets.twig'); echo $template->render(array('elements' => $unpack)); In this example we load the "tweets.twig" view and pass the elements variable.
  • 35. WP Plugin Example You can checkout an example at: • https://github.com/wdalmut/wp-simple-tweets In this example we add a widget into the admin dashboard that shows tweets of @CorleyCloud account.
  • 36. Make a template using Twig WordPress is designed to use PHP as template engine. We can force to integrate Twig as the default templating system. You can find an example of integration at: https://github.com/wdalmut/wp-twig-theme This example realize a simple blank template with some WP functionalities (sidebars, posts, pages, archives).
  • 37. Making a Twig Proxy WordPress uses a lot of functions to generate pieces of html. To speedup the Twig integration we can create a simple proxy that enable WP functions into a Twig template. class TwigProxy { public function __call($function, $arguments) { if (!function_exists($function)) { throw new Exception("{$function} not exists."); return NULL; } return call_user_func_array($function, $arguments); } }
  • 38. Using the Twig Proxy This proxy allows us to call WordPress functions into a view. <div id="sidebar"> {% if not wp.dynamic_sidebar("Sidebar Widgets") %} {{ wp.get_search_form }} <!-- continue --> </div> "dynamic_sidebar" and "get_search_form" are WP functions.
  • 39. Load Twig templates instead PHPs We can use WordPress hooking system to override the default template loading. • add_filter o home_template o single_template o page_template o 404_template o archive_template o Etc, etc... • add_action o template_include  Engage Twig and prepare data to view.
  • 40. Layout management Instead of use get_header and get_footer that break HTML we can use template inheritance of Twig. {% extends "base.twig" %} {% block title %} {{ parent() }} | Page Not Found {% endblock %} {% block content %} <h2>Error 404 - Page Not Found</h2> {% endblock %}
  • 41. Enjoy with Twig Twig is extremely simple and powerful, you can play and enjoy with this great template engine and get more power during your wp development. Have a nice day
  • 42. ?
  • 43. Thank you! Walter Dal Mut walter.dalmut@gmail.com @wdalmut Maurizio Pelizzone maurizio@mavida.com @miziomon