GETTING STARTED WITH
WORDPRESS PLUGIN
DEVELOPMENT
Thomas Vitale | thomasvitale.com | @vitalethomas
WordCamp Torino 2017 | #wctrn
49 479PLUGINS on WordPress.org
2
WHAT IS A PLUGIN?
1. INTRODUCTION TO PLUGINS
4
CORE
THEMES PLUGINS
5
WHY PLUGINS?
1. INTRODUCTION TO PLUGINS
6
DON’T TOUCH THE
CORE!
HODOR
Game of Thrones @ Home Box Office, Inc. All Rights Reserved.
7
CORE
THEMES PLUGINS
8
THE PLUGIN
TERRITORY
1. INTRODUCTION TO PLUGINS
9
THE PLUGIN TERRITORY
FUNCTIONS.PHP PLUGINSVS
10
THE MAIN CONCEPTS
2. PLUGIN BASICS
11
THE MAIN CONCEPTS
THE STRUCTURE
12
/wp-content/plugins/
Icons made by Freepik from www.flaticon.com is licensed by CC 3.0 BY
myplugin.php
myplugin/
THE MAIN CONCEPTS
THE HEADER (MYPLUGIN.PHP)
/**
* Plugin Name: My Plugin
* Plugin URI:  https://thomasvitale.com/myplugin
* Description: The awesome plugin for WordPress Community.
* Version:     3.9.4
* Author:      Thomas Vitale
* Author URI:  https://thomasvitale.com
*/
13
PREFIXES!
PREFIXES EVERYWHERE!
BUZZ LIGHTYEAR
14
CORE
THEMES PLUGINS
15
THE MAIN CONCEPTS
WordPress Execution Flow
Custom Function
16
Icons from www.vecteezy.com
Core
THE MAIN CONCEPTS
WordPress Execution Flow
Custom Function
17
Icons from www.vecteezy.com
Core
EVENT-DRIVEN
PROGRAMMING
2. PLUGIN BASICS
18
HOOK
CORE
PLUGINS
23
Icons from www.vecteezy.com
CORE
THEMES PLUGINS
24
ACTIONS
2. PLUGIN BASICS
25
ACTIONS
bob
function tom_ciak() {
// Print a paragraph
echo “<p>And action!</p>”;
}
add_action( ‘bob’, ‘tom_ciak’ );
1
2
26
Icons from www.vecteezy.com
WordPress Execution Flow
ACTIONS
Function1
Function3
Function2
27
Icons from www.vecteezy.com
WordPress Execution Flow
bob
ACTIONS
wp_head
LoadCSS
28
Icons from www.vecteezy.com
WordPress Execution Flow
FILTERS
2. PLUGIN BASICS
29
FILTERS
jack
function tom_adv( $content ) {
return $content .“Follow me!”;
}
add_filter( ‘jack’, ‘tom_adv’ );
1
2
30
Icons from www.vecteezy.com
WordPress Flow Execution
FILTERS
the_content
Function
31
Icons from www.vecteezy.com
WordPress Flow Execution
AN EXAMPLE
3. DEMO
32
AN EXAMPLE
TOM BANNER
34
/wp-content/plugins/tom-banner/
Icons made by Freepik from www.flaticon.com is licensed by CC 3.0 BY
tom-banner.php
css/
style.css
AN EXAMPLE
HEADER (TOM-BANNER.PHP)
/**
* Plugin Name: Tom Banner
* Plugin URI: https://thomasvitale.com/tom-banner
* Description: Show a fixed banner to promote your brand new e-book.
* Version: 3.9.4
* Author: Thomas Vitale
* Author URI: https://thomasvitale.com
* License: GPL2
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
* Text Domain: thomas
* Domain Path: /languages
*/
35
AN EXAMPLE
CALLBACK FUNCTION (TOM-BANNER.PHP)
function tom_banner_html() { ?>
<div class="book-banner">
<p>
Do you like reading?
<a href="#">Download</a> my new free e-book!
</p>
</div>
<?php }
add_action( 'wp_footer', ‘tom_banner_html' );
36
AN EXAMPLE
STYLESHEET LOADING (TOM-BANNER.PHP)
function tom_load_css() {
wp_enqueue_style(
'tom-banner',
plugins_url( 'css/style.css', __FILE__ )
);
}
add_action( 'wp_enqueue_scripts', 'tom_load_css' );
37
AN EXAMPLE
STYLESHEET (CSS/STYLE.CSS)
.book-banner {
position: fixed;
bottom: 0;
left: 0;
width: 100%;
text-align: center;
padding: 10px 0;
background: #86151d;
min-height: 24px;
line-height: 24px;
color: #eeeeee;
font-size: 1em;
}
.book-banner p {
margin: 0;
padding: 5px;
}
.book-banner a {
color: #eee;
text-decoration: underline;
}
38
NEXT?
3. RESOURCES
39
RESOURCES
USEFUL RESOURCES
▸ WordPress Codex: https://codex.wordpress.org
▸ Plugin Developer Handbook: https://developer.wordpress.org/plugins/
▸ Professional WordPress: Design and Development, 3rd edition (Wrox), Brad
Williams, David Damstra, Hal Stern
▸ Smashing WordPress: Beyond the Blog, 4th edition, Thord Daniel Hedengren
▸ Codice sorgente plugin d’esempio e altre risorse: https://github.com/
ThomasVitale/GettingStartedWithWordPressPlugins
40
ARE YOU READY
TO DEVELOP YOUR
FIRST PLUGIN?
Thomas Vitale |@vitalethomas | #wctrn
41
This work is licensed under a Creative Commons Attribution 4.0 International License.

Getting Started With WordPress Plugin Development