Your SlideShare is downloading. ×
0
Developing WordPressPlugins : For BeginnersM A Hossain Tonuhttp://mahtonu.wordpress.com
Who am i ?• Tech Blogger http://mahtonu.wordpress.com• Hacker, Community activist, FOSS advocate• Works atVantage Labs Dha...
Inside scoop!• What is Plugin?• Popular Plugins• Creating a Plugin from Scratch• Sanity Practices and a Plugin foundation•...
WordPress Plugins allow easy modification,customization, and enhancement to aWordPress website.
Instead of changing the core programmingof WordPress, you can add functionalitywith WordPress Plugins.
Book’s DefinitionA WordPress Plugin is a program, or a set ofone or more functions, written in the PHPscripting language, t...
Popular WP Pluginshttp://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 ofPlugins out there waiting for you
Plugins Repo Today!25,276 plugins, 464,157,564 downloads, andcounting
Lets Create A Pluginfrom Scratch...
How about a PhotoSlider?
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 wordpres...
Creating Plugin FileA single PHP filemy-slider/my-slider.phpinside your plugin folder
Creating Plugin File<?php/*Plugin Name: My SliderPlugin URI: http://mahtonu.wordpress.com/Description: Slider Plugin for W...
Creating Plugin File
Parameters• Plugin URI – is used to let users know about the details of the plugin andavailable download options.This isn’...
Plugin Api• Enabled “hooks”• Extend functionality without editing thecore code• Two categories:Actions and Filters
WordPress Plugin Activationand Deactivation Hooksregister_activation_hook()register_deactivation_hook()
WordPress Plugin Activationand Deactivation Hooksfunction my_slider_activation() {}register_activation_hook(__FILE__,my_sl...
Why Do We Use Activation/Deactivation Hooks• Create custom database tables onactivation to store data and remove tableson ...
ActionsSpecific points in the WordPress code thatcan be used to trigger plugin-specified eventsand functionsadd_action( hook...
Sample action: “wp_login”function notify_on_login() {// your code here// email to admin, etc...}add_action(wp_login, notif...
FiltersFunctions that modify text, lists and varioustypes of information that are used andproduced by WordPressadd_filter(...
Sample filter: “the_content”function add_rss_invite() {// output to screen the link to RSS feed// if 1st time visitor}add_f...
Understanding theComponents of Slider• jQuery library• jQuery plugin file• Initialization code• CSS files used for plugin• H...
My Slider Directory Structure
Sample HTML<html><head><script type=text/javascript src=http://code.jquery.com/jquery-latest.min.js></script><script type=...
Including Scripts : my-slider.php<?phpadd_action(wp_enqueue_scripts, my_scripts);function my_scripts() {wp_enqueue_script(...
Including Scripts : my-slider.php• wp_enqueue_script is used to include the script file to theHTML document• wp_register_sc...
Including Styles : my-slider.phpadd_action(wp_enqueue_scripts, my_styles);function my_styles() {wp_register_style(slidesjs...
Assigning Content to SliderUsing Shortcode: my-slider.phpadd_shortcode("my_shortcode", "my_shortcode_function");function m...
Assigning Content to SliderUsing Shortcode
Integrating Slider UsingShortcode: my-slider.phpadd_shortcode("my_slider", "my_display_slider");function my_display_slider...
Finally!shortcode = [my_slider]
Take away• Plugin Creation Basics• Sample Plugin Created from Scratch• Best Practices• Hooks:Activation & Deactivation,Act...
What should be my nextSteps?• Template Tags• Data Saving, Add/Update Options• Internationalization• Submit Plugin to Repos...
Questions?
Resources• Writing a Plugin: http://codex.wordpress.org/Writing_a_Plugin• Articles and resources for Plugin developers: ht...
More Resources• http://www.slideshare.net/rebelpixel/developing-wordpress-plugins-presentation• http://www.slideshare.net/...
Shameless Promotionhttp://link.packtpub.com/6HaElo
Upcoming SlideShare
Loading in...5
×

Developing WordPress Plugins : For Begineers

2,836

Published on

Create A WordPress Plugin from Scratch.

Published in: Technology, Art & Photos
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
2,836
On Slideshare
0
From Embeds
0
Number of Embeds
9
Actions
Shares
0
Downloads
86
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

Transcript of "Developing WordPress Plugins : For Begineers"

  1. 1. Developing WordPressPlugins : For BeginnersM A Hossain Tonuhttp://mahtonu.wordpress.com
  2. 2. Who am i ?• Tech Blogger http://mahtonu.wordpress.com• Hacker, Community activist, FOSS advocate• Works atVantage Labs Dhaka• @mahtonu• Authored the title “PHP ApplicationDevelopment with NetBeans: BeginnersGuide” http://link.packtpub.com/6HaElo
  3. 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. 4. WordPress Plugins allow easy modification,customization, and enhancement to aWordPress website.
  5. 5. Instead of changing the core programmingof WordPress, you can add functionalitywith WordPress Plugins.
  6. 6. Book’s DefinitionA WordPress Plugin is a program, or a set ofone or more functions, written in the PHPscripting language, that adds a specific set offeatures or services to the WordPressweblog, which can be seamlessly integratedwith the weblog using access points andmethods provided by the WordPress PluginApplication Program Interface (API).
  7. 7. Popular WP Pluginshttp://wordpress.org/plugins/browse/popular/
  8. 8. Popular WP Plugins
  9. 9. Popular WP Plugins
  10. 10. Popular WP Plugins
  11. 11. Popular WP Plugins
  12. 12. Popular WP Plugins
  13. 13. Popular WP Plugins
  14. 14. Popular WP Plugins
  15. 15. Popular WP Plugins
  16. 16. Popular WP Plugins
  17. 17. There are huge number ofPlugins out there waiting for you
  18. 18. Plugins Repo Today!25,276 plugins, 464,157,564 downloads, andcounting
  19. 19. Lets Create A Pluginfrom Scratch...
  20. 20. How about a PhotoSlider?
  21. 21. Prerequisites?• HTML/CSS• PHP• JavaScript / JQuery• MySQL
  22. 22. Prerequisites? designer?• HTML/CSS• PHP• JavaScript / JQuery• MySQL
  23. 23. Frond-end of the Slider Plugin
  24. 24. Plugins Directory
  25. 25. Dashboard | Plugins
  26. 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. 27. Creating Plugin FileA single PHP filemy-slider/my-slider.phpinside your plugin folder
  28. 28. Creating Plugin File<?php/*Plugin Name: My SliderPlugin URI: http://mahtonu.wordpress.com/Description: Slider Plugin for WordPressVersion: 1.0Author: M A Hossain TonuAuthor URI: http://mahtonu.wordpress.com/License: GPLv2 or later*/?>
  29. 29. Creating Plugin File
  30. 30. Parameters• Plugin URI – is used to let users know about the details of the plugin andavailable download options.This isn’t mandatory and you can keep it blank, ifyou 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 numberingformat as you wish. Plugins need be upgraded with each WordPress versionupgrade.Therefore it’s good to have proper version numbering even thoughit’s not mandatory.• Author and Author URI – is used to provide details about thedeveloper of the plugin.• License – is used to define the conditions for using this plugin.We caninclude standard licence such as GPL2 or just mention something we prefersuch as Free to use.
  31. 31. Plugin Api• Enabled “hooks”• Extend functionality without editing thecore code• Two categories:Actions and Filters
  32. 32. WordPress Plugin Activationand Deactivation Hooksregister_activation_hook()register_deactivation_hook()
  33. 33. WordPress Plugin Activationand Deactivation Hooksfunction my_slider_activation() {}register_activation_hook(__FILE__,my_slider_activation);function my_slider_deactivation() {}register_deactivation_hook(__FILE__,my_slider_deactivation);
  34. 34. Why Do We Use Activation/Deactivation Hooks• Create custom database tables onactivation to store data and remove tableson deactivation.• Create custom options for plugins andactivation and reset in deactivation.• Validate other dependent plugin onactivation.• Any other necessary task you need toexecute in activation.
  35. 35. ActionsSpecific points in the WordPress code thatcan be used to trigger plugin-specified eventsand functionsadd_action( hook_name, your_function_name,[priority], [accepted_args] );
  36. 36. Sample action: “wp_login”function notify_on_login() {// your code here// email to admin, etc...}add_action(wp_login, notify_on_login);
  37. 37. FiltersFunctions that modify text, lists and varioustypes of information that are used andproduced by WordPressadd_filter(hook_name, your_filter_function,[priority], [accepted_args]);
  38. 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. 39. Understanding theComponents of Slider• jQuery library• jQuery plugin file• Initialization code• CSS files used for plugin• HTML or Images used for sliding
  40. 40. My Slider Directory Structure
  41. 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. 42. Including Scripts : my-slider.php<?phpadd_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. 43. Including Scripts : my-slider.php• wp_enqueue_script is used to include the script file to theHTML document• wp_register_script is used to register a script file intoWordPress• plugins_url function will provide the URL of the pluginfolder.• SlidesJs core plugin file is named as jquery.slides.min.js• The initialization part of the library insideslidesjs.initialize.js jQuery(function() {jQuery(#slides).slidesjs({width: 940,height: 528,navigation: false});});
  44. 44. Including Styles : my-slider.phpadd_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. 45. Assigning Content to SliderUsing Shortcode: my-slider.phpadd_shortcode("my_shortcode", "my_shortcode_function");function my_shortcode_function() {return "<h1>Hello Shortcodes</h1>";}
  46. 46. Assigning Content to SliderUsing Shortcode
  47. 47. Integrating Slider UsingShortcode: my-slider.phpadd_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"><iclass="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>;}
  48. 48. Finally!shortcode = [my_slider]
  49. 49. Take away• Plugin Creation Basics• Sample Plugin Created from Scratch• Best Practices• Hooks:Activation & Deactivation,Actions & Filters• Shortcodes: Usage and Creation
  50. 50. What should be my nextSteps?• Template Tags• Data Saving, Add/Update Options• Internationalization• Submit Plugin to Repository• Admin:Add to admin menu, Controlsettings from Dashboard• Earn Money!!!
  51. 51. Questions?
  52. 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. 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
  54. 54. Shameless Promotionhttp://link.packtpub.com/6HaElo
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×