SlideShare a Scribd company logo
Extending WordPress
A (developers) guide to building your
first WordPress plugin
@jon_bossenger http://jonathanbossenger.com
http://jonathanbossenger.com/extending-wordpress/
WHAT IS A WORDPRESS PLUGIN?
• One (or more) files (PHP, HTML, CSS, JavaScript)
• Extend WordPress functionality
• Simple – display 10 most recent posts
• Advanced – ticketing/eCommerce
PLUGIN BASICS
• Single file
• More complex structure
– PHP
– HTML/CSS (templates)
– JavaScript
• Plugin Header
PLUGIN HEADER
/*
Plugin Name: My Toolset
Plugin URI: http://URI_Of_Page_Describing_Plugin_and_Updates
Description: This describes my plugin in a short sentence
Version: 1.5
Author: John Smith
Author URI: http://URI_Of_The_Plugin_Author
License: GPL2
License URI: https://www.gnu.org/licenses/gpl-2.0.html
Domain Path: /languages
Text Domain: my-toolset
*/
TASK
• Create a lyrics plugin
• Copy and edit the plugin header from
hello.php to suit your requirements
• The plugin should be available in your plugins
list, in WP admin
PLUGIN BUILDING BLOCKS
• PHP Functions
• WordPress Action Hooks
• WordPress Filter Hooks
• Templates
• WordPress APIs (eg Options, Settings API)
• CSS/JavaScript (wp_enqueue_script)
It starts with an idea!
• At the end of each post, show a line from a
song
• Make the line stand out somehow
• (Bonus) Make it possible to edit the song lyrics
Hooks
• A pre existing event, that triggers either an
Action or a applies a Filter
• Action Hooks
• Filter Hooks
Actions
• A PHP function that is executed at a specific
point (hook)
• Create custom Actions or remove code from
an existing Action
Filters
• A function that is associated with an
existing Action
• Create custom Filters to replace code from an
existing Action.
• Filters allow you to replace or alter specific
data.
Examples
// Action Hook Example
function my_action_hook_function(){
// do some things here
}
add_action(‘some_action_hook’, ‘my_action_hook_function’);
// Filter Hook Example
function my_filter_hook_function($some_variable){
// do something with $some_variable here
return $some_variable;
}
add_filter( ‘some_filter_hook’, ‘my_filter_hook_function’ );
Building our plugin
• ‘the_content’ filter hook, hooks into the
‘the_content’ filter, which is used to filter the
content of the post after it is retrieved from
the database and before it is printed to the
screen.
• add_filter(‘the_content’, ‘my_filter_function’)
Building our plugin (cont)
• ‘wp_enqueue_scripts’ action hook, used to
enqueue assets that are used on the front end
(eg CSS, JavaScript)
• add_action(‘wp_enqueue_scripts’,
‘my_enqueue_scripts_function’);
• ‘wp_enqueue_style’ function, used to
enqueue a style sheet file (load it on the front
end)
• wp_enqueue_style( $handle, $source);
TASK
• Create a custom filter hook to add one line of text
AFTER the post content
• Create a custom action hook to load the custom CSS
file
• Add some CSS styling to your one line of text (you did
wrap it in a div or p, didn’t you?)
• TIP: $plugin_url = plugin_dir_url( __FILE__ );
TASK
• Using the hello.php ‘hello_dolly_get_lyric’
function, create a function that gets one line
from the song to use in your custom
‘the_content’ filter in the previous step
• It should randomly select a lyric to display
Saving Plugin Data
• Options API
• Custom Tables
• Settings API
• Adding menus
Building our plugin (cont)
• ‘admin_menu’ action hook – used to add
admin menu items
• ‘add_options_page’ function – Add sub menu
page to the Settings menu
• add_options_page( $page_title, $menu_title,
• $capability, $menu_slug, $function);
Building our plugin (cont)
• add_option($option, $value) – add an option
to the options table
• update_option($option, $value) – update an
option by its key
• get_option($option, $default) – get an option
value
Bonus Task
• Create a Settings menu item for your plugin
• Create a simple form that allows you to save
new song lyrics as a WP option
• Modify your plugin to use these saved lyrics
instead of ‘hello dolly’
Development Tips and Tricks
• WP_DEBUG
• DebugBar
• BugFu
• PHPStorm
Resources
• Google ;-)
• https://codex.wordpress.org
• https://developer.wordpress.org/
• https://developer.wordpress.org/plugins/
• https://codex.wordpress.org/WordPress_Coding_Standards
Resources (cont)
• https://webdevstudios.com/books/professional-
wordpress-plugin-development/
• https://github.com/hlashbrooke/WordPress-
Plugin-Template
• WPSA Slack
Questions ?

