SlideShare ist ein Scribd-Unternehmen logo
1 von 24
Developing WordPress Plugins Markku Seguerra http://rebelpixel.com
What is a WordPress plugin? ,[object Object]
Some plugins: - Akismet - WordPress Database Backup - WordPress.com Stats - wp-recent-links - Comment Hilite
What do you need to make a plugin? - a problem to solve - some PHP knowledge - some spare time - a test server with your test WordPress (XAMPP is good.)‏
Structure: Things to remember - A unique descriptive name - Naming: myplugin.php or /myplugin/ folder - Readme.txt format for wordpress.org/extend/plugins - Plugin home page - File headers (very important!)‏
Headers <?php /* Plugin Name:  Name Of The Plugin Plugin URI:  http://mypage.com/myplugin/ Description:  What does it do? Version:  1.0 Author:  Name Of The Plugin Author Author URI:  http://mypage.com/ */ ?>
Include your license details! ,[object Object]
Plugin Programming ,[object Object],The solution?
Plugin API - Enabled &quot;hooks&quot; - Extend functionality without editing the core code - Two categories: Actions and Filters
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');
Template Tags Plugins can also be used to generate special template tags that display custom content. - Recent comments - Top posts - Ad display
Storing Plugin Data - For large amount of data, create your own database table. - For fairly small and/or static data, use built-in WP &quot;Options&quot; capability. add_option($name, $value, $deprecated, $autoload); get_option($option); update_option($option_name, $newvalue);
Administration Menus & Pages - There are specific functions to add pages and menu items. add_menu_page(page_title, menu_title, access_level/capability, file, [function]); add_submenu_page();  add_options_page(); add_management_page(); add_theme_page();
Other things to consider - Internationalization - WordPress Coding Standards & inline documentation - Function prefixes to avoid name collision - When creating tables, use $wpdb->prefix - Minimize database writes. - Write secure code! (Use nonces, sanitize, etc.)‏ - Be aware of user roles and capabilities. - Stick to the WordPress API to avoid problems!
Sample plugin: Strip! <?php /* Plugin Name: Strip! Plugin URI: http://rebelpixel.com/ Description: Removes hyperlink tags from a given comment. Version: 0.1 Author: Markku Seguerra Author URI: http://rebelpixel.com/projects/strip/ */
/*  Copyright 2008  Markku Seguerra  (email : markku@gmail.com)‏ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
add_filter('comment_text', 'strip_comments_add_admin'); function strip_comments_add_admin($text)‏ { // add the strip button to the comment } add_filter('comment_text', 'strip_comments_add'); add_filter('get_comment_author_link', 'strip_comments_add'); function strip_comments_add($text)‏ { // mark the comment as stripped and displays // it without links }
add_action('wp_ajax_strip', 'do_strip'); function do_strip()‏ { // function to mark comment as stripped // triggered via ajax } add_action('wp_ajax_unstrip', 'do_unstrip'); function do_unstrip()‏ { // function to mark comment as stripped } function strip_selected_tags($text, $tags = array())‏ { // our filter function that removes links }
add_action('admin_head', 'strip_comments_head'); function strip_comments_head()‏ { // show the necessary css and ajax // functions used in the admin interface }
<script type=&quot;text/javascript&quot;> //<![CDATA[ function strip_now(cid) { jQuery.post(&quot;<?php echo get_option('siteurl'); ?>/wp-admin/admin-ajax.php&quot;, {action:&quot;strip&quot;, &quot;c&quot;:cid, &quot;cookie&quot;: encodeURIComponent(document.cookie)}, function(str)  { pn = '#p-' + cid; jQuery(pn).html(str); }); } function unstrip_now(cid) { jQuery.post(&quot;<?php echo get_option('siteurl'); ?>/wp-admin/admin-ajax.php&quot;, {action:&quot;unstrip&quot;, &quot;c&quot;:cid, &quot;cookie&quot;: encodeURIComponent(document.cookie)}, function(str)  { pn = '#p-' + cid; jQuery(pn).html(str); }); } //]]> </script>
Thank you! Markku Seguerra http://rebelpixel.com

Weitere ähnliche Inhalte

Was ist angesagt?

Week 7 introduction to theme development
Week 7   introduction to theme developmentWeek 7   introduction to theme development
Week 7 introduction to theme development
henri_makembe
 
Week 12 - Search Engine Optimization
Week 12 -  Search Engine OptimizationWeek 12 -  Search Engine Optimization
Week 12 - Search Engine Optimization
henri_makembe
 
Extending BuddyPress – WordCamp Milano 2011 [italian]
Extending BuddyPress – WordCamp Milano 2011 [italian]Extending BuddyPress – WordCamp Milano 2011 [italian]
Extending BuddyPress – WordCamp Milano 2011 [italian]
Francesco Laffi
 
Introduction to building joomla! components using FOF
Introduction to building joomla! components using FOFIntroduction to building joomla! components using FOF
Introduction to building joomla! components using FOF
Tim Plummer
 
WordPress Theming
WordPress ThemingWordPress Theming
WordPress Theming
codebangla
 

Was ist angesagt? (20)

Week 7 introduction to theme development
Week 7   introduction to theme developmentWeek 7   introduction to theme development
Week 7 introduction to theme development
 
Creating Your First WordPress Plugin
Creating Your First WordPress PluginCreating Your First WordPress Plugin
Creating Your First WordPress Plugin
 
45 Minute Drupal Site
45 Minute Drupal Site45 Minute Drupal Site
45 Minute Drupal Site
 
Week 12 - Search Engine Optimization
Week 12 -  Search Engine OptimizationWeek 12 -  Search Engine Optimization
Week 12 - Search Engine Optimization
 
CSI: WordPress -- Getting Into the Guts
CSI: WordPress -- Getting Into the GutsCSI: WordPress -- Getting Into the Guts
CSI: WordPress -- Getting Into the Guts
 
Develop advance joomla! MVC Component for version 3
Develop advance joomla! MVC Component for version 3Develop advance joomla! MVC Component for version 3
Develop advance joomla! MVC Component for version 3
 
Introduction to WordPress Plugin Development, WordCamp North Canton, 2015
Introduction to WordPress Plugin Development, WordCamp North Canton, 2015Introduction to WordPress Plugin Development, WordCamp North Canton, 2015
Introduction to WordPress Plugin Development, WordCamp North Canton, 2015
 
The Future Of WordPress Presentation
The Future Of WordPress PresentationThe Future Of WordPress Presentation
The Future Of WordPress Presentation
 
WordCamp Finland 2015 - WordPress Security
WordCamp Finland 2015 - WordPress SecurityWordCamp Finland 2015 - WordPress Security
WordCamp Finland 2015 - WordPress Security
 
Extending BuddyPress – WordCamp Milano 2011 [italian]
Extending BuddyPress – WordCamp Milano 2011 [italian]Extending BuddyPress – WordCamp Milano 2011 [italian]
Extending BuddyPress – WordCamp Milano 2011 [italian]
 
How to develope plugin in wordpress: 6 simple steps.
How to develope plugin in wordpress: 6 simple steps.How to develope plugin in wordpress: 6 simple steps.
How to develope plugin in wordpress: 6 simple steps.
 
WordPress Theme & Plugin i18n & L10n
WordPress Theme & Plugin i18n & L10nWordPress Theme & Plugin i18n & L10n
WordPress Theme & Plugin i18n & L10n
 
Introduction to building joomla! components using FOF
Introduction to building joomla! components using FOFIntroduction to building joomla! components using FOF
Introduction to building joomla! components using FOF
 
WordPress Theming
WordPress ThemingWordPress Theming
WordPress Theming
 
Hardening WordPress - SAScon Manchester 2013 (WordPress Security)
Hardening WordPress - SAScon Manchester 2013 (WordPress Security)Hardening WordPress - SAScon Manchester 2013 (WordPress Security)
Hardening WordPress - SAScon Manchester 2013 (WordPress Security)
 
WordPress Theme Development
 WordPress Theme Development WordPress Theme Development
WordPress Theme Development
 
Developing new feature in Joomla - Joomladay UK 2016
Developing new feature in Joomla - Joomladay UK 2016Developing new feature in Joomla - Joomladay UK 2016
Developing new feature in Joomla - Joomladay UK 2016
 
How to create a joomla component from scratch
How to create a joomla component from scratchHow to create a joomla component from scratch
How to create a joomla component from scratch
 
Top 20 WordPress Plugins You've Never Heard Of
Top 20 WordPress Plugins You've Never Heard OfTop 20 WordPress Plugins You've Never Heard Of
Top 20 WordPress Plugins You've Never Heard Of
 
Top 20 word press plugins you've never heard of
Top 20 word press plugins you've never heard ofTop 20 word press plugins you've never heard of
Top 20 word press plugins you've never heard of
 

Andere mochten auch

WordPress Plugins
WordPress PluginsWordPress Plugins
WordPress Plugins
randyhoyt
 
Creating and Maintaining WordPress Plugins
Creating and Maintaining WordPress PluginsCreating and Maintaining WordPress Plugins
Creating and Maintaining WordPress Plugins
Mark Jaquith
 

Andere mochten auch (15)

WordPress Plugins For Website Development
WordPress Plugins For Website DevelopmentWordPress Plugins For Website Development
WordPress Plugins For Website Development
 
WordPress Plugins (WordCamp Utah)
WordPress Plugins (WordCamp Utah)WordPress Plugins (WordCamp Utah)
WordPress Plugins (WordCamp Utah)
 
Intro to WordPress Plugins
Intro to WordPress PluginsIntro to WordPress Plugins
Intro to WordPress Plugins
 
Intro to WordPress Plugins
Intro to WordPress PluginsIntro to WordPress Plugins
Intro to WordPress Plugins
 
Introduction To Simple WordPress Plugin Development
Introduction To Simple WordPress Plugin DevelopmentIntroduction To Simple WordPress Plugin Development
Introduction To Simple WordPress Plugin Development
 
WordPress Plugins
WordPress PluginsWordPress Plugins
WordPress Plugins
 
WordPress Plugins and Security
WordPress Plugins and SecurityWordPress Plugins and Security
WordPress Plugins and Security
 
Developing Plugins For WordPress
Developing Plugins For WordPressDeveloping Plugins For WordPress
Developing Plugins For WordPress
 
Intro to WordPress Plugin Development
Intro to WordPress Plugin DevelopmentIntro to WordPress Plugin Development
Intro to WordPress Plugin Development
 
Wordpress Plugin Development Short Tutorial
Wordpress Plugin Development Short TutorialWordpress Plugin Development Short Tutorial
Wordpress Plugin Development Short Tutorial
 
Creating and Maintaining WordPress Plugins
Creating and Maintaining WordPress PluginsCreating and Maintaining WordPress Plugins
Creating and Maintaining WordPress Plugins
 
Introduction To WordPress
Introduction To WordPressIntroduction To WordPress
Introduction To WordPress
 
Developing WordPress Plugins : For Begineers
Developing WordPress Plugins :  For BegineersDeveloping WordPress Plugins :  For Begineers
Developing WordPress Plugins : For Begineers
 
An easy guide to Plugin Development
An easy guide to Plugin DevelopmentAn easy guide to Plugin Development
An easy guide to Plugin Development
 
Favorite WordPress Plugins 2016
Favorite WordPress Plugins 2016Favorite WordPress Plugins 2016
Favorite WordPress Plugins 2016
 

Ähnlich wie Developing WordPress Plugins

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
 
Write your first WordPress plugin
Write your first WordPress pluginWrite your first WordPress plugin
Write your first WordPress plugin
Anthony Montalbano
 
Plug in development
Plug in developmentPlug in development
Plug in development
Lucky Ali
 

Ähnlich wie Developing WordPress Plugins (20)

Getting Started With WordPress Development
Getting Started With WordPress DevelopmentGetting Started With WordPress Development
Getting Started With WordPress Development
 
WordPress Plugin Basics
WordPress Plugin BasicsWordPress Plugin Basics
WordPress Plugin Basics
 
Write Your First WordPress Plugin
Write Your First WordPress PluginWrite Your First WordPress Plugin
Write Your First WordPress Plugin
 
Getting started with WordPress development
Getting started with WordPress developmentGetting started with WordPress development
Getting started with WordPress development
 
Extending WordPress
Extending WordPressExtending WordPress
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
 
WordPress Plugin development
WordPress Plugin developmentWordPress Plugin development
WordPress Plugin development
 
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
 
Making the Most of Plug-ins - WordCamp Toronto 2008
Making the Most of Plug-ins - WordCamp Toronto 2008Making the Most of Plug-ins - WordCamp Toronto 2008
Making the Most of Plug-ins - WordCamp Toronto 2008
 
WordPress development paradigms, idiosyncrasies and other big words
WordPress development paradigms, idiosyncrasies and other big wordsWordPress development paradigms, idiosyncrasies and other big words
WordPress development paradigms, idiosyncrasies and other big words
 
Write your first WordPress plugin
Write your first WordPress pluginWrite your first WordPress plugin
Write your first WordPress plugin
 
How To Write a WordPress Plugin
How To Write a WordPress PluginHow To Write a WordPress Plugin
How To Write a WordPress Plugin
 
Plug in development
Plug in developmentPlug in development
Plug in development
 
Wordpress Meetup 2 23 10
Wordpress Meetup 2 23 10Wordpress Meetup 2 23 10
Wordpress Meetup 2 23 10
 
5 年後還是新手 - WordPress Plugin 開發大冒險 - GOTY
5 年後還是新手 - WordPress Plugin 開發大冒險 - GOTY5 年後還是新手 - WordPress Plugin 開發大冒險 - GOTY
5 年後還是新手 - WordPress Plugin 開發大冒險 - GOTY
 
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
 
Philip Arthur Moore: Best Practices — On Breaking and Fixing WordPress Themes
Philip Arthur Moore: Best Practices — On Breaking and Fixing WordPress ThemesPhilip Arthur Moore: Best Practices — On Breaking and Fixing WordPress Themes
Philip Arthur Moore: Best Practices — On Breaking and Fixing WordPress Themes
 
Wordpress development: A Modern Approach
Wordpress development:  A Modern ApproachWordpress development:  A Modern Approach
Wordpress development: A Modern Approach
 
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
 
Internet Librarian Slides
Internet Librarian SlidesInternet Librarian Slides
Internet Librarian Slides
 

Kürzlich hochgeladen

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 
+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@
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 

Kürzlich hochgeladen (20)

Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
+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...
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 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
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
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...
 

Developing WordPress Plugins

  • 1. Developing WordPress Plugins Markku Seguerra http://rebelpixel.com
  • 2.
  • 3. Some plugins: - Akismet - WordPress Database Backup - WordPress.com Stats - wp-recent-links - Comment Hilite
  • 4. What do you need to make a plugin? - a problem to solve - some PHP knowledge - some spare time - a test server with your test WordPress (XAMPP is good.)‏
  • 5. Structure: Things to remember - A unique descriptive name - Naming: myplugin.php or /myplugin/ folder - Readme.txt format for wordpress.org/extend/plugins - Plugin home page - File headers (very important!)‏
  • 6. Headers <?php /* Plugin Name: Name Of The Plugin Plugin URI: http://mypage.com/myplugin/ Description: What does it do? Version: 1.0 Author: Name Of The Plugin Author Author URI: http://mypage.com/ */ ?>
  • 7.
  • 8.
  • 9. Plugin API - Enabled &quot;hooks&quot; - Extend functionality without editing the core code - Two categories: Actions and Filters
  • 10. 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] );
  • 11. Sample action: “wp_login” function notify_on_login()‏ { // your code here // email to admin, etc... } add_action('wp_login', 'notify_on_login');
  • 12. 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]);
  • 13. 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');
  • 14. Template Tags Plugins can also be used to generate special template tags that display custom content. - Recent comments - Top posts - Ad display
  • 15. Storing Plugin Data - For large amount of data, create your own database table. - For fairly small and/or static data, use built-in WP &quot;Options&quot; capability. add_option($name, $value, $deprecated, $autoload); get_option($option); update_option($option_name, $newvalue);
  • 16. Administration Menus & Pages - There are specific functions to add pages and menu items. add_menu_page(page_title, menu_title, access_level/capability, file, [function]); add_submenu_page(); add_options_page(); add_management_page(); add_theme_page();
  • 17. Other things to consider - Internationalization - WordPress Coding Standards & inline documentation - Function prefixes to avoid name collision - When creating tables, use $wpdb->prefix - Minimize database writes. - Write secure code! (Use nonces, sanitize, etc.)‏ - Be aware of user roles and capabilities. - Stick to the WordPress API to avoid problems!
  • 18. Sample plugin: Strip! <?php /* Plugin Name: Strip! Plugin URI: http://rebelpixel.com/ Description: Removes hyperlink tags from a given comment. Version: 0.1 Author: Markku Seguerra Author URI: http://rebelpixel.com/projects/strip/ */
  • 19. /* Copyright 2008 Markku Seguerra (email : markku@gmail.com)‏ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
  • 20. add_filter('comment_text', 'strip_comments_add_admin'); function strip_comments_add_admin($text)‏ { // add the strip button to the comment } add_filter('comment_text', 'strip_comments_add'); add_filter('get_comment_author_link', 'strip_comments_add'); function strip_comments_add($text)‏ { // mark the comment as stripped and displays // it without links }
  • 21. add_action('wp_ajax_strip', 'do_strip'); function do_strip()‏ { // function to mark comment as stripped // triggered via ajax } add_action('wp_ajax_unstrip', 'do_unstrip'); function do_unstrip()‏ { // function to mark comment as stripped } function strip_selected_tags($text, $tags = array())‏ { // our filter function that removes links }
  • 22. add_action('admin_head', 'strip_comments_head'); function strip_comments_head()‏ { // show the necessary css and ajax // functions used in the admin interface }
  • 23. <script type=&quot;text/javascript&quot;> //<![CDATA[ function strip_now(cid) { jQuery.post(&quot;<?php echo get_option('siteurl'); ?>/wp-admin/admin-ajax.php&quot;, {action:&quot;strip&quot;, &quot;c&quot;:cid, &quot;cookie&quot;: encodeURIComponent(document.cookie)}, function(str) { pn = '#p-' + cid; jQuery(pn).html(str); }); } function unstrip_now(cid) { jQuery.post(&quot;<?php echo get_option('siteurl'); ?>/wp-admin/admin-ajax.php&quot;, {action:&quot;unstrip&quot;, &quot;c&quot;:cid, &quot;cookie&quot;: encodeURIComponent(document.cookie)}, function(str) { pn = '#p-' + cid; jQuery(pn).html(str); }); } //]]> </script>
  • 24. Thank you! Markku Seguerra http://rebelpixel.com