Upgrade to Pro — share decks privately, control downloads, hide ads and more …

An Introduction to Plugin Development - WCBNE 19

An Introduction to Plugin Development - WCBNE 19

Have you ever wanted to build your own plugin? Or maybe you’re just curious as to how plugins work? We’ll take a look at some popular plugins, learn the WordPress hook system, then walk through building your first custom WordPress plugin from scratch.

Cameron Jones

August 24, 2019
Tweet

More Decks by Cameron Jones

Other Decks in Technology

Transcript

  1. @cameronjonesweb An Introduction to Plugin Development What We’re Gonna Build

    We will be building a plugin to customise the WordPress login screen with our own logo
  2. @cameronjonesweb An Introduction to Plugin Development About Me Cameron Jones

    Freelance WordPress developer Founder of Mongoose Marketplace @cameronjonesweb on all the things • Made my first website in 2006 with Microsoft Publisher • Started programming in 2008 with Flash Actionscript 2.0 to make flash games • Fell in love with WordPress in 2014 • Released my first plugin on WordPress.org in 2015 • Released my first premium plugin in 2019
  3. @cameronjonesweb An Introduction to Plugin Development What You Need To

    Know • What a plugin is • Where plugins are installed • A little bit of PHP
  4. @cameronjonesweb An Introduction to Plugin Development What You Need To

    Build A Plugin • A local development environment • A text editor
  5. @cameronjonesweb An Introduction to Plugin Development WordPress Hook System The

    WordPress hook system is how WordPress knows when to run your code There are two types of hooks • Actions • Filters
  6. @cameronjonesweb An Introduction to Plugin Development WordPress Hooks - Syntax

    & Parameters • Hook name • Callback • Priority • Arguments
  7. @cameronjonesweb An Introduction to Plugin Development WordPress Hooks - Actions

    Actions are like an event, allowing you to run your code when something specific occurs
  8. @cameronjonesweb An Introduction to Plugin Development WordPress Hooks - Filters

    Filters are like a sieve, allowing you to change data before it gets used
  9. @cameronjonesweb An Introduction to Plugin Development WordPress Hook System Pro

    Tips! • Add your own hooks to allow other developers to extend your plugin developer.wordpress.org/plugins/hooks/ custom-hooks
  10. @cameronjonesweb An Introduction to Plugin Development Building Our Plugin •

    Set up the file structure • Add the plugin file header • Write our code!
  11. @cameronjonesweb An Introduction to Plugin Development Set Up Our File

    Structure • Create a folder inside wp-content/plugins for our plugin • Create a PHP file in our folder • Create a CSS file in our folder • Copy our logo into the folder
  12. @cameronjonesweb An Introduction to Plugin Development Set Up Our File

    Structure Pro Tips! • Make the folder name as unique as possible to avoid conflicts with plugins on WordPress.org • Use the same name for the folder and the PHP file
  13. @cameronjonesweb An Introduction to Plugin Development Add The Plugin File

    Header The Plugin File Header provides WordPress with important information about our plugin. It is added to the main PHP file for the plugin.
  14. @cameronjonesweb An Introduction to Plugin Development Plugin File Header Pro

    Tips! • Your plugin will need to be licensed under the GPL v2 (or later) if you wish to distribute it
  15. @cameronjonesweb An Introduction to Plugin Development Load Our Custom Styles

    On The Login Page Pro Tips! • Make your function and variable names as unique as possible to avoid conflicts with other plugins and themes
  16. @cameronjonesweb An Introduction to Plugin Development Can I Release This

    On WordPress.org? Pro Tips! • Your plugin should adhere to the plugin guidelines developer.wordpress.org/plugins/ wordpress-org/detailed-plugin- guidelines • You will need to learn how to use SVN developer.wordpress.org/plugins/ wordpress-org/how-to-use-subversion
  17. @cameronjonesweb An Introduction to Plugin Development Can I Release This

    On WordPress.org? Pro Tips! • Adhere to the WordPress coding standards make.wordpress.org/core/handbook/best -practices/coding-standards • Make sure your plugin is translatable developer.wordpress.org/plugins/ internationalization/localization
  18. @cameronjonesweb An Introduction to Plugin Development Can I Release This

    On WordPress.org? Pro Tips! • Use nonces and capability checks when processing forms • Always escape and sanitise user input developer.wordpress.org/plugins/security
  19. @cameronjonesweb An Introduction to Plugin Development Links For demo code

    and slides visit: mongoosemarketplace.com/wcbne19