Save 37% off PRO during our Black Friday Sale! »

Best practices for WordPress plugin development

Best practices for WordPress plugin development

Slides for the first part of this tutorial presented on October 4th 2013 at PHPNW, Manchester, UK.
With the release of WP3, WordPress has become a serious contender on the CMS market. The WordPress plugin system allows you to add functionality to WordPress in a snap and turn it into much more than ‘just a blogging platform’.
Learn how to develop for WordPress like a pro and take WordPress to the next level.
Tutorial code:


Juliette Reinders Folmer

October 04, 2013


  1. Best practices for WordPress plugin development Tutorial @ PHPNW2013 Juliette

    Reinders Folmer
  2. Juliette Reinders Folmer Email: Web: LinkedIn: Twitter: GitHub: WordPress:
  3. None
  4. None
  5. None
  6. None
  7. Anatomy of WP Core Plugins Themes Languages Js Libraries Post

    Types Taxonomies Content areas: Front-end: Header Main (Loop) Sidebar (Widgets) Footer Back-end: Admin Bar Menu Post Types Metaboxes Settings pages
  8. None
  9. Hooks Actions – do something Filters – filter someting and

    return the result See: Manual Hooks database: Debug Bar - Action& filter hooks plugin
  10. None
  11. The Loop <?php if ( have_posts() ) { while (

    have_posts() ) { the_post(); // // Post Content here // } // end while } // end if ?>
  12. None
  13. Don’t reinvent the wheel Dashboard Widgets API Database API HTTP

    API File Header API Filesystem API Heartbeat API Metadata API Options API Plugin API Quicktags API Rewrite API Settings API Shortcode API Theme modification API Theme customization API Transients API Widgets API XML-RPC WordPress API
  14. None
  15. Avoid conflict function_exists() class_exists() Jquery no conflicts mode Use bundled

  16. None
  17. Be Unique PHP: Classes Functions global vars (global) constants WP:

    shortcodes option(s) / meta fields nonces settings pages custom post types hooks Filenames HTML/CSS: classes, ids Javascript: I18n object functions Multi-lingual I18n text domain Choose your plugin name carefully & implement consistently
  18. None
  19. Be lazy, be lean Use the available is_...() functions Conditional

    loading of include files Conditional loading of css / js both on admin as well as frontend! Minify js and css New in WP3.6: has_shortcode()
  20. None
  21. Be safe Check early & check often Validation all input

    sanitize_text_field(), sanitize_title(), sanitize_meta() etc function group Escape all output esc_html(), esc_attr(), esc_url(), esc_textarea(), esc_js() etc Use wp_nonce
  22. None
  23. Be worldly GetText UTF-8 Impact on data validation

  24. None
  25. None
  26. Don’t get discouraged WP_DEBUG constants Enable error logging! wp_config.php: @ini_set()

    set_error_handling() to a backtrace function Debug bar to the rescue JS console logging + plugin set_transient() Beware: Lots of templates which do not comply to the WP standards!
  27. None
  28. None
  29. None
  30. None
  31. Starting a plugin <?php /* Plugin Name: Demo Quotes Plugin

    Plugin URI: practices-demo Description: Demo plugin for WordPress Plugins Best Practices Tutorial Version: 1.0 Author: Juliette Reinders Folmer Author URI: Text Domain: demo-quotes-plugin Domain Path: /languages/ License: GPL v3 */
  32. What every plugin needs Hook your functionality onto actions and

    filters Loading your localization files Load CSS Load JS Do something Add admin page or add to another admin page Help information Activation/ Upgrade routines Uninstall routines ...
  33. None
  34. Hooks Offer your own action hooks Offer your own filter

    hooks Document using the @api tag
  35. None
  36. To sum up: Use classes, class constants and statics Most

    plugins run as singletons Leave as small a footprint in the global namespace as possible Prefix ALL your css classes/ids, js functions and anything else in the global namespace Use WP functions – combined knowledge of thousands
  37. Credits Anatomy - Eva di Martino Bridge - Glenn

    Euloth Conflict - Asaf Antman Help - Green Kozi Hooks - Raul Lieberwirth Hooks – Macroman (red background) Alone – Jon Fun - Justin Beckley Lazy - Kevin Cauchi Loop - Gabe Kinsman Security – kismihok
  38. Credits Unique - Luca Volpi (leafs) Unique - David

    Sprinks (birds) Wheel - Pauline Mak WordPress - mkhmarketing (crayons) WordPress - Tom Woodward (revolution) WordPress - Saad Irfan (core, plugins, themes) CMS Landscape - Philippe Martin World - Kenneth Lu Bike - Pauline Mak Daisies - Steve Wall
  39. Keep in touch! (I’m self-employed, you can hire me ;-)

    ) Juliette Reinders Folmer Email: Web: LinkedIn: Twitter: GitHub: WordPress: Please rate this talk on Endorsements and recommendations on LinkedIn are much appreciated too!