More Related Content

What's hot

Advanced WordPress Development Environments
Advanced WordPress Development EnvironmentsAdvanced WordPress Development Environments
Advanced WordPress Development Environments
Beau Lebens
 
Word press templates
Word press templatesWord press templates
Word press templates
Dan Phiffer
 
Sanjip Shah: Internationalizing and Localizing WordPress Themes
Sanjip Shah: Internationalizing and Localizing  WordPress ThemesSanjip Shah: Internationalizing and Localizing  WordPress Themes
Sanjip Shah: Internationalizing and Localizing WordPress Themes
wpnepal
 
WordPress Child Themes
WordPress Child ThemesWordPress Child Themes
WordPress Child Themes
rfair404
 
WordPress for Education PPT
WordPress for Education PPTWordPress for Education PPT
WordPress for Education PPT
jekkilekki
 

What's hot (20)

CSI: WordPress -- Getting Into the Guts
CSI: WordPress -- Getting Into the GutsCSI: WordPress -- Getting Into the Guts
CSI: WordPress -- Getting Into the Guts
 
Advanced WordPress Development Environments
Advanced WordPress Development EnvironmentsAdvanced WordPress Development Environments
Advanced WordPress Development Environments
 
Word press templates
Word press templatesWord press templates
Word press templates
 
WordPress as the Backbone(.js)
WordPress as the Backbone(.js)WordPress as the Backbone(.js)
WordPress as the Backbone(.js)
 
Theming 101
Theming 101Theming 101
Theming 101
 
I Can Haz More Performanz?
I Can Haz More Performanz?I Can Haz More Performanz?
I Can Haz More Performanz?
 
What is (not) WordPress
What is (not) WordPressWhat is (not) WordPress
What is (not) WordPress
 
Sanjip Shah: Internationalizing and Localizing WordPress Themes
Sanjip Shah: Internationalizing and Localizing  WordPress ThemesSanjip Shah: Internationalizing and Localizing  WordPress Themes
Sanjip Shah: Internationalizing and Localizing WordPress Themes
 
WordPress Theme Development: Part 2
WordPress Theme Development: Part 2WordPress Theme Development: Part 2
WordPress Theme Development: Part 2
 
Introduction to WordPress Theme Development
Introduction to WordPress Theme DevelopmentIntroduction to WordPress Theme Development
Introduction to WordPress Theme Development
 
Wordpress
WordpressWordpress
Wordpress
 
So You Want to Build and Release a Plugin? WordCamp Lancaster 2014
So You Want to Build and Release a Plugin? WordCamp Lancaster 2014So You Want to Build and Release a Plugin? WordCamp Lancaster 2014
So You Want to Build and Release a Plugin? WordCamp Lancaster 2014
 
Child Themes in WordPress
Child Themes in WordPressChild Themes in WordPress
Child Themes in WordPress
 
Put a little Backbone in your WordPress
Put a little Backbone in your WordPressPut a little Backbone in your WordPress
Put a little Backbone in your WordPress
 
Getting started with WordPress development
Getting started with WordPress developmentGetting started with WordPress development
Getting started with WordPress development
 
Extending Custom Post Types
Extending Custom Post Types Extending Custom Post Types
Extending Custom Post Types
 
Build a WordPress theme from HTML5 template @ Telerik
Build a WordPress theme from HTML5 template @ TelerikBuild a WordPress theme from HTML5 template @ Telerik
Build a WordPress theme from HTML5 template @ Telerik
 
WordPress Child Themes
WordPress Child ThemesWordPress Child Themes
WordPress Child Themes
 
