SlideShare a Scribd company logo
1 of 54
Download to read offline
Developing WordPress
Plugins : For Beginners
M A Hossain Tonu
http://mahtonu.wordpress.com
Who am i ?
• Tech Blogger http://mahtonu.wordpress.com
• Hacker, Community activist, FOSS advocate
• Works atVantage Labs Dhaka
• @mahtonu
• Authored the title “PHP Application
Development with NetBeans: Beginner's
Guide” http://link.packtpub.com/6HaElo
Inside scoop!
• What is Plugin?
• Popular Plugins
• Creating a Plugin from Scratch
• Sanity Practices and a Plugin foundation
• Activation, Deactivation Hooks
• Hooks: Actions and Filters
• Shortcodes
• Resources for Plugin Developer
WordPress Plugins allow easy modification,
customization, and enhancement to a
WordPress website.
Instead of changing the core programming
of WordPress, you can add functionality
with WordPress Plugins.
Book’s Definition
A WordPress Plugin is a program, or a set of
one or more functions, written in the PHP
scripting language, that adds a specific set of
features or services to the WordPress
weblog, which can be seamlessly integrated
with the weblog using access points and
methods provided by the WordPress Plugin
Application Program Interface (API).
Popular WP Plugins
http://wordpress.org/plugins/browse/popular/
Popular WP Plugins
Popular WP Plugins
Popular WP Plugins
Popular WP Plugins
Popular WP Plugins
Popular WP Plugins
Popular WP Plugins
Popular WP Plugins
Popular WP Plugins
There are huge number of
Plugins out there waiting for you
Plugins Repo Today!
25,276 plugins, 464,157,564 downloads, and
counting
Lets Create A Plugin
from Scratch...
How about a Photo
Slider?
Prerequisites?
• HTML/CSS
• PHP
• JavaScript / JQuery
• MySQL
Prerequisites? designer?
• HTML/CSS
• PHP
• JavaScript / JQuery
• MySQL
Frond-end of the Slider Plugin
Plugins Directory
Dashboard | Plugins
Things to remember
• A unique descriptive name
• Naming: my-plugin.php or /my-plugin/ folder
• Readme.txt format for wordpress.org/
extend/plugins
• Plugin home page
• File headers (very important!)
Creating Plugin File
A single PHP file
my-slider/my-slider.php
inside your plugin folder
Creating Plugin File
<?php
/*
Plugin Name: My Slider
Plugin URI: http://mahtonu.wordpress.com/
Description: Slider Plugin for WordPress
Version: 1.0
Author: M A Hossain Tonu
Author URI: http://mahtonu.wordpress.com/
License: GPLv2 or later
*/
?>
Creating Plugin File
Parameters
• Plugin URI – is used to let users know about the details of the plugin and
available download options.This isn’t mandatory and you can keep it blank, if
you don’t have an intention of making the plugin publicly available.
• Description – is used to provide a summary of functionality of the plugin.
• Version – is used to define the version and you can use any numbering
format as you wish. Plugins need be upgraded with each WordPress version
upgrade.Therefore it’s good to have proper version numbering even though
it’s not mandatory.
• Author and Author URI – is used to provide details about the
developer of the plugin.
• License – is used to define the conditions for using this plugin.We can
include standard licence such as GPL2 or just mention something we prefer
such as Free to use.
Plugin Api
• Enabled “hooks”
• Extend functionality without editing the
core code
• Two categories:Actions and Filters
WordPress Plugin Activation
and Deactivation Hooks
register_activation_hook()
register_deactivation_hook()
WordPress Plugin Activation
and Deactivation Hooks
function my_slider_activation() {
}
register_activation_hook(__FILE__,
'my_slider_activation');
function my_slider_deactivation() {
}
register_deactivation_hook(__FILE__,
'my_slider_deactivation');
Why Do We Use Activation/
Deactivation Hooks
• Create custom database tables on
activation to store data and remove tables
on deactivation.
• Create custom options for plugins and
activation and reset in deactivation.
• Validate other dependent plugin on
activation.
• Any other necessary task you need to
execute in activation.
Actions
Specific points in the WordPress code that
can be used to trigger plugin-specified events
and functions
add_action( 'hook_name', 'your_function_name',
[priority], [accepted_args] );
Sample action: “wp_login”
function notify_on_login() {
// your code here
// email to admin, etc...
}
add_action('wp_login', 'notify_on_login');
Filters
Functions that modify text, lists and various
types of information that are used and
produced by WordPress
add_filter('hook_name', 'your_filter_function',
[priority], [accepted_args]);
Sample filter: “the_content”
function add_rss_invite() {
// output to screen the link to RSS feed
// if 1st time visitor
}
add_filter('the_content', 'add_rss_invite');
Understanding the
Components of Slider
• jQuery library
• jQuery plugin file
• Initialization code
• CSS files used for plugin
• HTML or Images used for sliding
My Slider Directory Structure
Sample HTML
<html>
<head>
<script type='text/javascript' src='http://code.jquery.com/
jquery-latest.min.js'></script>
<script type='text/javascript' src='jquery.slides.min.js'></
script>
<script type='text/javascript'>
jQuery(function() {
jQuery('#slides').slidesjs({
width: 940,
height: 528,
navigation: false
});
});
</script>
</head>
<body>
</body>
</html>
Including Scripts : my-slider.php
<?php
add_action('wp_enqueue_scripts', 'my_scripts');
function my_scripts() {
wp_enqueue_script('jquery');
wp_register_script('slidesjs_core', plugins_url('js/
jquery.slides.min.js', __FILE__), array("jquery"));
wp_enqueue_script('slidesjs_core');
wp_register_script('slidesjs_init', plugins_url('js/
slidesjs.initialize.js', __FILE__));
wp_enqueue_script('slidesjs_init');
}
?>
Including Scripts : my-slider.php
• wp_enqueue_script is used to include the script file to the
HTML document
• wp_register_script is used to register a script file into
WordPress
• plugins_url function will provide the URL of the plugin
folder.
• SlidesJs core plugin file is named as jquery.slides.min.js
• The initialization part of the library inside
slidesjs.initialize.js jQuery(function() {
jQuery('#slides').slidesjs({
width: 940,
height: 528,
navigation: false
});
});
Including Styles : my-slider.php
add_action('wp_enqueue_scripts', 'my_styles');
function my_styles() {
wp_register_style('slidesjs_example', plugins_url('css/
example.css', __FILE__));
wp_enqueue_style('slidesjs_example');
wp_register_style('slidesjs_fonts', plugins_url('css/font-
awesome.min.css', __FILE__));
wp_enqueue_style('slidesjs_fonts');
}
Assigning Content to Slider
Using Shortcode: my-slider.php
add_shortcode("my_shortcode", "my_shortcode_function");
function my_shortcode_function() {
return "<h1>Hello Shortcodes</h1>";
}
Assigning Content to Slider
Using Shortcode
Integrating Slider Using
Shortcode: my-slider.php
add_shortcode("my_slider", "my_display_slider");
function my_display_slider() {
$plugins_url = plugins_url();
echo '<div class="container">
<div id="slides">
<img src="'.plugins_url( 'img/example-slide-1.jpg' , __FILE__ ).'" />
<img src="'.plugins_url( 'img/example-slide-2.jpg' , __FILE__ ).'" />
<img src="'.plugins_url( 'img/example-slide-3.jpg' , __FILE__ ).'" />
<img src="'.plugins_url( 'img/example-slide-4.jpg' , __FILE__ ).'" />
<a href="#" class="slidesjs-previous slidesjs-navigation"><i
class="icon-chevron-left icon-large"></i></a>
<a href="#" class="slidesjs-next slidesjs-navigation"><i class="icon-
chevron-right icon-large"></i></a>
</div>
</div>';
}
Finally!
shortcode = [my_slider]
Take away
• Plugin Creation Basics
• Sample Plugin Created from Scratch
• Best Practices
• Hooks:Activation & Deactivation,
Actions & Filters
• Shortcodes: Usage and Creation
What should be my next
Steps?
• Template Tags
• Data Saving, Add/Update Options
• Internationalization
• Submit Plugin to Repository
• Admin:Add to admin menu, Control
settings from Dashboard
• Earn Money!!!
Questions?
Resources
• Writing a Plugin: http://codex.wordpress.org/Writing_a_Plugin
• Articles and resources for Plugin developers: https://
codex.wordpress.org/Plugin_Resources
• basics about how WordPress Plugins are written: https://
codex.wordpress.org/Plugins#Default_Plugins
• Plugin API http://codex.wordpress.org/Plugin_API
• Plugin API / Action Reference http://codex.wordpress.org/
Plugin_API/Action_Reference
• Plugin API / Filter Reference http://codex.wordpress.org/
More Resources
• http://www.slideshare.net/rebelpixel/developing-wordpress-
plugins-presentation
• http://www.slideshare.net/chzigkol/wordpress-plugin-
development-short-tutorial-presentation
• http://www.slideshare.net/gamerz/developing-plugins-for-
wordpress
• http://www.slideshare.net/williamsba/create-your-first-wordpress-
plugin
Shameless Promotion
http://link.packtpub.com/6HaElo

More Related Content

What's hot

Debugging tools in web browsers
Debugging tools in web browsersDebugging tools in web browsers
Debugging tools in web browsers
Sarah Dutkiewicz
 
Javascript Frameworks
Javascript FrameworksJavascript Frameworks
Javascript Frameworks
Mitesh Gandhi
 

What's hot (20)

Micro frontend: The microservices puzzle extended to frontend
Micro frontend: The microservices puzzle  extended to frontendMicro frontend: The microservices puzzle  extended to frontend
Micro frontend: The microservices puzzle extended to frontend
 
Anatomy of a Progressive Web App
Anatomy of a Progressive Web AppAnatomy of a Progressive Web App
Anatomy of a Progressive Web App
 
Debugging tools in web browsers
Debugging tools in web browsersDebugging tools in web browsers
Debugging tools in web browsers
 
Decoupled Architecture and WordPress
Decoupled Architecture and WordPressDecoupled Architecture and WordPress
Decoupled Architecture and WordPress
 
Revolutionize Your Workflow with ChatOps
Revolutionize Your Workflow with ChatOpsRevolutionize Your Workflow with ChatOps
Revolutionize Your Workflow with ChatOps
 
jQuery Conference Boston 2011 CouchApps
jQuery Conference Boston 2011 CouchAppsjQuery Conference Boston 2011 CouchApps
jQuery Conference Boston 2011 CouchApps
 
Web application framework
Web application frameworkWeb application framework
Web application framework
 
Creating MVC Application with backbone js
Creating MVC Application with backbone jsCreating MVC Application with backbone js
Creating MVC Application with backbone js
 
Shift Remote FRONTEND: Micro Frontend Architecture: A Look Into the Future - ...
Shift Remote FRONTEND: Micro Frontend Architecture: A Look Into the Future - ...Shift Remote FRONTEND: Micro Frontend Architecture: A Look Into the Future - ...
Shift Remote FRONTEND: Micro Frontend Architecture: A Look Into the Future - ...
 
Introduction, Examples - Firebase
Introduction, Examples - Firebase Introduction, Examples - Firebase
Introduction, Examples - Firebase
 
JMP103 : Extending Your App Arsenal With OpenSocial
JMP103 : Extending Your App Arsenal With OpenSocialJMP103 : Extending Your App Arsenal With OpenSocial
JMP103 : Extending Your App Arsenal With OpenSocial
 
Give Your Java Apps “The Boot” With Spring Boot And Cloud Foundry
Give Your Java Apps “The Boot” With Spring Boot And Cloud FoundryGive Your Java Apps “The Boot” With Spring Boot And Cloud Foundry
Give Your Java Apps “The Boot” With Spring Boot And Cloud Foundry
 
Guidance on how to develop a progressive web app using react native!
Guidance on how to develop a progressive web app using react native!Guidance on how to develop a progressive web app using react native!
Guidance on how to develop a progressive web app using react native!
 
Javascript Frameworks
Javascript FrameworksJavascript Frameworks
Javascript Frameworks
 
Secured Development
Secured DevelopmentSecured Development
Secured Development
 
Untying the Knots of Web Dev with Internet Explorer
Untying the Knots of Web Dev with Internet Explorer Untying the Knots of Web Dev with Internet Explorer
Untying the Knots of Web Dev with Internet Explorer
 
Introducing Mobile Cross Promotion Framework
Introducing Mobile Cross Promotion FrameworkIntroducing Mobile Cross Promotion Framework
Introducing Mobile Cross Promotion Framework
 
Angular js
Angular jsAngular js
Angular js
 
PWA basics for developers
PWA basics for developersPWA basics for developers
PWA basics for developers
 
Aeternity Blockchain - Ecosystem & Devtools [2019]
Aeternity Blockchain - Ecosystem & Devtools [2019]Aeternity Blockchain - Ecosystem & Devtools [2019]
Aeternity Blockchain - Ecosystem & Devtools [2019]
 

Viewers also liked

Viewers also liked (9)

Software Engineering in PHP
Software Engineering in PHPSoftware Engineering in PHP
Software Engineering in PHP
 
Google Map API
Google Map APIGoogle Map API
Google Map API
 
Google Maps API
Google Maps APIGoogle Maps API
Google Maps API
 
Google Maps API
Google Maps APIGoogle Maps API
Google Maps API
 
Secure my ng-app
Secure my ng-appSecure my ng-app
Secure my ng-app
 
Before you jump into Angular
Before you jump into AngularBefore you jump into Angular
Before you jump into Angular
 
Succeeding with FOSS!
Succeeding with FOSS!Succeeding with FOSS!
Succeeding with FOSS!
 
Understanding meteor
Understanding meteorUnderstanding meteor
Understanding meteor
 
JavaScript Wash - Story of UI Development
JavaScript Wash - Story of UI DevelopmentJavaScript Wash - Story of UI Development
JavaScript Wash - Story of UI Development
 

Similar to Developing WordPress Plugins : For Begineers

Write your first WordPress plugin
Write your first WordPress pluginWrite your first WordPress plugin
Write your first WordPress plugin
Anthony Montalbano
 
In Act Developers Platform
In Act Developers PlatformIn Act Developers Platform
In Act Developers Platform
Eris Ristemena
 
WordPress Plugin Development
WordPress Plugin DevelopmentWordPress Plugin Development
WordPress Plugin Development
Adam Englander
 
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
 

Similar to Developing WordPress Plugins : For Begineers (20)

Plugin development demystified 2017
Plugin development demystified 2017Plugin development demystified 2017
Plugin development demystified 2017
 
Getting Started with WordPress Plugin Development
Getting Started with WordPress Plugin DevelopmentGetting Started with WordPress Plugin Development
Getting Started with WordPress Plugin Development
 
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
 
Write your first WordPress plugin
Write your first WordPress pluginWrite your first WordPress plugin
Write your first WordPress plugin
 
WordPress plugins
WordPress pluginsWordPress plugins
WordPress plugins
 
WordCamp Greenville 2018 - Beware the Dark Side, or an Intro to Development
WordCamp Greenville 2018 - Beware the Dark Side, or an Intro to DevelopmentWordCamp Greenville 2018 - Beware the Dark Side, or an Intro to Development
WordCamp Greenville 2018 - Beware the Dark Side, or an Intro to Development
 
Extending WordPress - a guide to building your first plugin
Extending WordPress -  a guide to building your first pluginExtending WordPress -  a guide to building your first plugin
Extending WordPress - a guide to building your first plugin
 
How to Create a Custom WordPress Plugin
How to Create a Custom WordPress PluginHow to Create a Custom WordPress Plugin
How to Create a Custom WordPress Plugin
 
Faster WordPress Workflows
Faster WordPress WorkflowsFaster WordPress Workflows
Faster WordPress Workflows
 
In Act Developers Platform
In Act Developers PlatformIn Act Developers Platform
In Act Developers Platform
 
WordPress Plugin Development
WordPress Plugin DevelopmentWordPress Plugin Development
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
 
Extending MadCap Flare HTML5 Targets with jQuery - MadWorld 2016, Scott DeLoa...
Extending MadCap Flare HTML5 Targets with jQuery - MadWorld 2016, Scott DeLoa...Extending MadCap Flare HTML5 Targets with jQuery - MadWorld 2016, Scott DeLoa...
Extending MadCap Flare HTML5 Targets with jQuery - MadWorld 2016, Scott DeLoa...
 
Rebrand WordPress Admin
Rebrand WordPress AdminRebrand WordPress Admin
Rebrand WordPress Admin
 
Getting started with WordPress development
Getting started with WordPress developmentGetting started with WordPress development
Getting started with WordPress development
 
WordPress Plugin Development- Rich Media Institute Workshop
WordPress Plugin Development- Rich Media Institute WorkshopWordPress Plugin Development- Rich Media Institute Workshop
WordPress Plugin Development- Rich Media Institute Workshop
 
Office 365 Saturday (Sydney) - SharePoint framework – build integrated user e...
Office 365 Saturday (Sydney) - SharePoint framework – build integrated user e...Office 365 Saturday (Sydney) - SharePoint framework – build integrated user e...
Office 365 Saturday (Sydney) - SharePoint framework – build integrated user e...
 
WordPress Complete Tutorial
WordPress Complete TutorialWordPress Complete Tutorial
WordPress Complete Tutorial
 
WordCamp Asheville 2017 - So You Wanna Dev? Join the Team!
WordCamp Asheville 2017 - So You Wanna Dev? Join the Team!WordCamp Asheville 2017 - So You Wanna Dev? Join the Team!
WordCamp Asheville 2017 - So You Wanna Dev? Join the Team!
 

Recently uploaded

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Recently uploaded (20)

GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 

Developing WordPress Plugins : For Begineers

  • 1. Developing WordPress Plugins : For Beginners M A Hossain Tonu http://mahtonu.wordpress.com
  • 2. Who am i ? • Tech Blogger http://mahtonu.wordpress.com • Hacker, Community activist, FOSS advocate • Works atVantage Labs Dhaka • @mahtonu • Authored the title “PHP Application Development with NetBeans: Beginner's Guide” http://link.packtpub.com/6HaElo
  • 3. Inside scoop! • What is Plugin? • Popular Plugins • Creating a Plugin from Scratch • Sanity Practices and a Plugin foundation • Activation, Deactivation Hooks • Hooks: Actions and Filters • Shortcodes • Resources for Plugin Developer
  • 4. WordPress Plugins allow easy modification, customization, and enhancement to a WordPress website.
  • 5. Instead of changing the core programming of WordPress, you can add functionality with WordPress Plugins.
  • 6. Book’s Definition A WordPress Plugin is a program, or a set of one or more functions, written in the PHP scripting language, that adds a specific set of features or services to the WordPress weblog, which can be seamlessly integrated with the weblog using access points and methods provided by the WordPress Plugin Application Program Interface (API).
  • 17. There are huge number of Plugins out there waiting for you
  • 18. Plugins Repo Today! 25,276 plugins, 464,157,564 downloads, and counting
  • 19. Lets Create A Plugin from Scratch...
  • 20. How about a Photo Slider?
  • 21. Prerequisites? • HTML/CSS • PHP • JavaScript / JQuery • MySQL
  • 22. Prerequisites? designer? • HTML/CSS • PHP • JavaScript / JQuery • MySQL
  • 23. Frond-end of the Slider Plugin
  • 26. Things to remember • A unique descriptive name • Naming: my-plugin.php or /my-plugin/ folder • Readme.txt format for wordpress.org/ extend/plugins • Plugin home page • File headers (very important!)
  • 27. Creating Plugin File A single PHP file my-slider/my-slider.php inside your plugin folder
  • 28. Creating Plugin File <?php /* Plugin Name: My Slider Plugin URI: http://mahtonu.wordpress.com/ Description: Slider Plugin for WordPress Version: 1.0 Author: M A Hossain Tonu Author URI: http://mahtonu.wordpress.com/ License: GPLv2 or later */ ?>
  • 30. Parameters • Plugin URI – is used to let users know about the details of the plugin and available download options.This isn’t mandatory and you can keep it blank, if you don’t have an intention of making the plugin publicly available. • Description – is used to provide a summary of functionality of the plugin. • Version – is used to define the version and you can use any numbering format as you wish. Plugins need be upgraded with each WordPress version upgrade.Therefore it’s good to have proper version numbering even though it’s not mandatory. • Author and Author URI – is used to provide details about the developer of the plugin. • License – is used to define the conditions for using this plugin.We can include standard licence such as GPL2 or just mention something we prefer such as Free to use.
  • 31. Plugin Api • Enabled “hooks” • Extend functionality without editing the core code • Two categories:Actions and Filters
  • 32. WordPress Plugin Activation and Deactivation Hooks register_activation_hook() register_deactivation_hook()
  • 33. WordPress Plugin Activation and Deactivation Hooks function my_slider_activation() { } register_activation_hook(__FILE__, 'my_slider_activation'); function my_slider_deactivation() { } register_deactivation_hook(__FILE__, 'my_slider_deactivation');
  • 34. Why Do We Use Activation/ Deactivation Hooks • Create custom database tables on activation to store data and remove tables on deactivation. • Create custom options for plugins and activation and reset in deactivation. • Validate other dependent plugin on activation. • Any other necessary task you need to execute in activation.
  • 35. Actions Specific points in the WordPress code that can be used to trigger plugin-specified events and functions add_action( 'hook_name', 'your_function_name', [priority], [accepted_args] );
  • 36. Sample action: “wp_login” function notify_on_login() { // your code here // email to admin, etc... } add_action('wp_login', 'notify_on_login');
  • 37. Filters Functions that modify text, lists and various types of information that are used and produced by WordPress add_filter('hook_name', 'your_filter_function', [priority], [accepted_args]);
  • 38. Sample filter: “the_content” function add_rss_invite() { // output to screen the link to RSS feed // if 1st time visitor } add_filter('the_content', 'add_rss_invite');
  • 39. Understanding the Components of Slider • jQuery library • jQuery plugin file • Initialization code • CSS files used for plugin • HTML or Images used for sliding
  • 40. My Slider Directory Structure
  • 41. Sample HTML <html> <head> <script type='text/javascript' src='http://code.jquery.com/ jquery-latest.min.js'></script> <script type='text/javascript' src='jquery.slides.min.js'></ script> <script type='text/javascript'> jQuery(function() { jQuery('#slides').slidesjs({ width: 940, height: 528, navigation: false }); }); </script> </head> <body> </body> </html>
  • 42. Including Scripts : my-slider.php <?php add_action('wp_enqueue_scripts', 'my_scripts'); function my_scripts() { wp_enqueue_script('jquery'); wp_register_script('slidesjs_core', plugins_url('js/ jquery.slides.min.js', __FILE__), array("jquery")); wp_enqueue_script('slidesjs_core'); wp_register_script('slidesjs_init', plugins_url('js/ slidesjs.initialize.js', __FILE__)); wp_enqueue_script('slidesjs_init'); } ?>
  • 43. Including Scripts : my-slider.php • wp_enqueue_script is used to include the script file to the HTML document • wp_register_script is used to register a script file into WordPress • plugins_url function will provide the URL of the plugin folder. • SlidesJs core plugin file is named as jquery.slides.min.js • The initialization part of the library inside slidesjs.initialize.js jQuery(function() { jQuery('#slides').slidesjs({ width: 940, height: 528, navigation: false }); });
  • 44. Including Styles : my-slider.php add_action('wp_enqueue_scripts', 'my_styles'); function my_styles() { wp_register_style('slidesjs_example', plugins_url('css/ example.css', __FILE__)); wp_enqueue_style('slidesjs_example'); wp_register_style('slidesjs_fonts', plugins_url('css/font- awesome.min.css', __FILE__)); wp_enqueue_style('slidesjs_fonts'); }
  • 45. Assigning Content to Slider Using Shortcode: my-slider.php add_shortcode("my_shortcode", "my_shortcode_function"); function my_shortcode_function() { return "<h1>Hello Shortcodes</h1>"; }
  • 46. Assigning Content to Slider Using Shortcode
  • 47. Integrating Slider Using Shortcode: my-slider.php add_shortcode("my_slider", "my_display_slider"); function my_display_slider() { $plugins_url = plugins_url(); echo '<div class="container"> <div id="slides"> <img src="'.plugins_url( 'img/example-slide-1.jpg' , __FILE__ ).'" /> <img src="'.plugins_url( 'img/example-slide-2.jpg' , __FILE__ ).'" /> <img src="'.plugins_url( 'img/example-slide-3.jpg' , __FILE__ ).'" /> <img src="'.plugins_url( 'img/example-slide-4.jpg' , __FILE__ ).'" /> <a href="#" class="slidesjs-previous slidesjs-navigation"><i class="icon-chevron-left icon-large"></i></a> <a href="#" class="slidesjs-next slidesjs-navigation"><i class="icon- chevron-right icon-large"></i></a> </div> </div>'; }
  • 49. Take away • Plugin Creation Basics • Sample Plugin Created from Scratch • Best Practices • Hooks:Activation & Deactivation, Actions & Filters • Shortcodes: Usage and Creation
  • 50. What should be my next Steps? • Template Tags • Data Saving, Add/Update Options • Internationalization • Submit Plugin to Repository • Admin:Add to admin menu, Control settings from Dashboard • Earn Money!!!
  • 52. Resources • Writing a Plugin: http://codex.wordpress.org/Writing_a_Plugin • Articles and resources for Plugin developers: https:// codex.wordpress.org/Plugin_Resources • basics about how WordPress Plugins are written: https:// codex.wordpress.org/Plugins#Default_Plugins • Plugin API http://codex.wordpress.org/Plugin_API • Plugin API / Action Reference http://codex.wordpress.org/ Plugin_API/Action_Reference • Plugin API / Filter Reference http://codex.wordpress.org/
  • 53. More Resources • http://www.slideshare.net/rebelpixel/developing-wordpress- plugins-presentation • http://www.slideshare.net/chzigkol/wordpress-plugin- development-short-tutorial-presentation • http://www.slideshare.net/gamerz/developing-plugins-for- wordpress • http://www.slideshare.net/williamsba/create-your-first-wordpress- plugin