Slide 1

Slide 1 text

WordCamp Lagos 2019 Tunbosun Ayinla Developing Your First WordPress Plugin

Slide 2

Slide 2 text

Tunbosun Ayinla Developer at Sandhills Development, LLC Lagos WordPress Meetup Group Co-organizer ABOUT ME

Slide 3

Slide 3 text

‣ What is a WordPress Plugin ‣ Hooks ‣ Actions ‣ Filters ‣ Let’s create a plugin ‣ Questions AGENDA

Slide 4

Slide 4 text

WHAT IS A WORDPRESS PLUGIN?

Slide 5

Slide 5 text

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

Slide 6

Slide 6 text

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.

Slide 7

Slide 7 text

PLUGIN HEADER SAMPLE

Slide 8

Slide 8 text

HOOKS

Slide 9

Slide 9 text

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.

Slide 10

Slide 10 text

ACTIONS

Slide 11

Slide 11 text

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.

Slide 12

Slide 12 text

‣ $hook ‣ $function_to_add ‣ $priority ‣ $accepted_args HOW TO HOOK INTO AN ACTION?

Slide 13

Slide 13 text

‣ $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?

Slide 14

Slide 14 text

AN EXAMPLE OF AN ACTION

Slide 15

Slide 15 text

FILTERS

Slide 16

Slide 16 text

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?

Slide 17

Slide 17 text

‣ $tag ‣ $function_to_add ‣ $priority ‣ $accepted_args HOW TO HOOK INTO A FILTER?

Slide 18

Slide 18 text

‣ $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?

Slide 19

Slide 19 text

AN EXAMPLE OF A FILTER

Slide 20

Slide 20 text

‣ 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

Slide 21

Slide 21 text

RESOURCES

Slide 22

Slide 22 text

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

Slide 23

Slide 23 text

QUESTIONS?

Slide 24

Slide 24 text

https://bosun.me @tubiz Thank You