SlideShare a Scribd company logo
Plugging into
Matt Harris

<head> conference
26th October 2008




                    1
Types of Wordpress                 Wordpress.com
                                Hosted blogging solution




                                    Wordpress.org
                     Downloadable edition for use on your own server




                                   Wordpress MU
                           Multi-user edition of Wordpress.org




                                                                       2
Hosted
    Wordpress.com

                                                             Free



                                              Maintained and backed up for you



                                               Not hackable or pluggable by you



                                                                                  3
Hosted: scalable, Automa1c deals with the spikes you may 
get
Customisable
    Wordpress.org

                                                          Self-hosted



                                                     Complete code control


                                     Maintenance, backup and reliability are
                                              your responsibility



                                                                               4
Customisable: hackable, expandable.  Add your own 
features
All of Wordpress.org pros and cons
    Wordpress MU

                                Hosting of multiple blogs under one install



                                          Bespoke permission settings per blog



                                                               Your own Wordpress.com



                                                                                        5
Basically this is the meat behind Wordpress.com
Great for Uni’s, EducaEonal places, newspapers, blog networks etc
User Interface




                 6
User Interface




                 7
User Interface




                 8
User Interface




                 9
Admin Interface




                  10
Admin Interface




                  11
Admin Interface




                  12
Hooks and
                                                                                                                                             Filters

       add_action($tag, $function, $priority, $accepted_args)




       add_filter($tag, $function, $priority, $accepted_args)




       add_shortcode($tag, $function)




http://www.flickr.com/photos/gaetanlee/2906941718/
                                                                                                                                                         13
Don’t hack at the core code – makes it difficult to update the your installaEon
Use hooks and filters to ‘inject’ an event into the page processing

Filters are the hooks that WordPress launches to modify text of various types before adding it to the database or sending it to the browser screen

Hooks aOach custom funcEons onto specific acEons
hOp://codex.wordpress.org/Plugin_API/AcEon_Reference
hOp://codex.wordpress.org/Plugin_API/Filter_Reference
hOp://codex.wordpress.org/Shortcode_API
Where to put your code

                                                                                                                     Plugins
                                                                                                               Inside it’s own file




                                                                                                    Theme folder in the file
                                                                                                        functions.php




                                                                                                                                                                                           14
Plugins advantage – easily switch off and onable
FuncEons – will always run – best if required as part of your theme (not covered today but example would be to change something a theme relies on – maybe the movement of a login buOon)
Simple Filter
       <?php

       function changeWord($content) {
           $search = “wordpress”;
           $replace = “my blog”;
           return str_ireplace($search, $replace, $content);
       }

       add_filter(‘the_content’, ‘changeWord’);

       ?>




        http://codex.wordpress.org/Plugin_API/Filter_Reference


                                                                 15
‘the_content” is a built in Wordpress tag
Str_ireplace is case insensiEve

To test this included it in funcEons.php
Simple Filter
       <?php

       function changeWord($content) {
           $search = “wordpress”;
           $replace = “my blog”;
           return str_ireplace($search, $replace, $content);
       }

       add_filter(‘the_content’, ‘changeWord’);

       ?>




        http://codex.wordpress.org/Plugin_API/Filter_Reference


                                                                 16
‘the_content” is a built in Wordpress tag
Str_ireplace is case insensiEve

To test this included it in funcEons.php
Simple Filter




     Before     After


                        17
