SlideShare a Scribd company logo
How to Write a
WordPress Plugin
Baltimore WordPress Meetup • September 19,
                   2011
What is a plugin?
Written in PHP
        Adds functionality
      without affecting core
               code
               Plugin API
Hooks: Actions &
    Filters
Actions
Hey, WP! I’d like to do this
   when you do that...

Calls a function that performs an
 action, possibly with some data
           given by WP
Actions
add_action( $hook_name, $function );

     add_action(‘wp_head’, ‘my_custom_js’);



add_action(‘wp_head’, array(
    $some_object, ‘my_custom_js_method’)
));
Actions
init

  wp_head

       save_post
Filters

Hey, WP! I’d like to change a
value that you’re returning/
           using...

Calls a function that returns a final
Filters
add_filter( $hook_name, $function );

add_filter(‘the_content’, ‘my_content_filter’);



add_filter(‘the_content’, array(
    $some_object, ‘my_content_method)
));
Filters
the_title

  the_content

     wp_email_from
Getting Started
PHP file or folder
containing PHP file

    Javascript, CSS, etc.

          /wp-content/
Plugin Information
<?php
/*
Plugin Name: My Simple Plugin
Plugin URI: http://theandystratton.com/my-plugin
Description: Does something awesome.
Version: 1.0
Author: theandystratton
Author URI: http://theandystratton.com
License: GPL2
*/
Info Shows in Admin
         UI
Don’t Just Drop
        Code
WordPress includes plugins
    while initializing

Coding without hooking into
 actions/filters = explosion
Starting to Code

What do you want to do?

I want to add my personal
   signature to all posts.
Starting to Code
What does my plugin do?

 Filter the content of all
  posts and append my
         signature.
Some Code

   Hey WP! When you’re
processing standard content,
     call this function!
Take the value WP provides us, add
    my signature, give it back.
It’s as easy as that.
But we can
complicate things...
Archives, Listings,
        etc.
Oops. I mean, I only want it
to add my signature to the
 single post, not listings/
         archives.
Archives, Listings,
         etc.
 What do you want to do
         now?

Filter the content of all posts
  and append my signature
IF we’re on a single post page,
    THEN add my signature.
But we can
complicate things...
Post Type Content

Oops. I have a custom post
type called “Products,” and
it’s adding my signature to
         those, too.
IF we’re on a single blog post
page, THEN add my signature.
How To Write a WordPress Plugin
Getting More
 Advanced
Using Objects
      Avoid tons of
    prefixed functions

Use a prefixed class to hold
  all your actions/filters
Using Objects
Do All Kinds of Fun
       Stuff
Plugins Do Way
     More
  Custom Post Types

      Shortcodes

Metaboxes and metadata
     management
Plugins Do Way
         More
        Settings Pages

        Settings Fields

Incorporate Internationalization
Plugins Do Way
     More
   Redirect requests

 Modify Rewrite Rules

Emulate CRON jobs (wp-
       cron.php)
Going Public
Get in the
        Repository
  Submit your plugin code
http://wordpress.org/extend/plugins/
               about/
http://wordpress.org/extend/plugins/
             about/faq/
Get in the
        Repository
          Readme.txt
http://wordpress.org/extend/plugins/
          about/readme.txt
Get in the
       Repository
    Subversion access &
       management

       Support URL?

Update within 2 years or hide
More Resources
 “Writing a Plugin”
http://codex.wordpress.org/
      Writing_a_Plugin

“WordPress Coding
   Standards”
  http://codex.wordpress.org/
  WordPress_Coding_Standards
Google Works Great
Keep It Simple Stupid.
Code is poetry.
Thanks.

More Related Content

What's hot (20)

PDF
Teaming up WordPress API with Backbone.js in Titanium
Jeroen van Dijk
 
PDF
Bending word press to your will
Tom Jenkins
 
PPT
WordPress Plugins
OpenSource Technologies Pvt. Ltd.
 
PPT
Word press Plugins by WordPress Experts
Yameen Khan
 
PPTX
Building native mobile apps with word press
Nikhil Vishnu P.V
 
PPTX
Writing your own WordPress themes and plugins
Stephanie Wells
 
ODP
Creating Themes
DaisyOlsen
 
PPTX
Web development basics2
Kalluri Vinay Reddy
 
PPTX
Building the basics (WordPress Ottawa 2014)
Christopher Ross
 
ODP
WordPress Security & Backup
Randy Barnes
 
PPTX
Plug in development
Lucky Ali
 
PPTX
Scout web
cciotti3
 
PPTX
Web scraping
rebekacox
 
PPTX
5 Things You Shouldn't Do With A WordPress Plugin
Kelly Phillips
 
