SlideShare uma empresa Scribd logo
1 de 42
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.
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.

Mais conteúdo relacionado

Mais procurados

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
 
Building native mobile apps with word press
Building native mobile apps with word pressBuilding native mobile apps with word press
Building native mobile apps with word press
Nikhil Vishnu P.V
 
Plug in development
Plug in developmentPlug in development
Plug in development
Lucky Ali
 

Mais procurados (20)

Teaming up WordPress API with Backbone.js in Titanium
Teaming up WordPress API with Backbone.js in TitaniumTeaming up WordPress API with Backbone.js in Titanium
Teaming up WordPress API with Backbone.js in Titanium
 
Bending word press to your will
Bending word press to your willBending word press to your will
Bending word press to your will
 
WordPress Plugins
WordPress PluginsWordPress Plugins
WordPress Plugins
 
Word press Plugins by WordPress Experts
Word press Plugins by WordPress ExpertsWord press Plugins by WordPress Experts
Word press Plugins by WordPress Experts
 
Building native mobile apps with word press
Building native mobile apps with word pressBuilding native mobile apps with word press
Building native mobile apps with word press
 
Writing your own WordPress themes and plugins
Writing your own WordPress themes and pluginsWriting your own WordPress themes and plugins
Writing your own WordPress themes and plugins
 
Creating Themes
Creating ThemesCreating Themes
Creating Themes
 
Web development basics2
Web development basics2Web development basics2
Web development basics2
 
Building the basics (WordPress Ottawa 2014)
Building the basics (WordPress Ottawa 2014)Building the basics (WordPress Ottawa 2014)
Building the basics (WordPress Ottawa 2014)
 
WordPress Security & Backup
WordPress Security & Backup WordPress Security & Backup
WordPress Security & Backup
 
Plug in development
Plug in developmentPlug in development
Plug in development
 
Scout web
Scout webScout web
Scout web
 
Web scraping
Web scrapingWeb scraping
Web scraping
 
5 Things You Shouldn't Do With A WordPress Plugin
5 Things You Shouldn't Do With A WordPress Plugin5 Things You Shouldn't Do With A WordPress Plugin
5 Things You Shouldn't Do With A WordPress Plugin
 
So You Want to Build and Release a Plugin? WordCamp Lancaster 2014
So You Want to Build and Release a Plugin? WordCamp Lancaster 2014So You Want to Build and Release a Plugin? WordCamp Lancaster 2014
So You Want to Build and Release a Plugin? WordCamp Lancaster 2014
 
Using Firebug & YSlow
Using Firebug & YSlowUsing Firebug & YSlow
Using Firebug & YSlow
 
WordPress for beginners lesson 4 fall2015 JALC
WordPress for beginners lesson 4 fall2015 JALCWordPress for beginners lesson 4 fall2015 JALC
WordPress for beginners lesson 4 fall2015 JALC
 
Intro to WordPress theme development
Intro to WordPress theme developmentIntro to WordPress theme development
Intro to WordPress theme development
 
doing_it_right() with WordPress
doing_it_right() with WordPressdoing_it_right() with WordPress
doing_it_right() with WordPress
 
Intro to jQuery - Tulsa Ruby Group
Intro to jQuery - Tulsa Ruby GroupIntro to jQuery - Tulsa Ruby Group
Intro to jQuery - Tulsa Ruby Group
 

Semelhante a How To Write a WordPress Plugin

Write your first WordPress plugin
Write your first WordPress pluginWrite your first WordPress plugin
Write your first WordPress plugin
Anthony Montalbano
 

Semelhante a How To Write a WordPress Plugin (20)

Jumping Into WordPress Plugin Programming
Jumping Into WordPress Plugin ProgrammingJumping Into WordPress Plugin Programming
Jumping Into WordPress Plugin Programming
 
Creating Your First WordPress Plugin
Creating Your First WordPress PluginCreating Your First WordPress Plugin
Creating Your First WordPress Plugin
 
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
 
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
 
How to create your own WordPress plugin
How to create your own WordPress pluginHow to create your own WordPress plugin
How to create your own WordPress plugin
 
Write your first WordPress plugin
Write your first WordPress pluginWrite your first WordPress plugin
Write your first WordPress plugin
 
WordPress Plugin development
WordPress Plugin developmentWordPress Plugin development
WordPress Plugin development
 
WordPress Plugin Basics
WordPress Plugin BasicsWordPress Plugin Basics
WordPress Plugin Basics
 
