Creating                        andMark Jaquith      “JAKE-with”                    Maintaining                    WordPre...
Why?Pa erns! Repo… Sanity.
Why makeplugins
functions.phpis not the newmy-hacks.php
Plugins separatefunctionality fromcore and themes
Pluginscomparmentalize  your code
Plugins[comparmentalize]   your code
Plugins[compart][mentalize]    your code
Pa erns
<?php/*Plugin Name: NAME*/
Encapsulatewith CLASS
function your_initials_long_plugin_name_do_thing()                       vs.               function do_thing()
<?php/*Plugin Name: NAME*/class CWS_ATL_Plugin {  static $instance;    function __construct() {      self::$instance = $th...
function plugins_loaded() {  add_filter( the_title, array( $this, the_title ), 10, 2 );  add_action( init, array( $this, i...
if(!class_exists(CWS_Plugin_v2)){class CWS_Plugin_v2{functionhook($h){$p=10;$m=$this->sanitize_method($h);$b=func_get_args...
<?php/*Plugin Name: NAME*/if(!class_exists(CWS_Plugin_v2)){class CWS_Plugin_v2{function hook($h){$p=10;$m=$this->sanitize_...
// BEFOREfunction plugins_loaded() {  add_filter( the_title, array( $this, the_title ), 10, 2 );  add_action( init, array(...
Defer actions
Options in an array
const OPTIONS = my_plugin_option_name;function get_option( $key ) {  $options = get_option( self::OPTIONS );  if ( isset( ...
Plugins Repo
Community Karma
Professional Credibility
Easy reuse for you
SVN
svn checkout h p://plugins.svn.wordpress.org/{plugin-name}Plugin dev loop                  {                      svn up  ...
/trunk/ for developmentTag your releases
/trunk/readme.txtspecifies the stable tag    Stable tag: 2.3
=== Your Plugin ===Contributors: markjaquith, nacinbotDonate link: h p://example.com/paypalTags: foo, barRequires at least...
1. Tag in SVN2. “Repoint” /trunk/readme.txt
Support        forumswordpress.org/support/view/plugin-commi er/USERNAME
assets/banner-772x250.(jpg|png)
Sanity
Slow downon the optionscowboyand/or-girl
Say hello to my li le friend:
Say hello to my li le friend:     “no”
Encourage goodbehavior
Encourage g o o dbehavior
Q&AMark Jaquith      “JAKE-with” @markjaquithmark@jaquith.memarkjaquith.com
Creating and Maintaining WordPress Plugins
Upcoming SlideShare
Loading in...5
×

Creating and Maintaining WordPress Plugins

4,709

Published on

Published in: Technology, Art & Photos
1 Comment
6 Likes
Statistics
Notes
No Downloads
Views
Total Views
4,709
On Slideshare
0
From Embeds
0
Number of Embeds
12
Actions
Shares
0
Downloads
46
Comments
1
Likes
6
Embeds 0
No embeds

No notes for slide

Creating and Maintaining WordPress Plugins

  1. 1. Creating andMark Jaquith “JAKE-with” Maintaining WordPress @markjaquith Pluginsmark@jaquith.memarkjaquith.com
  2. 2. Why?Pa erns! Repo… Sanity.
  3. 3. Why makeplugins
  4. 4. functions.phpis not the newmy-hacks.php
  5. 5. Plugins separatefunctionality fromcore and themes
  6. 6. Pluginscomparmentalize your code
  7. 7. Plugins[comparmentalize] your code
  8. 8. Plugins[compart][mentalize] your code
  9. 9. Pa erns
  10. 10. <?php/*Plugin Name: NAME*/
  11. 11. Encapsulatewith CLASS
  12. 12. function your_initials_long_plugin_name_do_thing() vs. function do_thing()
  13. 13. <?php/*Plugin Name: NAME*/class CWS_ATL_Plugin { static $instance; function __construct() { self::$instance = $this; add_action( plugins_loaded, array( $this, plugins_loaded ) ); } function plugins_loaded() { // Add actions and hooks here }}new CWS_ATL_Plugin;
  14. 14. function plugins_loaded() { add_filter( the_title, array( $this, the_title ), 10, 2 ); add_action( init, array( $this, init ), 5 ); add_action( omg, array( $this, is_really_tedious ), 11, 3 );}
  15. 15. if(!class_exists(CWS_Plugin_v2)){class CWS_Plugin_v2{functionhook($h){$p=10;$m=$this->sanitize_method($h);$b=func_get_args();unset($b[0]);foreach((array)$b as $a){if(is_int($a))$p=$a;else $m=$a;}return add_action($h,array($this,$m),$p,999);}private functionsanitize_method($m){returnstr_replace(array(.,-),array(_DOT_,_DASH_),$m);}}}
  16. 16. <?php/*Plugin Name: NAME*/if(!class_exists(CWS_Plugin_v2)){class CWS_Plugin_v2{function hook($h){$p=10;$m=$this->sanitize_method($h);$b=func_get_args();unset($b[0]);foreach((array)$b as $a){if(is_int($a))$p=$a;else$m=$a;}return add_action($h,array($this,$m),$p,999);}private function sanitize_method($m){returnstr_replace(array(.,-),array(_DOT_,_DASH_),$m);}}}class CWS_ATL_Plugin extends CWS_Plugin_v2 { static $instance; function __construct() { self::$instance = $this; $this->hook( plugins_loaded ); } function plugins_loaded() { // Add actions and hooks here }}new CWS_ATL_Plugin;
  17. 17. // BEFOREfunction plugins_loaded() { add_filter( the_title, array( $this, the_title ), 10, 2 ); add_action( init, array( $this, init ), 5 ); add_action( omg, array( $this, is_really_tedious ), 11, 3 );}// AFTERfunction plugins_loaded() { $this->hook( the_title ); $this->hook( init, 5 ); $this->hook( omg, is_really_tedious, 3 );}
  18. 18. Defer actions
  19. 19. Options in an array
  20. 20. const OPTIONS = my_plugin_option_name;function get_option( $key ) { $options = get_option( self::OPTIONS ); if ( isset( $options[$key] ) ) return $options[$key];}function set_option( $key, $value ) { $options = get_option( self::OPTIONS ); $options[$key] = $value; update_option( self::OPTIONS, $options );}
  21. 21. Plugins Repo
  22. 22. Community Karma
  23. 23. Professional Credibility
  24. 24. Easy reuse for you
  25. 25. SVN
  26. 26. svn checkout h p://plugins.svn.wordpress.org/{plugin-name}Plugin dev loop { svn up {hackity hack hack} svn add {new-files} svn commit -m {Message about your changes}
  27. 27. /trunk/ for developmentTag your releases
  28. 28. /trunk/readme.txtspecifies the stable tag Stable tag: 2.3
  29. 29. === Your Plugin ===Contributors: markjaquith, nacinbotDonate link: h p://example.com/paypalTags: foo, barRequires at least: 3.2Tested up to: 3.3.1Stable tag: 2.3Here is a short description of the plugin. This should be no morethan 150 characters. No markup here.
  30. 30. 1. Tag in SVN2. “Repoint” /trunk/readme.txt
  31. 31. Support forumswordpress.org/support/view/plugin-commi er/USERNAME
  32. 32. assets/banner-772x250.(jpg|png)
  33. 33. Sanity
  34. 34. Slow downon the optionscowboyand/or-girl
  35. 35. Say hello to my li le friend:
  36. 36. Say hello to my li le friend: “no”
  37. 37. Encourage goodbehavior
  38. 38. Encourage g o o dbehavior
  39. 39. Q&AMark Jaquith “JAKE-with” @markjaquithmark@jaquith.memarkjaquith.com
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×