PPT
So You Want to Build and Release a Plugin? WordCamp Lancaster 2014
ryanduff
 
PPT
Using Firebug & YSlow
Brad Vernon
 
PPTX
WordPress for beginners lesson 4 fall2015 JALC
Michele Butcher-Jones
 
PDF
Intro to WordPress theme development
Thad Allender
 
KEY
doing_it_right() with WordPress
ryanduff
 
PPT
Intro to jQuery - Tulsa Ruby Group
Brad Vernon
 
Teaming up WordPress API with Backbone.js in Titanium
Jeroen van Dijk
 
Bending word press to your will
Tom Jenkins
 
Word press Plugins by WordPress Experts
Yameen Khan
 
Building native mobile apps with word press
Nikhil Vishnu P.V
 
Writing your own WordPress themes and plugins
Stephanie Wells
 
Creating Themes
DaisyOlsen
 
Web development basics2
Kalluri Vinay Reddy
 
Building the basics (WordPress Ottawa 2014)
Christopher Ross
 
WordPress Security & Backup
Randy Barnes
 
Plug in development
Lucky Ali
 
Scout web
cciotti3
 
Web scraping
rebekacox
 
5 Things You Shouldn't Do With A WordPress Plugin
Kelly Phillips
 
So You Want to Build and Release a Plugin? WordCamp Lancaster 2014
ryanduff
 
Using Firebug & YSlow
Brad Vernon
 
WordPress for beginners lesson 4 fall2015 JALC
Michele Butcher-Jones
 
Intro to WordPress theme development
Thad Allender
 
doing_it_right() with WordPress
ryanduff
 
Intro to jQuery - Tulsa Ruby Group
Brad Vernon
 

Similar to How To Write a WordPress Plugin (20)

PPT
WordPress plugins
Christopher Ross
 
PDF
Jumping Into WordPress Plugin Programming
Dougal Campbell
 
ODP
Beginning WordPress Plugin Development
Aizat Faiz
 
PDF
Write your first WordPress plugin
Anthony Montalbano
 
PDF
Intro to WordPress Plugin Development
Brad Williams
 
PDF
Creating Your First WordPress Plugin
Brad Williams
 
PPTX
Let’s write a plugin
Brian Layman
 
PDF
Laying the proper foundation for plugin and theme development
Tammy Hart
 
PDF
Stop Hacking WordPress, Start Working with it - Charly Leetham - WordCamp Syd...
WordCamp Sydney
 
PPTX
Wordcamp2012 build your plugin
Alexandre Marreiros
 
KEY
WordPress Bootcamp Part 2 - Extending WordPress
Metronet
 
PDF
Extending WordPress - a guide to building your first plugin
Jonathan Bossenger
 
KEY
Intro to WordPress Plugins
zamoose
 
PDF
Becoming a better WordPress Developer
Joey Kudish
 
ODP
WordPress Plugin Development For Beginners
johnpbloch
 
PPTX
2016 WordCamp Pittsburgh - Let's Write a Plugin
Brian Layman
 
PPT
WordPress Plugin Basics
Amanda Giles
 
PDF
Plugin Development @ WordCamp Norway 2014
Barry Kooij
 
PDF
My first WordPress Plugin
Abbas Siddiqi
 
KEY
&lt;?php + WordPress
Christopher Reding
 
WordPress plugins
Christopher Ross
 
Jumping Into WordPress Plugin Programming
Dougal Campbell
 
Beginning WordPress Plugin Development
Aizat Faiz
 
Write your first WordPress plugin
Anthony Montalbano
 
Intro to WordPress Plugin Development
Brad Williams
 
Creating Your First WordPress Plugin
Brad Williams
 
Let’s write a plugin
Brian Layman
 
Laying the proper foundation for plugin and theme development
Tammy Hart
 
Stop Hacking WordPress, Start Working with it - Charly Leetham - WordCamp Syd...
WordCamp Sydney
 
Wordcamp2012 build your plugin
Alexandre Marreiros
 
WordPress Bootcamp Part 2 - Extending WordPress
Metronet
 
Extending WordPress - a guide to building your first plugin
Jonathan Bossenger
 
Intro to WordPress Plugins
zamoose
 
Becoming a better WordPress Developer
Joey Kudish
 
WordPress Plugin Development For Beginners
johnpbloch
 
2016 WordCamp Pittsburgh - Let's Write a Plugin
Brian Layman
 
WordPress Plugin Basics
Amanda Giles
 
Plugin Development @ WordCamp Norway 2014
Barry Kooij
 
My first WordPress Plugin
Abbas Siddiqi
 
&lt;?php + WordPress
Christopher Reding
 
Ad

More from Andy Stratton (10)

PDF
Advanced Custom Post Types
Andy Stratton
 