WordPress for Education PPT
WordPress for Education PPTWordPress for Education PPT
WordPress for Education PPT
 
How to Create WordPress Website in Easy Steps
How to Create WordPress Website in Easy StepsHow to Create WordPress Website in Easy Steps
How to Create WordPress Website in Easy Steps
 

Similar to Extending WordPress

Step by step guide for creating wordpress plugin
Step by step guide for creating wordpress pluginStep by step guide for creating wordpress plugin
Step by step guide for creating wordpress plugin
Mainak Goswami
 
WordPress Custom Fields: Control your content presentation by breaking out of...
WordPress Custom Fields: Control your content presentation by breaking out of...WordPress Custom Fields: Control your content presentation by breaking out of...
WordPress Custom Fields: Control your content presentation by breaking out of...
Denise Williams
 
WordPress Plugin Development 201
WordPress Plugin Development 201WordPress Plugin Development 201
WordPress Plugin Development 201
ylefebvre
 
Write your first WordPress plugin
Write your first WordPress pluginWrite your first WordPress plugin
Write your first WordPress plugin
Anthony Montalbano
 

Similar to Extending WordPress (20)

Creating Your First WordPress Plugin
Creating Your First WordPress PluginCreating Your First WordPress Plugin
Creating Your First WordPress Plugin
 
Intro to WordPress Plugin Development
Intro to WordPress Plugin DevelopmentIntro to WordPress Plugin Development
Intro to WordPress Plugin Development
 
Step by step guide for creating wordpress plugin
Step by step guide for creating wordpress pluginStep by step guide for creating wordpress plugin
Step by step guide for creating wordpress plugin
 
Plugin development demystified 2017
Plugin development demystified 2017Plugin development demystified 2017
Plugin development demystified 2017
 
Faster WordPress Workflows
Faster WordPress WorkflowsFaster WordPress Workflows
Faster WordPress Workflows
 
WordPress Theming 101
WordPress Theming 101WordPress Theming 101
WordPress Theming 101
 
Write Your First WordPress Plugin
Write Your First WordPress PluginWrite Your First WordPress Plugin
Write Your First WordPress Plugin
 
Developing WordPress Plugins
Developing WordPress PluginsDeveloping WordPress Plugins
Developing WordPress Plugins
 
How to create your own WordPress plugin
How to create your own WordPress pluginHow to create your own WordPress plugin
How to create your own WordPress plugin
 
The Way to Theme Enlightenment
The Way to Theme EnlightenmentThe Way to Theme Enlightenment
The Way to Theme Enlightenment
 
From WordPress With Love
From WordPress With LoveFrom WordPress With Love
From WordPress With Love
 
Introduction to Plugin Programming, WordCamp Miami 2011
Introduction to Plugin Programming, WordCamp Miami 2011Introduction to Plugin Programming, WordCamp Miami 2011
Introduction to Plugin Programming, WordCamp Miami 2011
 
WordPress 2.5 Overview - Rich Media Institute
WordPress 2.5 Overview - Rich Media InstituteWordPress 2.5 Overview - Rich Media Institute
WordPress 2.5 Overview - Rich Media Institute
 
WordPress Custom Fields: Control your content presentation by breaking out of...
WordPress Custom Fields: Control your content presentation by breaking out of...WordPress Custom Fields: Control your content presentation by breaking out of...
WordPress Custom Fields: Control your content presentation by breaking out of...
 
Word press Plugins by WordPress Experts
Word press Plugins by WordPress ExpertsWord press Plugins by WordPress Experts
Word press Plugins by WordPress Experts
 
Intro to Plugin Development, Miami WordCamp, 2015
Intro to Plugin Development, Miami WordCamp, 2015Intro to Plugin Development, Miami WordCamp, 2015
Intro to Plugin Development, Miami WordCamp, 2015
 
WordPress Plugins
WordPress PluginsWordPress Plugins
WordPress Plugins
 
WordPress theme development from scratch : ICT MeetUp 2013 Nepal
WordPress theme development from scratch : ICT MeetUp 2013 NepalWordPress theme development from scratch : ICT MeetUp 2013 Nepal
WordPress theme development from scratch : ICT MeetUp 2013 Nepal
 
