WordCamp Atlanta Presentation


Published on

My presentation for WordCamp Atlanta 2012 titled "Got Awesome Theme Functionality? It Probably Needs a Plugin". Sorry for the crazy font - SS didn't want to process it right. :-)

Published in: Technology, Business
  • Be the first to comment

WordCamp Atlanta Presentation

  1. 1. GOT AWESOMETHEMEFUNCTIONALITY?!IT PROBABLYNEEDS A PLUGINCore Functionality Plugin + TGM Plugin Activation + WP_FilesystemBy: Thomas Griffin / @jthomasgriffin / thomasgriffinmedia.com
  2. 2. A LITTLE BIT!ABOUT ME I DEVELOP WORDPRESS FOR A LIVING I hold a degree in Business Management and Administration from the best college in the world – Appalachian State University. I officially started September 2010, but have been at this whole developing thing for around two years. Fun fact: I am a scratch golfer.
  3. 3. THE DOWN!AND DIRTY WHERE ARE WE GOING TODAY? 1.  Core Functionality plugin 1.  Anatomy of a plugin 2.  What is a core functionality plugin and why is it important? 2.  TGM Plugin Activation class 1.  Leveraging plugins for your users 2.  Requiring/recommending plugins with your themes 3.  Practical examples 3.  WP_Filesystem (if we have time) 1.  Brief tutorial and how-to’s 4.  Q and A
  4. 4. PLUGINS, PLUGINS,! PROTECT YOURSELFPLUGINS ! A core functionality plugin contains (what should be) themeCORE independent elements of a site.FUNCTIONALITY PLUGINS This can be a range of things, but generally this includes shortcodes,PROTECT metaboxes and CPT’s/CT’s.YOU FROM Why? Users expect these things toANGRY, SNARKY, UPSET, RUDE, INSENSITIVE remain when switching themes. AtIRATE, IRRITATED, ANNOYED & PEEVED worst, this saves you hours of support calls.USERS AND CLIENTS Themes shouldn’t be the end-all- be-all for your projects. Ever.
  6. 6. BUILDING A PLUGINPLUGIN REQUIREMENTS •  Plugin Name•  Plugin URI•  Description•  Author•  Author URI•  (optional) License•  (optional) License URI  
  9. 9. BUILDING A PLUGIN (CONT)A COUPLE OF USEFUL FUNCTIONS•  plugin_dir_path( __FILE__ ) •  __FILE__ is a PHP constant that gets the full path and filename of the current file•  plugins_url( $path, $plugin ) •  $path is the path to whatever you are calling (e.g. an image or script) •  $plugin is the path to the plugin (we can use __FILE__ here)•  Both are documented in the Codex – look them up
  10. 10. BUT WAIT I KNOW YOU ARE THINKING… How can I include plugins within a theme? How will users know how to install them? How can I give users a way to install them? What about private plugins? Can I pull plugins from WordPress repo? What about pre-packaged plugins? ENTER TGM PLUGIN ACTIVATION
  11. 11. TGM PLUGIN!ACTIVATION TGM PLUGIN ACTIVATION is a PHP library that allows you to easily require or recommend plugins for your WordPress themes (and plugins). It allows your users to install and even automatically activate plugins in singular or bulk fashion using native WordPress classes, functions and interfaces. You can reference pre- packaged plugins, plugins from the WordPress Plugin Repository or even plugins hosted elsewhere on the internet. http://tgmpluginactivation.com
  12. 12. WHY !USE IT? SIMPLE: IT IS SILLY NOT TO The library uses all of WordPress’ own classes and methods in the installation process. It even works for those users who have strict permissions. And it works for MultiSite, too.
  13. 13. WHY !USE IT? (CONT) The are a number of benefits to using a plugin for your functionality vs. including it directly in the theme: 1.  To reiterate, it saves you from having to deal with “urgent” messes later 2.  Easy updating and management (WP repo or even your own private repo) 3.  If the project allows, you can share your code with others 4.  Users can’t mess their own site up (no WSOD if they edit it incorrectly) Let’s dive into the library, shall we?
  14. 14. WP_FILESYSTEMWP_Filesystem is a function used to call various WP_Filesystem_*classes depending on a user’s server setup.There are 4 different “methods” that WP_Filesystem uses:1.  Direct2.  FTP3.  FTP Sockets4.  SSH2WP_Filesystem will automatically choose the best method basedon the server setup.  
  15. 15. WHY WP_FILESYSTEM?Writing local files, if not done correctly (err, not done withWP_Filesystem), poses security risks.Why? It is highly unlikely that your webserver user and your useraccount are one in the same. Consider shared hosting – it has awebserver user and lots of other users (like you on it). Give thewebserver user ownership of your files and now everyone hasaccess to them – no bueno.In effect, WP_Filesystem makes sure that you in fact are the onemaking changes to your files.
  16. 16. USING WP_FILESYSTEM?Due to a lack of time, we’ll dive into the TGM Plugin Activationlibrary to see how WP_Filesystem is setup to process plugininstallations.There is one important function you need to know, though:request_filesystem_credentials( $form_post, $type, $error = false,$context, $extra_fields )And once setup, you can call the WP_Filesystem object:global $wp_filesystem
  17. 17. WRAPPING UP1.  Use a core functionality plugin when working on projects2.  Don’t include functionality in a theme that should be in a plugin3.  Require/recommend plugins within your distributed/ commercial themes with the TGM Plugin Activation library4.  Use WP_Filesystem to do any local file writing within your plugins or themes
  18. 18. THANKS!FOR !LISTENING! QUESTIONS?http://thomasgriffinmedia.comhttp://twitter.com/jthomasgriffinhttp://facebook.com/thomasgriffinmedia