PDF
50 Shades of WordPress
Andy Stratton
 
PDF
We Are WordPress
Andy Stratton
 
PDF
Everything is Relative: Frameworks, Plugins & SEO
Andy Stratton
 
PDF
Accomplish It With Core: Sliders Galleries + More
Andy Stratton
 
KEY
Let's Build a Custom Theme
Andy Stratton
 
PDF
Accomplish It With Core: Sliders, Galleries and More
Andy Stratton
 
KEY
Diet Pills, SEO & Theme Frameworks: There are no magic bullets.
Andy Stratton
 
KEY
WordPress - Open Source Overview Presentation
Andy Stratton
 
KEY
Trendsetting: Web Design and Beyond
Andy Stratton
 
Advanced Custom Post Types
Andy Stratton
 
50 Shades of WordPress
Andy Stratton
 
We Are WordPress
Andy Stratton
 
Everything is Relative: Frameworks, Plugins & SEO
Andy Stratton
 
Accomplish It With Core: Sliders Galleries + More
Andy Stratton
 
Let's Build a Custom Theme
Andy Stratton
 
Accomplish It With Core: Sliders, Galleries and More
Andy Stratton
 
Diet Pills, SEO & Theme Frameworks: There are no magic bullets.
Andy Stratton
 
WordPress - Open Source Overview Presentation
Andy Stratton
 
Trendsetting: Web Design and Beyond
Andy Stratton
 
Ad

Recently uploaded (20)

PDF
Persuasive AI: risks and opportunities in the age of digital debate
Speck&Tech
 
PDF
Smart Air Quality Monitoring with Serrax AQM190 LITE
SERRAX TECHNOLOGIES LLP
 
PDF
SWEBOK Guide and Software Services Engineering Education
Hironori Washizaki
 
PPTX
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
PDF
Wojciech Ciemski for Top Cyber News MAGAZINE. June 2025
Dr. Ludmila Morozova-Buss
 
PDF
The Builder’s Playbook - 2025 State of AI Report.pdf
jeroen339954
 
PDF
Ampere Offers Energy-Efficient Future For AI And Cloud
ShapeBlue
 
PPTX
Extensions Framework (XaaS) - Enabling Orchestrate Anything
ShapeBlue
 
PPTX
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
PPTX
UiPath Academic Alliance Educator Panels: Session 2 - Business Analyst Content
DianaGray10
 
PDF
Apache CloudStack 201: Let's Design & Build an IaaS Cloud
ShapeBlue
 
PPT
Interview paper part 3, It is based on Interview Prep
SoumyadeepGhosh39
 
PDF
TrustArc Webinar - Data Privacy Trends 2025: Mid-Year Insights & Program Stra...
TrustArc
 
PPTX
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
PDF
Log-Based Anomaly Detection: Enhancing System Reliability with Machine Learning
Mohammed BEKKOUCHE
 
PDF
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
PDF
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
PDF
CloudStack GPU Integration - Rohit Yadav
ShapeBlue
 
PPTX
Top iOS App Development Company in the USA for Innovative Apps
SynapseIndia
 
PPTX
Top Managed Service Providers in Los Angeles
Captain IT
 
Persuasive AI: risks and opportunities in the age of digital debate
Speck&Tech
 
Smart Air Quality Monitoring with Serrax AQM190 LITE
SERRAX TECHNOLOGIES LLP
 
SWEBOK Guide and Software Services Engineering Education
Hironori Washizaki
 
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
Wojciech Ciemski for Top Cyber News MAGAZINE. June 2025
Dr. Ludmila Morozova-Buss
 
The Builder’s Playbook - 2025 State of AI Report.pdf
jeroen339954
 
Ampere Offers Energy-Efficient Future For AI And Cloud
ShapeBlue
 
Extensions Framework (XaaS) - Enabling Orchestrate Anything
ShapeBlue
 
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
UiPath Academic Alliance Educator Panels: Session 2 - Business Analyst Content
DianaGray10
 
Apache CloudStack 201: Let's Design & Build an IaaS Cloud
ShapeBlue
 
Interview paper part 3, It is based on Interview Prep
SoumyadeepGhosh39
 
TrustArc Webinar - Data Privacy Trends 2025: Mid-Year Insights & Program Stra...
TrustArc
 
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
Log-Based Anomaly Detection: Enhancing System Reliability with Machine Learning
Mohammed BEKKOUCHE
 
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
CloudStack GPU Integration - Rohit Yadav
ShapeBlue
 
Top iOS App Development Company in the USA for Innovative Apps
SynapseIndia
 
Top Managed Service Providers in Los Angeles
Captain IT
 

How To Write a WordPress Plugin

Editor's Notes