WordPress Plugin Development 201
WordPress Plugin Development 201WordPress Plugin Development 201
WordPress Plugin Development 201
 
Write your first WordPress plugin
Write your first WordPress pluginWrite your first WordPress plugin
Write your first WordPress plugin
 

More from Jonathan Bossenger

More from Jonathan Bossenger (20)

New WordPress Developer APIs The Interactivity API
New WordPress Developer APIs The Interactivity APINew WordPress Developer APIs The Interactivity API
New WordPress Developer APIs The Interactivity API
 
The WordPress HTML API
The WordPress HTML APIThe WordPress HTML API
The WordPress HTML API
 
The WordPress Create Block tool
The WordPress Create Block toolThe WordPress Create Block tool
The WordPress Create Block tool
 
PHP compatibility testing with PHPCompatibilityWP
PHP compatibility testing with PHPCompatibilityWPPHP compatibility testing with PHPCompatibilityWP
PHP compatibility testing with PHPCompatibilityWP
 
Common WordPress APIs_ Settings API
Common WordPress APIs_ Settings APICommon WordPress APIs_ Settings API
Common WordPress APIs_ Settings API
 
Common WordPress APIs - Options API
Common WordPress APIs - Options APICommon WordPress APIs - Options API
Common WordPress APIs - Options API
 
Common WordPress APIs_ HTTP API.pptx
Common WordPress APIs_ HTTP API.pptxCommon WordPress APIs_ HTTP API.pptx
Common WordPress APIs_ HTTP API.pptx
 
Common WordPress APIs: Metadata
Common WordPress APIs: MetadataCommon WordPress APIs: Metadata
Common WordPress APIs: Metadata
 
What’s new for developers_ (August 2023).pptx
What’s new for developers_ (August 2023).pptxWhat’s new for developers_ (August 2023).pptx
What’s new for developers_ (August 2023).pptx
 
Testing your plugins for PHP version compatibility
Testing your plugins for PHP version compatibilityTesting your plugins for PHP version compatibility
Testing your plugins for PHP version compatibility
 
Common WordPress APIs_ Global Variables
Common WordPress APIs_ Global VariablesCommon WordPress APIs_ Global Variables
Common WordPress APIs_ Global Variables
 
Common WordPress APIs_ Internationalization
Common WordPress APIs_ InternationalizationCommon WordPress APIs_ Internationalization
Common WordPress APIs_ Internationalization
 
Testing WordPress 6.3 - Developer edition
Testing WordPress 6.3 - Developer editionTesting WordPress 6.3 - Developer edition
Testing WordPress 6.3 - Developer edition
 
Common WordPress APIs: Responsive Images
Common WordPress APIs: Responsive ImagesCommon WordPress APIs: Responsive Images
Common WordPress APIs: Responsive Images
 
Common WordPress APIs - Dashboard Widgets
Common WordPress APIs - Dashboard WidgetsCommon WordPress APIs - Dashboard Widgets
Common WordPress APIs - Dashboard Widgets
 
Custom Tables in WordPress
Custom Tables in WordPressCustom Tables in WordPress
Custom Tables in WordPress
 
The WordPress Database
The WordPress DatabaseThe WordPress Database
The WordPress Database
 
WordPress Coding Standards
WordPress Coding StandardsWordPress Coding Standards
WordPress Coding Standards
 
Managing a WordPress Multisite Network
Managing a WordPress Multisite NetworkManaging a WordPress Multisite Network
Managing a WordPress Multisite Network
 
Debugging in WordPress
Debugging in WordPressDebugging in WordPress
Debugging in WordPress
 

Recently uploaded

Article writing on excessive use of internet.pptx
Article writing on excessive use of internet.pptxArticle writing on excessive use of internet.pptx
Article writing on excessive use of internet.pptx
abhinandnam9997
 
一比一原版UTS毕业证悉尼科技大学毕业证成绩单如何办理
一比一原版UTS毕业证悉尼科技大学毕业证成绩单如何办理一比一原版UTS毕业证悉尼科技大学毕业证成绩单如何办理
一比一原版UTS毕业证悉尼科技大学毕业证成绩单如何办理
aagad
 
