Writing Plugins for WordPress MU

2,919 views
2,830 views

Published on

Slides for my writing plugins presentation at WordCamp NYC 2009.

Published in: Technology, Business

Writing Plugins for WordPress MU

  1. 1. WordCamp NYC 2009 Writing Plugins for WordPress MU by Ron Rennick
  2. 2. Where to find me <ul><li>http://wpmututorials.com </li></ul><ul><li>http://ronandandrea.com /contact/ </li></ul><ul><li>http://freebpthemes.com </li></ul><ul><li>http://musupport.net </li></ul><ul><li>@wpmuguru </li></ul><ul><li>http://profiles.wordpress.org/wpmuguru </li></ul>
  3. 3. Overview <ul><li>A little out of order - </li></ul><ul><li>Background </li></ul><ul><li>Traps </li></ul><ul><li>Tips </li></ul><ul><li>Tricks </li></ul><ul><li>Discussion </li></ul>
  4. 4. Background <ul><li>Freelancing 16 years </li></ul><ul><li>Teaching </li></ul><ul><li>WordPress </li></ul>
  5. 5. Traps <ul><li>Template tags <?php my_plugin_output(); ?> </li></ul>
  6. 6. Traps <ul><li>Template tags <?php my_plugin_output(); ?> </li></ul><ul><li>$_SERVER['PHP_SELF'] </li></ul>
  7. 7. Traps <ul><li>Template tags <?php my_plugin_output(); ?> </li></ul><ul><li>$_SERVER['PHP_SELF'] </li></ul><ul><li>wp-content/uploads </li></ul>
  8. 8. Traps <ul><li>Template tags <?php my_plugin_output(); ?> </li></ul><ul><li>$_SERVER['PHP_SELF'] </li></ul><ul><li>wp-content/uploads </li></ul><ul><li>plugin tables </li></ul>
  9. 9. Tips <ul><li>Am I WordPress MU ? </li></ul><ul><ul><li>global $wpmu_version; </li></ul></ul><ul><ul><li>if( isset( $wpmu_version ) ) { </li></ul></ul><ul><ul><ul><li>// do MU specific code </li></ul></ul></ul><ul><ul><li>} else { </li></ul></ul><ul><ul><ul><li>// do standard WP code </li></ul></ul></ul><ul><ul><li>} </li></ul></ul>
  10. 10. Tips <ul><li>Globals/Constants </li></ul><ul><li>$current_blog </li></ul><ul><li>$current_site </li></ul>
  11. 11. Tips <ul><li>Globals/Constants </li></ul><ul><li>$current_blog </li></ul><ul><li>$current_site </li></ul><ul><li>VHOST </li></ul><ul><li>$bp </li></ul>
  12. 12. Tips <ul><li>Functions </li></ul><ul><li>get_site_option($key, $default) </li></ul><ul><li>update_site_option($key, $value) </li></ul><ul><li>is_site_admin() </li></ul>
  13. 13. Tips <ul><li>Functions </li></ul><ul><li>get_site_option($key, $default) </li></ul><ul><li>update_site_option($key, $value) </li></ul><ul><li>is_site_admin() </li></ul><ul><li>switch_to_blog($id)/restore_current_blog() </li></ul><ul><li>$wpdb->get_blog_prefix($id) </li></ul>
  14. 14. Tips <ul><li>Constants </li></ul><ul><li>WPMU_PLUGIN_DIR </li></ul><ul><li>WPMU_PLUGIN_URL </li></ul><ul><li>BLOGUPLOADDIR </li></ul>
  15. 15. Tips <ul><li>Global tables </li></ul><ul><li>$wpdb->site </li></ul><ul><li>$wpdb->blogs </li></ul><ul><li>$wpdb->sitemeta </li></ul><ul><li>$wpdb->sitecategories </li></ul>
  16. 16. Tricks <ul><li>Filters </li></ul><ul><li>'pre_site_option_' . $key </li></ul><ul><li>'site_option_' . $key </li></ul><ul><li>'pre_update_site_option_' . $key </li></ul><ul><li>'pre_add_site_option_' . $key </li></ul>
  17. 17. Tricks <ul><li>Hooks </li></ul><ul><li>muplugins_loaded </li></ul><ul><li>delete_blog </li></ul><ul><li>wpmu_new_user </li></ul><ul><li>wpmu_new_blog </li></ul>
  18. 18. Tricks <ul><li>Functions </li></ul><ul><li>get_site_option($key, $default) </li></ul><ul><li>update_site_option($key, $value) </li></ul>
  19. 19. Tricks <ul><li>Functions </li></ul><ul><li>get_site_option($key, $default) </li></ul><ul><li>update_site_option($key, $value) </li></ul><ul><li>Tables </li></ul><ul><li>make it global </li></ul><ul><li>add blog_id field to table </li></ul>
  20. 20. Remember Code is poetry

×