WordPress Structure and Best Practices
WordPress Structure and Best PracticesWordPress Structure and Best Practices
WordPress Structure and Best Practices
 
Custom Post Type - Create and Display
Custom Post Type - Create and DisplayCustom Post Type - Create and Display
Custom Post Type - Create and Display
 
Stop Hacking WordPress, Start Working with it - Charly Leetham - WordCamp Syd...
Stop Hacking WordPress, Start Working with it - Charly Leetham - WordCamp Syd...Stop Hacking WordPress, Start Working with it - Charly Leetham - WordCamp Syd...
Stop Hacking WordPress, Start Working with it - Charly Leetham - WordCamp Syd...
 
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
 
How to Create a Custom WordPress Plugin
How to Create a Custom WordPress PluginHow to Create a Custom WordPress Plugin
How to Create a Custom WordPress Plugin
 
Introduction to WordPress Hooks 2016
Introduction to WordPress Hooks 2016Introduction to WordPress Hooks 2016
Introduction to WordPress Hooks 2016
 
Plugin development demystified 2017
Plugin development demystified 2017Plugin development demystified 2017
Plugin development demystified 2017
 
WordPress plugin #2
WordPress plugin #2WordPress plugin #2
WordPress plugin #2
 
WordPress Plugin Development For Beginners
WordPress Plugin Development For BeginnersWordPress Plugin Development For Beginners
WordPress Plugin Development For Beginners
 
Developing Plugins For WordPress
Developing Plugins For WordPressDeveloping Plugins For WordPress
Developing Plugins For WordPress
 
How to in WPMU: Building a blog directory & Domain Mapping
How to in WPMU: Building a blog directory & Domain MappingHow to in WPMU: Building a blog directory & Domain Mapping
How to in WPMU: Building a blog directory & Domain Mapping
 

Mais de Andy Stratton

Everything is Relative: Frameworks, Plugins & SEO
Everything is Relative: Frameworks, Plugins & SEOEverything is Relative: Frameworks, Plugins & SEO
Everything is Relative: Frameworks, Plugins & SEO
Andy Stratton
 

Mais de Andy Stratton (10)

Advanced Custom Post Types
Advanced Custom Post TypesAdvanced Custom Post Types
Advanced Custom Post Types
 
50 Shades of WordPress
50 Shades of WordPress50 Shades of WordPress
50 Shades of WordPress
 
We Are WordPress
We Are WordPressWe Are WordPress
We Are WordPress
 
Everything is Relative: Frameworks, Plugins & SEO
Everything is Relative: Frameworks, Plugins & SEOEverything is Relative: Frameworks, Plugins & SEO
Everything is Relative: Frameworks, Plugins & SEO
 
Accomplish It With Core: Sliders Galleries + More
Accomplish It With Core: Sliders Galleries + MoreAccomplish It With Core: Sliders Galleries + More
Accomplish It With Core: Sliders Galleries + More
 
Let's Build a Custom Theme
Let's Build a Custom ThemeLet's Build a Custom Theme
Let's Build a Custom Theme
 
Accomplish It With Core: Sliders, Galleries and More
Accomplish It With Core: Sliders, Galleries and MoreAccomplish It With Core: Sliders, Galleries and More
Accomplish It With Core: Sliders, Galleries and More
 
Diet Pills, SEO & Theme Frameworks: There are no magic bullets.
Diet Pills, SEO & Theme Frameworks: There are no magic bullets.Diet Pills, SEO & Theme Frameworks: There are no magic bullets.
Diet Pills, SEO & Theme Frameworks: There are no magic bullets.
 
WordPress - Open Source Overview Presentation
WordPress - Open Source Overview PresentationWordPress - Open Source Overview Presentation
WordPress - Open Source Overview Presentation
 
Trendsetting: Web Design and Beyond
Trendsetting: Web Design and BeyondTrendsetting: Web Design and Beyond
Trendsetting: Web Design and Beyond
 

Último

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 

Último (20)

Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 

How To Write a WordPress Plugin

Notas do Editor

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n
  22. \n
  23. \n
  24. \n
  25. \n
  26. \n
  27. \n
  28. \n
  29. \n
  30. \n
  31. \n
  32. \n
  33. \n
  34. \n
  35. \n
  36. \n
  37. \n
  38. \n
  39. \n
  40. \n
  41. \n
  42. \n