audience research (emma) 1.pptxkkkkkkkkkkkkkkkkk
audience research (emma) 1.pptxkkkkkkkkkkkkkkkkkaudience research (emma) 1.pptxkkkkkkkkkkkkkkkkk
audience research (emma) 1.pptxkkkkkkkkkkkkkkkkk
lolsDocherty
 

Recently uploaded (13)

The+Prospects+of+E-Commerce+in+China.pptx
The+Prospects+of+E-Commerce+in+China.pptxThe+Prospects+of+E-Commerce+in+China.pptx
The+Prospects+of+E-Commerce+in+China.pptx
 
Article writing on excessive use of internet.pptx
Article writing on excessive use of internet.pptxArticle writing on excessive use of internet.pptx
Article writing on excessive use of internet.pptx
 
Bug Bounty Blueprint : A Beginner's Guide
Bug Bounty Blueprint : A Beginner's GuideBug Bounty Blueprint : A Beginner's Guide
Bug Bounty Blueprint : A Beginner's Guide
 
The AI Powered Organization-Intro to AI-LAN.pdf
The AI Powered Organization-Intro to AI-LAN.pdfThe AI Powered Organization-Intro to AI-LAN.pdf
The AI Powered Organization-Intro to AI-LAN.pdf
 
How Do I Begin the Linksys Velop Setup Process?
How Do I Begin the Linksys Velop Setup Process?How Do I Begin the Linksys Velop Setup Process?
How Do I Begin the Linksys Velop Setup Process?
 
The Use of AI in Indonesia Election 2024: A Case Study
The Use of AI in Indonesia Election 2024: A Case StudyThe Use of AI in Indonesia Election 2024: A Case Study
The Use of AI in Indonesia Election 2024: A Case Study
 
一比一原版UTS毕业证悉尼科技大学毕业证成绩单如何办理
一比一原版UTS毕业证悉尼科技大学毕业证成绩单如何办理一比一原版UTS毕业证悉尼科技大学毕业证成绩单如何办理
一比一原版UTS毕业证悉尼科技大学毕业证成绩单如何办理
 
ER(Entity Relationship) Diagram for online shopping - TAE
ER(Entity Relationship) Diagram for online shopping - TAEER(Entity Relationship) Diagram for online shopping - TAE
ER(Entity Relationship) Diagram for online shopping - TAE
 
The Best AI Powered Software - Intellivid AI Studio
The Best AI Powered Software - Intellivid AI StudioThe Best AI Powered Software - Intellivid AI Studio
The Best AI Powered Software - Intellivid AI Studio
 
Pvtaan Social media marketing proposal.pdf
Pvtaan Social media marketing proposal.pdfPvtaan Social media marketing proposal.pdf
Pvtaan Social media marketing proposal.pdf
 
Case study on merger of Vodafone and Idea (VI).pptx
Case study on merger of Vodafone and Idea (VI).pptxCase study on merger of Vodafone and Idea (VI).pptx
Case study on merger of Vodafone and Idea (VI).pptx
 
audience research (emma) 1.pptxkkkkkkkkkkkkkkkkk
audience research (emma) 1.pptxkkkkkkkkkkkkkkkkkaudience research (emma) 1.pptxkkkkkkkkkkkkkkkkk
audience research (emma) 1.pptxkkkkkkkkkkkkkkkkk
 
Multi-cluster Kubernetes Networking- Patterns, Projects and Guidelines
Multi-cluster Kubernetes Networking- Patterns, Projects and GuidelinesMulti-cluster Kubernetes Networking- Patterns, Projects and Guidelines
Multi-cluster Kubernetes Networking- Patterns, Projects and Guidelines
 

