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

Developing Your First WordPress Plugin

Developing Your First WordPress Plugin

A session delivered at WordCamp Lagos 2019

Tunbosun

May 10, 2019
Tweet

More Decks by Tunbosun

Other Decks in Programming

Transcript

  1. ‣ What is a WordPress Plugin ‣ Hooks ‣ Actions

    ‣ Filters ‣ Let’s create a plugin ‣ Questions AGENDA
  2. WHAT IS A WORDPRESS PLUGIN? ‣ Plugins are packages of

    code that extend the core functionality of WordPress. ‣ WordPress plugins are made up of PHP code and other assets such as images, CSS, and JavaScript. https://developer.wordpress.org/plugins/intro/what-is-a-plugin
  3. PLUGIN HEADER At the top of every main plugin file

    is the plugin header comment. This is what tells WordPress that this is a plugin.
  4. HOOKS? WordPress hooks allow you to tap into WordPress at

    specific points to change how WordPress behaves without editing any core files. A hook allows you to add your own code or change what WordPress is doing or outputting by default. ‣ Actions ‣ Filters WordPress has two types of Hooks.
  5. WHAT ARE ACTIONS? Actions allows you to add data or

    change how WordPress operate. An action is always triggered at a specific time when WordPress is running.
  6. ‣ $hook - the action you want to hook into

    when it is run ‣ $function_to_add - the callback function which will be called when the action is run ‣ $priority - (int) the priority given to the callback function ‣ $accepted_args - (int) the number of arguments that will be passed to the callback function HOW TO HOOK INTO AN ACTION?
  7. Filters allow you to get and modify WordPress data before

    is is sent to the database or the browser. A filter allows you to modify content before it is displayed to the user. WHAT ARE FILTERS?
  8. ‣ $tag - the filter you want to target when

    it is run ‣ $function_to_add - the callback function which will be called when the filter is run ‣ $priority - (int) the priority given to the callback function ‣ $accepted_args - (int) the number of arguments that will be passed to the callback function HOW TO HOOK INTO A FILTER?
  9. ‣ A plugin can be a single file but it

    is always recommended to create a directory to hold your plugin file ‣ Always prefix your function names ‣ Sanitize all input data ‣ Enable debug mode when developing a plugin
 define( 'WP_DEBUG', true ); IMPORTANT NOTES
  10. RESOURCES WordPress Plugin Handbook https://developer.wordpress.org/plugins WordPress Code Reference https://developer.wordpress.org/reference WordPress

    Coding Standards https://make.wordpress.org/core/handbook/best-practices/coding-standards/ WordPress TV http://wordpress.tv/?s=plugins