Simple Hook
      <?php

      function addText() {
          echo “Can you see me?”;
      }

      add_action(’wp_footer', ’addText’);

      ?>




       http://codex.wordpress.org/Plugin_API/Action_Reference


                                                                                                           18
wp_footer Runs when the template calls the wp_footer funcEon, generally near the boOom of the blog page.
Simple Hook
      <?php

      function addText() {
          echo “Can you see me?”;
      }

      add_action(’wp_footer', ’addText’);

      ?>




       http://codex.wordpress.org/Plugin_API/Action_Reference


                                                                                                           19
wp_footer Runs when the template calls the wp_footer funcEon, generally near the boOom of the blog page.
Simple Hook
      <?php

      function changeTextCol() {
          echo “
          <style type=‘text/css’>
               body { color: #0ff00f; }
          </style>
          “;
      }

      add_action(’wp_head', ’changeTextCol’);

      ?>




       http://codex.wordpress.org/Plugin_API/Action_Reference


                                                                                                           20
wp_footer Runs when the template calls the wp_footer funcEon, generally near the boOom of the blog page.
Simple Hook




    Before    After


                      21
Simple Shortcode
       <?php

       function myH1_shortcode($atts, $content = null) {
           extract($atts);
           return ‘
           <div class=“heading”>
                <h1 style=“color:’ . $colour . ‘”>' .
                     $content . '</h1>
           </div>’;
       }

       add_shortcode(’heading', 'myH1_shortcode');

       ?>




       http://codex.wordpress.org/Shortcode_API


                                                                                                                                                                              22
Shortcodes cannot be nested be default. Must add do_shortcode($content) into your handler to do this

Since WP2.5 (fixed 2.5.1. parsing order)

Note this isn’t really safe, $content should be saniEzed first using (stripslashes(wp_filter_post_kses($content) and colour should be protected with aOribute_escape($colour)
Simple Shortcode
      <?php

      [heading color=“#f00”]This is my heading[/heading]

      ?>



       Output

      <div class=quot;headingquot;>
          <h1 style=quot;color:#f00quot;>This is my heading</h1>
      </div>




                                                                                                       23
Shortcodes cannot be nested be default. Must add do_shortcode($content) into your handler to do this
Namespacing




http://www.flickr.com/photos/thost/2244046981/
                                                24
Namespacing
<?php

function addText() {
    echo “Can you see me?”;
}

add_action(’wp_footer', ’addText’);

?>




                                      25
Namespacing
<?php

function tmh_addText() {
    echo “Can you see me?”;
}

add_action(’wp_footer', ’tmh_addText’);

?>




                                          26
Widgets

          27
Plugin Code Structure
<?php

/*
Plugin Name: My Widget
Plugin URI: http://themattharris.com
Description: A widget that puts some text in the
sidebar
Author: Matt Harris
Version: 1.0
Author URI: http://themattharris.com
*/

?>




                                                   28
Widget Code Structure
<?php

function tmh_renderWidget($args) {
    extract($args);
    ?>
    <?php echo $before_widget; ?>
    <?php echo $before_title .
            wptexturize(’My Widget') .
            $after_title;
    ?>
    <p>My Widget Code</p>
    <?php echo $after_widget; ?>
    <?php
}

?>




                                         29
Widget Code Structure
<?php

function tmh_renderWidget($args) {
    extract($args);
    ?>
    <?php echo $before_widget; ?>
    <?php echo $before_title .
            wptexturize(’My Widget') .
            $after_title;
    ?>
    <p>My Widget Code</p>
    <?php echo $after_widget; ?>
    <?php
}

?>




                                         30
Widget Code Structure
<?php

function tmh_renderWidget($args) {
    extract($args);
    ?>
    <?php echo $before_widget; ?>
    <?php echo $before_title .
            wptexturize(’My Widget') .
            $after_title;
    ?>
    <p>My Widget Code</p>
    <?php echo $after_widget; ?>
    <?php
}

?>




                                         31
Widget Code Structure
      <?php

      function tmh_renderWidget($args) {
          extract($args);
          ?>
          <?php echo $before_widget; ?>
          <?php echo $before_title .
                  wptexturize(‘My Widget’) .
                  $after_title;
          ?>
          <p>My Widget Code</p>
          <?php echo $after_widget; ?>
          <?php
      }

      ?>




                                                                           32
wp_specialchars ‐ Like htmlspecialchars except don't double‐encode HTML 
enEEes
Widget Code Structure
<?php

function tmh_renderWidget($args) {
    extract($args);
    ?>
    <?php echo $before_widget; ?>
    <?php echo $before_title .
            wptexturize(’My Widget') .
            $after_title;
    ?>
    <p>My Widget Code</p>
    <?php echo $after_widget; ?>
    <?php
}

?>




                                         33
Widget Registration Code
<?php

function tmh_widgetInit() {
    if (function_exists('register_sidebar_widget’)) {
         register_sidebar_widget('My Widget',
                                 'tmh_renderWidget');
    }
}

add_action( 'widgets_init', 'tmh_widgetInit');

?>




                                                        34
Putting it all together
<?php
/*
Plugin Name: My Widget
Plugin URI: http://themattharris.com
Description: A widget that puts some text in the sidebar
Author: Matt Harris
Version: 1.0
Author URI: http://themattharris.com
*/

function tmh_renderWidget($args) {
         extract($args);
         ?>

        <?php echo $before_widget; ?>
        <?php echo $before_title . wptexturize('My Widget') . $after_title; ?>

        <p>My Widget Code</p>

        <?php echo $after_widget; ?>

        <?php
}

function tmh_widgetInit() {
         if ( function_exists('register_sidebar_widget') ) {
                  register_sidebar_widget('My Widget', 'tmh_renderWidget');
         }
}

add_action( 'widgets_init', 'tmh_widgetInit');

?>




                                                                                 35
Making it work




                 36
Making it work




                 37
Making it work




                 38
Making it work




                 39
40
41
Protecting your blog

check_admin_referer($action, [$query_arg]);

Use with

wp_create_nonce($action);




Use this on any forms you have.




                                              42
Protecting your blog

      attribute_escape($text);                           // also tag escape

      wp_filter_post_kses($data);                        // adds slashes

      wp_filter_nohtml_kses($data);                      // adds slashes




       Use these when outputting data




                                                                              43
aOribute_escape (used for escaping for HTML aOributes)
Kses checks for allow html (or removes it in nohtml)
Protecting your blog
      <?php current_user_can($capability) ?>



       Example
      <?php
       if (current_user_can(‘unfiltered_html’)) {
          $data = Wp_filter_post_kses($data);
       } else {
          $data = wp_filter_nohtml_kses($data);
       }
      ?>



       http://codex.wordpress.org/Roles_and_Capabilities


                                                           44
aOribute_escape (used for escaping for HTML aOributes)
Kses checks for allow html (or removes it in nohtml)
Translation friendly

       <?php __($message, $domain); ?>



       <?php _e($message, $domain); ?>



       Example
       <?php _e(“Title:”,’tmh_pluginname’); ?>


       http://codex.wordpress.org/Translating_WordPress


                                                                                                                          45
WP uses GNU geOext localizaEon framework
Message level translaEon


_e echos
__ doesn’t
Too much info to go into here on how to have wordpress do the translaEon, but its worth building this in from the start
$message is output/returned if no translaEon is found so always worth building this in
Help and More Information
                         Wordpress Mailing Lists
                         http://codex.wordpress.org/Mailing_Lists

                         Wordpress Codex (or Google term + “codex”)
                         http://codex.wordpress.org/

                         Wordpress Support Forum
                         http://wordpress.org/support/

                         Writing a Plugin
                         http://codex.wordpress.org/Writing_a_Plugin



                                                                       46
Wordpres support forum – if the FAQ can’t help
Google search – whole community out there that can help
Matt Harris
http://themattharris.com
me@themattharris.com

All the links:
http://ma.gnolia.com/people/themattharris/tags/plugging
%20into%20wordpress

Image credits:
“Hello … my name is”: http://www.flickr.com/photos/thost/2244046981/
“Hooks for hand”: http://www.flickr.com/photos/gaetanlee/2906941718/
“Wordpress Logo”: http://wordpress.org/about/logos/




                                                                      47

More Related Content

What's hot

WordPress Multisite at WordCamp Columbus by Angie Meeker
WordPress Multisite at WordCamp Columbus by Angie MeekerWordPress Multisite at WordCamp Columbus by Angie Meeker
WordPress Multisite at WordCamp Columbus by Angie Meeker
Angela Meeker
 
Cms & wordpress theme development 2011
Cms & wordpress theme development 2011Cms & wordpress theme development 2011
Cms & wordpress theme development 2011
Dave Wallace
 
How to create a basic template
How to create a basic templateHow to create a basic template
How to create a basic template
vathur
 
HTML5와 모바일
HTML5와 모바일HTML5와 모바일
HTML5와 모바일
ACCESS
 
Wordpress development: A Modern Approach
Wordpress development:  A Modern ApproachWordpress development:  A Modern Approach
Wordpress development: A Modern Approach
Alessandro Fiore
 
Rebrand WordPress Admin
Rebrand WordPress AdminRebrand WordPress Admin
Rebrand WordPress Admin
Chandra Prakash Thapa
 
Bending word press to your will
Bending word press to your willBending word press to your will
Bending word press to your will
Tom Jenkins
 
Introduction to WordPress Theme Development
Introduction to WordPress Theme DevelopmentIntroduction to WordPress Theme Development
Introduction to WordPress Theme Development
Sitdhibong Laokok
 
Extending WordPress Multisite for Fun and Profit by Angie Meeker at WordPress...
Extending WordPress Multisite for Fun and Profit by Angie Meeker at WordPress...Extending WordPress Multisite for Fun and Profit by Angie Meeker at WordPress...
Extending WordPress Multisite for Fun and Profit by Angie Meeker at WordPress...
Angela Meeker
 
Drupal 8 - Corso frontend development
Drupal 8 - Corso frontend developmentDrupal 8 - Corso frontend development
Drupal 8 - Corso frontend development
sparkfabrik
 
Magento Product Types Demystified
Magento Product Types DemystifiedMagento Product Types Demystified
Magento Product Types Demystified
AOE
 
WordPress and Ajax
WordPress and AjaxWordPress and Ajax
WordPress and Ajax
Ronald Huereca
 
WordPress Child Themes
WordPress Child ThemesWordPress Child Themes
WordPress Child Themes
rfair404
 
WordPress Developers Israel Meetup #1
WordPress Developers Israel Meetup #1WordPress Developers Israel Meetup #1
WordPress Developers Israel Meetup #1
Yoav Farhi
 
Wordpress(css,php,js,ajax)
Wordpress(css,php,js,ajax)Wordpress(css,php,js,ajax)
Wordpress(css,php,js,ajax)
SARAVANAN RAMAOORTHY
 
Lone StarPHP 2013 - Building Web Apps from a New Angle
Lone StarPHP 2013 - Building Web Apps from a New AngleLone StarPHP 2013 - Building Web Apps from a New Angle
Lone StarPHP 2013 - Building Web Apps from a New Angle
Pablo Godel
 
20100622 e z_find_slides_gig_v2.1
20100622 e z_find_slides_gig_v2.120100622 e z_find_slides_gig_v2.1
20100622 e z_find_slides_gig_v2.1
Gilles Guirand
 
SEO Cheat Sheets for WordPress
SEO Cheat Sheets for WordPressSEO Cheat Sheets for WordPress
SEO Cheat Sheets for WordPress
Shankar Soma
 
Installing And Configuration for your Wordpress blog
Installing And Configuration for your Wordpress blogInstalling And Configuration for your Wordpress blog
Installing And Configuration for your Wordpress blog
igorgentry
 
Tycho - good, bad or ugly ?
Tycho - good, bad or ugly ?Tycho - good, bad or ugly ?
Tycho - good, bad or ugly ?
Max Andersen
 

What's hot (20)

WordPress Multisite at WordCamp Columbus by Angie Meeker
WordPress Multisite at WordCamp Columbus by Angie MeekerWordPress Multisite at WordCamp Columbus by Angie Meeker
WordPress Multisite at WordCamp Columbus by Angie Meeker
 
Cms & wordpress theme development 2011
Cms & wordpress theme development 2011Cms & wordpress theme development 2011
Cms & wordpress theme development 2011
 
How to create a basic template
How to create a basic templateHow to create a basic template
How to create a basic template
 
HTML5와 모바일
HTML5와 모바일HTML5와 모바일
HTML5와 모바일
 
Wordpress development: A Modern Approach
Wordpress development:  A Modern ApproachWordpress development:  A Modern Approach
Wordpress development: A Modern Approach
 
Rebrand WordPress Admin
Rebrand WordPress AdminRebrand WordPress Admin
Rebrand WordPress Admin
 
Bending word press to your will
Bending word press to your willBending word press to your will
Bending word press to your will
 
Introduction to WordPress Theme Development
Introduction to WordPress Theme DevelopmentIntroduction to WordPress Theme Development
Introduction to WordPress Theme Development
 
Extending WordPress Multisite for Fun and Profit by Angie Meeker at WordPress...
Extending WordPress Multisite for Fun and Profit by Angie Meeker at WordPress...Extending WordPress Multisite for Fun and Profit by Angie Meeker at WordPress...
Extending WordPress Multisite for Fun and Profit by Angie Meeker at WordPress...
 
Drupal 8 - Corso frontend development
Drupal 8 - Corso frontend developmentDrupal 8 - Corso frontend development
Drupal 8 - Corso frontend development
 
Magento Product Types Demystified
Magento Product Types DemystifiedMagento Product Types Demystified
Magento Product Types Demystified
 
WordPress and Ajax
WordPress and AjaxWordPress and Ajax
WordPress and Ajax
 
WordPress Child Themes
WordPress Child ThemesWordPress Child Themes
WordPress Child Themes
 
WordPress Developers Israel Meetup #1
WordPress Developers Israel Meetup #1WordPress Developers Israel Meetup #1
WordPress Developers Israel Meetup #1
 
Wordpress(css,php,js,ajax)
Wordpress(css,php,js,ajax)Wordpress(css,php,js,ajax)
Wordpress(css,php,js,ajax)
 
Lone StarPHP 2013 - Building Web Apps from a New Angle
Lone StarPHP 2013 - Building Web Apps from a New AngleLone StarPHP 2013 - Building Web Apps from a New Angle
Lone StarPHP 2013 - Building Web Apps from a New Angle
 
20100622 e z_find_slides_gig_v2.1
20100622 e z_find_slides_gig_v2.120100622 e z_find_slides_gig_v2.1
20100622 e z_find_slides_gig_v2.1
 
SEO Cheat Sheets for WordPress
SEO Cheat Sheets for WordPressSEO Cheat Sheets for WordPress
SEO Cheat Sheets for WordPress
 
Installing And Configuration for your Wordpress blog
Installing And Configuration for your Wordpress blogInstalling And Configuration for your Wordpress blog
Installing And Configuration for your Wordpress blog
 
Tycho - good, bad or ugly ?
Tycho - good, bad or ugly ?Tycho - good, bad or ugly ?
Tycho - good, bad or ugly ?
 

Similar to <Head> Presentation: Plugging Into Wordpress

Intro to WordPress Plugin Development
Intro to WordPress Plugin DevelopmentIntro to WordPress Plugin Development
Intro to WordPress Plugin Development
Brad Williams
 
Getting started with WordPress development
Getting started with WordPress developmentGetting started with WordPress development
Getting started with WordPress development
Steve Mortiboy
 
Wordpress Plugin Development Short Tutorial
Wordpress Plugin Development Short TutorialWordpress Plugin Development Short Tutorial
Wordpress Plugin Development Short Tutorial
Christos Zigkolis
 
Advanced WordPress Optimization - iGaming Supershow 2012
Advanced WordPress Optimization - iGaming Supershow 2012Advanced WordPress Optimization - iGaming Supershow 2012
Advanced WordPress Optimization - iGaming Supershow 2012
Bastian Grimm
 
Introduction to Plugin Programming, WordCamp Miami 2011
Introduction to Plugin Programming, WordCamp Miami 2011Introduction to Plugin Programming, WordCamp Miami 2011
Introduction to Plugin Programming, WordCamp Miami 2011
David Carr
 
Write your first WordPress plugin
Write your first WordPress pluginWrite your first WordPress plugin
Write your first WordPress plugin
Anthony Montalbano
 
From WordPress With Love
From WordPress With LoveFrom WordPress With Love
From WordPress With Love
Up2 Technology
 
Wordpress
WordpressWordpress
Wordpress
samirlakhanistb
 
40 WordPress Tips: Security, Engagement, SEO & Performance - SMX Sydney 2013
40 WordPress Tips: Security, Engagement, SEO & Performance - SMX Sydney 201340 WordPress Tips: Security, Engagement, SEO & Performance - SMX Sydney 2013
40 WordPress Tips: Security, Engagement, SEO & Performance - SMX Sydney 2013
Bastian Grimm
 
Plug in development
Plug in developmentPlug in development
Plug in development
Lucky Ali
 
WordPress Plugin Development- Rich Media Institute Workshop
WordPress Plugin Development- Rich Media Institute WorkshopWordPress Plugin Development- Rich Media Institute Workshop
WordPress Plugin Development- Rich Media Institute Workshop
Brendan Sera-Shriar
 
WordPress 2.5 Overview - Rich Media Institute
WordPress 2.5 Overview - Rich Media InstituteWordPress 2.5 Overview - Rich Media Institute
WordPress 2.5 Overview - Rich Media Institute
Brendan Sera-Shriar
 
WordPress Optimization & Security - ThinkVisibility 2012, Leeds
WordPress Optimization & Security - ThinkVisibility 2012, LeedsWordPress Optimization & Security - ThinkVisibility 2012, Leeds
WordPress Optimization & Security - ThinkVisibility 2012, Leeds
Bastian Grimm
 
WordPress Theme Workshop: Part 3
WordPress Theme Workshop: Part 3WordPress Theme Workshop: Part 3
WordPress Theme Workshop: Part 3
David Bisset
 
Mastering WordPress Vol.1
Mastering WordPress Vol.1Mastering WordPress Vol.1
Mastering WordPress Vol.1
Wataru OKAMOTO
 
WordPress 3.0 at DC PHP
WordPress 3.0 at DC PHPWordPress 3.0 at DC PHP
WordPress 3.0 at DC PHP
andrewnacin
 
The Way to Theme Enlightenment
The Way to Theme EnlightenmentThe Way to Theme Enlightenment
The Way to Theme Enlightenment
Amanda Giles
 
Step by step guide for creating wordpress plugin
Step by step guide for creating wordpress pluginStep by step guide for creating wordpress plugin
Step by step guide for creating wordpress plugin
Mainak Goswami
 
WordPress Plugins
WordPress PluginsWordPress Plugins
WordPress Plugins
randyhoyt
 
WordPress End-User Security
WordPress End-User SecurityWordPress End-User Security
WordPress End-User Security
Dre Armeda
 

Similar to <Head> Presentation: Plugging Into Wordpress (20)

Intro to WordPress Plugin Development
Intro to WordPress Plugin DevelopmentIntro to WordPress Plugin Development
Intro to WordPress Plugin Development
 
Getting started with WordPress development
Getting started with WordPress developmentGetting started with WordPress development
Getting started with WordPress development
 
Wordpress Plugin Development Short Tutorial
Wordpress Plugin Development Short TutorialWordpress Plugin Development Short Tutorial
Wordpress Plugin Development Short Tutorial
 
Advanced WordPress Optimization - iGaming Supershow 2012
Advanced WordPress Optimization - iGaming Supershow 2012Advanced WordPress Optimization - iGaming Supershow 2012
Advanced WordPress Optimization - iGaming Supershow 2012
 
Introduction to Plugin Programming, WordCamp Miami 2011
Introduction to Plugin Programming, WordCamp Miami 2011Introduction to Plugin Programming, WordCamp Miami 2011
Introduction to Plugin Programming, WordCamp Miami 2011
 
Write your first WordPress plugin
Write your first WordPress pluginWrite your first WordPress plugin
Write your first WordPress plugin
 
From WordPress With Love
From WordPress With LoveFrom WordPress With Love
From WordPress With Love
 
Wordpress
WordpressWordpress
Wordpress
 
40 WordPress Tips: Security, Engagement, SEO & Performance - SMX Sydney 2013
40 WordPress Tips: Security, Engagement, SEO & Performance - SMX Sydney 201340 WordPress Tips: Security, Engagement, SEO & Performance - SMX Sydney 2013
40 WordPress Tips: Security, Engagement, SEO & Performance - SMX Sydney 2013
 
Plug in development
Plug in developmentPlug in development
Plug in development
 
WordPress Plugin Development- Rich Media Institute Workshop
WordPress Plugin Development- Rich Media Institute WorkshopWordPress Plugin Development- Rich Media Institute Workshop
WordPress Plugin Development- Rich Media Institute Workshop
 
WordPress 2.5 Overview - Rich Media Institute
WordPress 2.5 Overview - Rich Media InstituteWordPress 2.5 Overview - Rich Media Institute
WordPress 2.5 Overview - Rich Media Institute
 
WordPress Optimization & Security - ThinkVisibility 2012, Leeds
WordPress Optimization & Security - ThinkVisibility 2012, LeedsWordPress Optimization & Security - ThinkVisibility 2012, Leeds
WordPress Optimization & Security - ThinkVisibility 2012, Leeds
 
WordPress Theme Workshop: Part 3
WordPress Theme Workshop: Part 3WordPress Theme Workshop: Part 3
WordPress Theme Workshop: Part 3
 
Mastering WordPress Vol.1
Mastering WordPress Vol.1Mastering WordPress Vol.1
Mastering WordPress Vol.1
 
WordPress 3.0 at DC PHP
WordPress 3.0 at DC PHPWordPress 3.0 at DC PHP
WordPress 3.0 at DC PHP
 
The Way to Theme Enlightenment
The Way to Theme EnlightenmentThe Way to Theme Enlightenment
The Way to Theme Enlightenment
 
Step by step guide for creating wordpress plugin
Step by step guide for creating wordpress pluginStep by step guide for creating wordpress plugin
Step by step guide for creating wordpress plugin
 
WordPress Plugins
WordPress PluginsWordPress Plugins
WordPress Plugins
 
WordPress End-User Security
WordPress End-User SecurityWordPress End-User Security
WordPress End-User Security
 

More from Matt Harris

HackMIT Presentation
HackMIT PresentationHackMIT Presentation
HackMIT Presentation
Matt Harris
 
HackMIT Lightning Talk
HackMIT Lightning TalkHackMIT Lightning Talk
HackMIT Lightning Talk
Matt Harris
 
From API to Website
From API to WebsiteFrom API to Website
From API to Website
Matt Harris
 
@twitterapi meetup at Paypal Town Hall
@twitterapi meetup at Paypal Town Hall@twitterapi meetup at Paypal Town Hall
@twitterapi meetup at Paypal Town Hall
Matt Harris
 
@twitterapi at SocialApp Workshop
@twitterapi at SocialApp Workshop@twitterapi at SocialApp Workshop
@twitterapi at SocialApp Workshop
Matt Harris
 
Twitter Meetup at the Hacker Dojo
Twitter Meetup at the Hacker DojoTwitter Meetup at the Hacker Dojo
Twitter Meetup at the Hacker Dojo
Matt Harris
 
Hackcamp
HackcampHackcamp
Hackcamp
Matt Harris
 
Adding timezones into Upcoming feeds
Adding timezones into Upcoming feedsAdding timezones into Upcoming feeds
Adding timezones into Upcoming feeds
Matt Harris
 
The eLearning Agenda
The eLearning AgendaThe eLearning Agenda
The eLearning Agenda
Matt Harris
 

More from Matt Harris (9)

HackMIT Presentation
HackMIT PresentationHackMIT Presentation
HackMIT Presentation
 
HackMIT Lightning Talk
HackMIT Lightning TalkHackMIT Lightning Talk
HackMIT Lightning Talk
 
From API to Website
From API to WebsiteFrom API to Website
From API to Website
 
@twitterapi meetup at Paypal Town Hall
@twitterapi meetup at Paypal Town Hall@twitterapi meetup at Paypal Town Hall
@twitterapi meetup at Paypal Town Hall
 
@twitterapi at SocialApp Workshop
@twitterapi at SocialApp Workshop@twitterapi at SocialApp Workshop
@twitterapi at SocialApp Workshop
 
Twitter Meetup at the Hacker Dojo
Twitter Meetup at the Hacker DojoTwitter Meetup at the Hacker Dojo
Twitter Meetup at the Hacker Dojo
 
Hackcamp
HackcampHackcamp
Hackcamp
 
Adding timezones into Upcoming feeds
Adding timezones into Upcoming feedsAdding timezones into Upcoming feeds
Adding timezones into Upcoming feeds
 
The eLearning Agenda
The eLearning AgendaThe eLearning Agenda
The eLearning Agenda
 

Recently uploaded

Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Paige Cruz
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
名前 です男
 
How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
danishmna97
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
Matthew Sinclair
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
Alpen-Adria-Universität
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
Kari Kakkonen
 
Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
DianaGray10
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
Matthew Sinclair
 
Large Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial ApplicationsLarge Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial Applications
Rohit Gautam
 
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
Neo4j
 
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
Neo4j
 
Building RAG with self-deployed Milvus vector database and Snowpark Container...
Building RAG with self-deployed Milvus vector database and Snowpark Container...Building RAG with self-deployed Milvus vector database and Snowpark Container...
Building RAG with self-deployed Milvus vector database and Snowpark Container...
Zilliz
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
Uni Systems S.M.S.A.
 
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Speck&Tech
 
20 Comprehensive Checklist of Designing and Developing a Website
20 Comprehensive Checklist of Designing and Developing a Website20 Comprehensive Checklist of Designing and Developing a Website
20 Comprehensive Checklist of Designing and Developing a Website
Pixlogix Infotech
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
Adtran
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
Octavian Nadolu
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
Neo4j
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
Quotidiano Piemontese
 

Recently uploaded (20)

Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
 
How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
 
Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
 
Large Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial ApplicationsLarge Language Model (LLM) and it’s Geospatial Applications
Large Language Model (LLM) and it’s Geospatial Applications
 
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
 
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
 
Building RAG with self-deployed Milvus vector database and Snowpark Container...
Building RAG with self-deployed Milvus vector database and Snowpark Container...Building RAG with self-deployed Milvus vector database and Snowpark Container...
Building RAG with self-deployed Milvus vector database and Snowpark Container...
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
 
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
 
20 Comprehensive Checklist of Designing and Developing a Website
20 Comprehensive Checklist of Designing and Developing a Website20 Comprehensive Checklist of Designing and Developing a Website
20 Comprehensive Checklist of Designing and Developing a Website
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
 
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
 

<Head> Presentation: Plugging Into Wordpress

  • 1. Plugging into Matt Harris <head> conference 26th October 2008 1
  • 2. Types of Wordpress Wordpress.com Hosted blogging solution Wordpress.org Downloadable edition for use on your own server Wordpress MU Multi-user edition of Wordpress.org 2
  • 3. Hosted Wordpress.com Free Maintained and backed up for you Not hackable or pluggable by you 3 Hosted: scalable, Automa1c deals with the spikes you may  get
  • 4. Customisable Wordpress.org Self-hosted Complete code control Maintenance, backup and reliability are your responsibility 4 Customisable: hackable, expandable.  Add your own  features
  • 5. All of Wordpress.org pros and cons Wordpress MU Hosting of multiple blogs under one install Bespoke permission settings per blog Your own Wordpress.com 5 Basically this is the meat behind Wordpress.com Great for Uni’s, EducaEonal places, newspapers, blog networks etc
  • 13. Hooks and Filters add_action($tag, $function, $priority, $accepted_args) add_filter($tag, $function, $priority, $accepted_args) add_shortcode($tag, $function) http://www.flickr.com/photos/gaetanlee/2906941718/ 13 Don’t hack at the core code – makes it difficult to update the your installaEon Use hooks and filters to ‘inject’ an event into the page processing Filters are the hooks that WordPress launches to modify text of various types before adding it to the database or sending it to the browser screen Hooks aOach custom funcEons onto specific acEons hOp://codex.wordpress.org/Plugin_API/AcEon_Reference hOp://codex.wordpress.org/Plugin_API/Filter_Reference hOp://codex.wordpress.org/Shortcode_API
  • 14. Where to put your code Plugins Inside it’s own file Theme folder in the file functions.php 14 Plugins advantage – easily switch off and onable FuncEons – will always run – best if required as part of your theme (not covered today but example would be to change something a theme relies on – maybe the movement of a login buOon)
  • 15. Simple Filter <?php function changeWord($content) { $search = “wordpress”; $replace = “my blog”; return str_ireplace($search, $replace, $content); } add_filter(‘the_content’, ‘changeWord’); ?> http://codex.wordpress.org/Plugin_API/Filter_Reference 15 ‘the_content” is a built in Wordpress tag Str_ireplace is case insensiEve To test this included it in funcEons.php
  • 16. Simple Filter <?php function changeWord($content) { $search = “wordpress”; $replace = “my blog”; return str_ireplace($search, $replace, $content); } add_filter(‘the_content’, ‘changeWord’); ?> http://codex.wordpress.org/Plugin_API/Filter_Reference 16 ‘the_content” is a built in Wordpress tag Str_ireplace is case insensiEve To test this included it in funcEons.php
  • 17. Simple Filter Before After 17
  • 18. Simple Hook <?php function addText() { echo “Can you see me?”; } add_action(’wp_footer', ’addText’); ?> http://codex.wordpress.org/Plugin_API/Action_Reference 18 wp_footer Runs when the template calls the wp_footer funcEon, generally near the boOom of the blog page.
  • 19. Simple Hook <?php function addText() { echo “Can you see me?”; } add_action(’wp_footer', ’addText’); ?> http://codex.wordpress.org/Plugin_API/Action_Reference 19 wp_footer Runs when the template calls the wp_footer funcEon, generally near the boOom of the blog page.
  • 20. Simple Hook <?php function changeTextCol() { echo “ <style type=‘text/css’> body { color: #0ff00f; } </style> “; } add_action(’wp_head', ’changeTextCol’); ?> http://codex.wordpress.org/Plugin_API/Action_Reference 20 wp_footer Runs when the template calls the wp_footer funcEon, generally near the boOom of the blog page.
  • 21. Simple Hook Before After 21
  • 22. Simple Shortcode <?php function myH1_shortcode($atts, $content = null) { extract($atts); return ‘ <div class=“heading”> <h1 style=“color:’ . $colour . ‘”>' . $content . '</h1> </div>’; } add_shortcode(’heading', 'myH1_shortcode'); ?> http://codex.wordpress.org/Shortcode_API 22 Shortcodes cannot be nested be default. Must add do_shortcode($content) into your handler to do this Since WP2.5 (fixed 2.5.1. parsing order) Note this isn’t really safe, $content should be saniEzed first using (stripslashes(wp_filter_post_kses($content) and colour should be protected with aOribute_escape($colour)
  • 23. Simple Shortcode <?php [heading color=“#f00”]This is my heading[/heading] ?> Output <div class=quot;headingquot;> <h1 style=quot;color:#f00quot;>This is my heading</h1> </div> 23 Shortcodes cannot be nested be default. Must add do_shortcode($content) into your handler to do this
  • 25. Namespacing <?php function addText() { echo “Can you see me?”; } add_action(’wp_footer', ’addText’); ?> 25
  • 26. Namespacing <?php function tmh_addText() { echo “Can you see me?”; } add_action(’wp_footer', ’tmh_addText’); ?> 26
  • 27. Widgets 27
  • 28. Plugin Code Structure <?php /* Plugin Name: My Widget Plugin URI: http://themattharris.com Description: A widget that puts some text in the sidebar Author: Matt Harris Version: 1.0 Author URI: http://themattharris.com */ ?> 28
  • 29. Widget Code Structure <?php function tmh_renderWidget($args) { extract($args); ?> <?php echo $before_widget; ?> <?php echo $before_title . wptexturize(’My Widget') . $after_title; ?> <p>My Widget Code</p> <?php echo $after_widget; ?> <?php } ?> 29
  • 30. Widget Code Structure <?php function tmh_renderWidget($args) { extract($args); ?> <?php echo $before_widget; ?> <?php echo $before_title . wptexturize(’My Widget') . $after_title; ?> <p>My Widget Code</p> <?php echo $after_widget; ?> <?php } ?> 30
  • 31. Widget Code Structure <?php function tmh_renderWidget($args) { extract($args); ?> <?php echo $before_widget; ?> <?php echo $before_title . wptexturize(’My Widget') . $after_title; ?> <p>My Widget Code</p> <?php echo $after_widget; ?> <?php } ?> 31
  • 32. Widget Code Structure <?php function tmh_renderWidget($args) { extract($args); ?> <?php echo $before_widget; ?> <?php echo $before_title . wptexturize(‘My Widget’) . $after_title; ?> <p>My Widget Code</p> <?php echo $after_widget; ?> <?php } ?> 32 wp_specialchars ‐ Like htmlspecialchars except don't double‐encode HTML  enEEes
  • 33. Widget Code Structure <?php function tmh_renderWidget($args) { extract($args); ?> <?php echo $before_widget; ?> <?php echo $before_title . wptexturize(’My Widget') . $after_title; ?> <p>My Widget Code</p> <?php echo $after_widget; ?> <?php } ?> 33
  • 34. Widget Registration Code <?php function tmh_widgetInit() { if (function_exists('register_sidebar_widget’)) { register_sidebar_widget('My Widget', 'tmh_renderWidget'); } } add_action( 'widgets_init', 'tmh_widgetInit'); ?> 34
  • 35. Putting it all together <?php /* Plugin Name: My Widget Plugin URI: http://themattharris.com Description: A widget that puts some text in the sidebar Author: Matt Harris Version: 1.0 Author URI: http://themattharris.com */ function tmh_renderWidget($args) { extract($args); ?> <?php echo $before_widget; ?> <?php echo $before_title . wptexturize('My Widget') . $after_title; ?> <p>My Widget Code</p> <?php echo $after_widget; ?> <?php } function tmh_widgetInit() { if ( function_exists('register_sidebar_widget') ) { register_sidebar_widget('My Widget', 'tmh_renderWidget'); } } add_action( 'widgets_init', 'tmh_widgetInit'); ?> 35
  • 40. 40
  • 41. 41
  • 42. Protecting your blog check_admin_referer($action, [$query_arg]); Use with wp_create_nonce($action); Use this on any forms you have. 42
  • 43. Protecting your blog attribute_escape($text); // also tag escape wp_filter_post_kses($data); // adds slashes wp_filter_nohtml_kses($data); // adds slashes Use these when outputting data 43 aOribute_escape (used for escaping for HTML aOributes) Kses checks for allow html (or removes it in nohtml)
  • 44. Protecting your blog <?php current_user_can($capability) ?> Example <?php if (current_user_can(‘unfiltered_html’)) { $data = Wp_filter_post_kses($data); } else { $data = wp_filter_nohtml_kses($data); } ?> http://codex.wordpress.org/Roles_and_Capabilities 44 aOribute_escape (used for escaping for HTML aOributes) Kses checks for allow html (or removes it in nohtml)
  • 45. Translation friendly <?php __($message, $domain); ?> <?php _e($message, $domain); ?> Example <?php _e(“Title:”,’tmh_pluginname’); ?> http://codex.wordpress.org/Translating_WordPress 45 WP uses GNU geOext localizaEon framework Message level translaEon _e echos __ doesn’t Too much info to go into here on how to have wordpress do the translaEon, but its worth building this in from the start $message is output/returned if no translaEon is found so always worth building this in
  • 46. Help and More Information Wordpress Mailing Lists http://codex.wordpress.org/Mailing_Lists Wordpress Codex (or Google term + “codex”) http://codex.wordpress.org/ Wordpress Support Forum http://wordpress.org/support/ Writing a Plugin http://codex.wordpress.org/Writing_a_Plugin 46 Wordpres support forum – if the FAQ can’t help Google search – whole community out there that can help
  • 47. Matt Harris http://themattharris.com me@themattharris.com All the links: http://ma.gnolia.com/people/themattharris/tags/plugging %20into%20wordpress Image credits: “Hello … my name is”: http://www.flickr.com/photos/thost/2244046981/ “Hooks for hand”: http://www.flickr.com/photos/gaetanlee/2906941718/ “Wordpress Logo”: http://wordpress.org/about/logos/ 47