Extending WordPress

  • 1. Extending WordPress A (developers) guide to building your first WordPress plugin @jon_bossenger http://jonathanbossenger.com http://jonathanbossenger.com/extending-wordpress/
  • 2. WHAT IS A WORDPRESS PLUGIN? • One (or more) files (PHP, HTML, CSS, JavaScript) • Extend WordPress functionality • Simple – display 10 most recent posts • Advanced – ticketing/eCommerce
  • 3. PLUGIN BASICS • Single file • More complex structure – PHP – HTML/CSS (templates) – JavaScript • Plugin Header
  • 4. PLUGIN HEADER /* Plugin Name: My Toolset Plugin URI: http://URI_Of_Page_Describing_Plugin_and_Updates Description: This describes my plugin in a short sentence Version: 1.5 Author: John Smith Author URI: http://URI_Of_The_Plugin_Author License: GPL2 License URI: https://www.gnu.org/licenses/gpl-2.0.html Domain Path: /languages Text Domain: my-toolset */
  • 5. TASK • Create a lyrics plugin • Copy and edit the plugin header from hello.php to suit your requirements • The plugin should be available in your plugins list, in WP admin
  • 6. PLUGIN BUILDING BLOCKS • PHP Functions • WordPress Action Hooks • WordPress Filter Hooks • Templates • WordPress APIs (eg Options, Settings API) • CSS/JavaScript (wp_enqueue_script)
  • 7. It starts with an idea! • At the end of each post, show a line from a song • Make the line stand out somehow • (Bonus) Make it possible to edit the song lyrics
  • 8. Hooks • A pre existing event, that triggers either an Action or a applies a Filter • Action Hooks • Filter Hooks
  • 9. Actions • A PHP function that is executed at a specific point (hook) • Create custom Actions or remove code from an existing Action
  • 10. Filters • A function that is associated with an existing Action • Create custom Filters to replace code from an existing Action. • Filters allow you to replace or alter specific data.
  • 11. Examples // Action Hook Example function my_action_hook_function(){ // do some things here } add_action(‘some_action_hook’, ‘my_action_hook_function’); // Filter Hook Example function my_filter_hook_function($some_variable){ // do something with $some_variable here return $some_variable; } add_filter( ‘some_filter_hook’, ‘my_filter_hook_function’ );
  • 12. Building our plugin • ‘the_content’ filter hook, hooks into the ‘the_content’ filter, which is used to filter the content of the post after it is retrieved from the database and before it is printed to the screen. • add_filter(‘the_content’, ‘my_filter_function’)
  • 13. Building our plugin (cont) • ‘wp_enqueue_scripts’ action hook, used to enqueue assets that are used on the front end (eg CSS, JavaScript) • add_action(‘wp_enqueue_scripts’, ‘my_enqueue_scripts_function’); • ‘wp_enqueue_style’ function, used to enqueue a style sheet file (load it on the front end) • wp_enqueue_style( $handle, $source);
  • 14. TASK • Create a custom filter hook to add one line of text AFTER the post content • Create a custom action hook to load the custom CSS file • Add some CSS styling to your one line of text (you did wrap it in a div or p, didn’t you?) • TIP: $plugin_url = plugin_dir_url( __FILE__ );
  • 15. TASK • Using the hello.php ‘hello_dolly_get_lyric’ function, create a function that gets one line from the song to use in your custom ‘the_content’ filter in the previous step • It should randomly select a lyric to display
  • 16. Saving Plugin Data • Options API • Custom Tables • Settings API • Adding menus
  • 17. Building our plugin (cont) • ‘admin_menu’ action hook – used to add admin menu items • ‘add_options_page’ function – Add sub menu page to the Settings menu • add_options_page( $page_title, $menu_title, • $capability, $menu_slug, $function);
  • 18. Building our plugin (cont) • add_option($option, $value) – add an option to the options table • update_option($option, $value) – update an option by its key • get_option($option, $default) – get an option value
  • 19. Bonus Task • Create a Settings menu item for your plugin • Create a simple form that allows you to save new song lyrics as a WP option • Modify your plugin to use these saved lyrics instead of ‘hello dolly’
  • 20. Development Tips and Tricks • WP_DEBUG • DebugBar • BugFu • PHPStorm
  • 21. Resources • Google ;-) • https://codex.wordpress.org • https://developer.wordpress.org/ • https://developer.wordpress.org/plugins/ • https://codex.wordpress.org/WordPress_Coding_Standards
  • 22. Resources (cont) • https://webdevstudios.com/books/professional- wordpress-plugin-development/ • https://github.com/hlashbrooke/WordPress- Plugin-Template • WPSA Slack