Post on 13-Jan-2015
description
transcript
GOT AWESOME THEME FUNCTIONALITY?!IT PROBABLY NEEDS A PLUGIN Core Functionality Plugin + TGM Plugin Activation + WP_Filesystem By: Thomas Griffin / @jthomasgriffin / thomasgriffinmedia.com
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.
THE DOWN!AND DIRTY
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
WHERE ARE WE GOING TODAY?
PLUGINS, PLUGINS,!PLUGINS
CORE
FUNCTIONALITY
PLUGINS
PROTECT
YOU
FROM
ANGRY, SNARKY, UPSET, RUDE, INSENSITIVE
IRATE, IRRITATED, ANNOYED & PEEVED
USERS AND CLIENTS
PROTECT YOURSELF !A core functionality plugin contains (what should be) theme independent elements of a site. This can be a range of things, but generally this includes shortcodes, metaboxes and CPT’s/CT’s. Why? Users expect these things to remain when switching themes. At worst, this saves you hours of support calls. Themes shouldn’t be the end-all-be-all for your projects. Ever.
BECAUSE IF YOU DON’T, THIS HAPPENS…
BUILDING A PLUGIN
PLUGIN REQUIREMENTS • Plugin Name • Plugin URI • Description • Author • Author URI • (optional) License • (optional) License URI
BUILDING A PLUGIN (CONT)
BUILDING A PLUGIN (CONT)
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
BUT WAIT
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
I KNOW YOU ARE THINKING…
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
WHY !USE IT?
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.
SIMPLE: IT IS SILLY NOT TO
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?
WP_FILESYSTEM
WP_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. Direct 2. FTP 3. FTP Sockets 4. SSH2
WP_Filesystem will automatically choose the best method based on the server setup.
WHY WP_FILESYSTEM?
Writing local files, if not done correctly (err, not done with WP_Filesystem), poses security risks. Why? It is highly unlikely that your webserver user and your user account are one in the same. Consider shared hosting – it has a webserver user and lots of other users (like you on it). Give the webserver user ownership of your files and now everyone has access to them – no bueno. In effect, WP_Filesystem makes sure that you in fact are the one making changes to your files.
USING WP_FILESYSTEM?
Due to a lack of time, we’ll dive into the TGM Plugin Activation library to see how WP_Filesystem is setup to process plugin installations. 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
WRAPPING UP
1. Use a core functionality plugin when working on projects 2. Don’t include functionality in a theme that should be in a plugin 3. Require/recommend plugins within your distributed/
commercial themes with the TGM Plugin Activation library 4. Use WP_Filesystem to do any local file writing within your
plugins or themes
THANKS!FOR !LISTENING!
QUESTIONS? http://thomasgriffinmedia.com http://twitter.com/jthomasgriffin http://facebook.com/thomasgriffinmedia