SlideShare une entreprise Scribd logo
1  sur  18
Let’s write a plugin
Stupid WordPress tricks Part 0.1A
WordCamp Pittsburgh 2016
Brian Layman
HTTP://EHERMITSINC.COM
http://slideshare.net/brianlayman
Introduction
• Brian Layman
• I work from home
• I spend all day on the computer
• All best my friends are online
• I don’t hang out at parties
• I spend my day in a cave like room
• Yes, I am an eHermit
http://eHermitsInc.com
My World
(This word cloud replaces one I made on my own back in 2008 in which I foolishly referenced
browser versions making it reach end of life when IE9 was no longer in beta. This cloud was
ripped and edited from http://swordstudios.net/wp-
content/themes/swordtheme/images/word-cloud.png with apologies to Jessie Friedman.
http://imgs.xkcd.com/comics/tech_support_cheat_sheet.png
Our
Dark
Secret
Before we start to play
• What is a plugin?
• What can plugins do?
• What do you need to know?
• “But I heard plugins make your site slow!”
• “But I heard that plugins make your site insecure!”
Plugin
• A Plugin is a group of php functions that can extend the functionality
present in a standard WordPress weblog. These functions may all be
defined in one php file, or may be spread among more than one file.
Usually, a plugin is a php file that can be uploaded to the "wp-
content/plugins" directory on your webserver, where you have installed
WordPress. Once you have uploaded the plugin file, you should be able to
"turn it on" or Enable it from the "Plugins" page in the administration
interface of your weblog. The WordPress source code contains hooks that
can be used by plugins.
• See also: Hack, Hacking
• Related articles: Plugins
http://codex.wordpress.org/Glossary
Hook
• Hooks are specified, by the developer, in Actions and Filters. Here is a (hopefully) complete
list of all existing Hooks within WordPress.
Because Hooks are required by Actions and Filter you may hear the phrase "Action Hooks"
and "Filter Hooks" used from time to time.
In technical and strict terms: a Hook is an event, i.e. event as understood by Observer pattern,
invoked by the do_action() orapply_filters() call that afterwards triggers all
the action or filter functions, previously hooked to that event
usingadd_action() or add_filter(), respectively.
•See also: Action, Filter
•Related articles: Hooks, Actions and Filters, Plugin API/Hooks
http://codex.wordpress.org/Glossary
Filter
In WordPress, a Filter is a function that is associated with an
existing Action by specifying any existing Hook.
Developers can create custom Filters using the Filter API to replace code
from an existing Action. This process is called "hooking".
Custom Filters differ from custom Actions because custom Actions allow you
to add or remove code from existing Actions. Whereas custom Filters allow
you to replace specific data (such as a variable) found within an existing
Action.
•See also: Action, Hook, Terminology Confusion
•Related articles: Filters, Filter Reference, add_filter()
http://codex.wordpress.org/Glossary
Action
• In WordPress; an Action is a PHP function that is executed at specific points throughout the
WordPress Core.
Developers can create a custom Action using the Action API to add or remove code from an
existing Action by specifying any existing Hook. This process is called "hooking".
For example: A developer may want to add code to the footer of a Theme. This could be
accomplished by writing new function, then Hooking it to the wp_footer Action.
Custom Actions differ from custom Filters because custom Actions allow you to add or
remove code from existing Actions. Whereas custom Filters allow you to replace specific data
(such as a variable) found within an existing Action.
•See also: Filter, Hook, Terminology Confusion
•Related articles: Actions, Action Reference, add_action()
•Forum posts: Filters vs. Actions Discussion and Explanation
http://codex.wordpress.org/Glossary
Ok – How are we doing?
Hello Dolly
Let’s Play
• We’re going to use the tools we have seen to create a plugin
• Let’s mess with Dolly’s head a little bit
• Using actions
• Using filters
• Including CSS
• Including Scripts
Brian did miraculous stuff you can’t see in
the downloaded slideshow
• Bet you wish you were at Pittsburgh’s first WordCamp
• Then you could have seen us do all the fun stuff we did
• We’re sorry you missed it
• Maybe you can make it next year..
• OK next slide…
Figuring out where you messed up
• http://codex.wordpress.org/Editing_wp-config.php
@ini_set( 'log_errors', On' );
@ini_set( 'error_log', '/home/example/php_error.log' );
@ini_set( 'display_errors', 'On' );
@ini_set( 'error_reporting', E_ALL );
define( 'WP_DEBUG', true );
define( 'WP_DEBUG_LOG', false );
define( 'WP_DEBUG_DISPLAY', true );
Doing things right
• Data Validation
• https://codex.wordpress.org/Data_Validation
• esc_attr, wp kses, esc_url
• Use $wpdb for database access
• get_var, get_row, insert, update, delete
• Use prepare for custom queries
• $wpdb->query( $wpdb->prepare(“select blah from foo where i= %d”, $myintvar )
Plugin Survival Kit
• http://wordpress.org/plugins/ - Even if your plugin exists, write it anyway
• http://codex.wordpress.org/ - Your guide to all things WordPress
• http://codex.wordpress.org/Writing_a_Plugin - A starting point
• http://codex.wordpress.org/Plugin_API/Action_Reference - Common actions
• http://codex.wordpress.org/Plugin_API/Filter_Reference - List of common Filters
• https://developer.wordpress.org/plugins/ - The Plugin Developer
handbook
Plugin Survival Kit
• http://wordpress.org/plugins/about/ - Describes how to release your plugin
• https://wordpress.org/plugins/about/readme.txt - The official readme standard
• https://wordpress.org/plugins/about/validator/ - Readme Validator
• https://wordpress.org/plugins/add/ - Submit your plugin to the repository
• https://wordpress.org/plugins/hello-dolly/ - Hello Dolly!
• Unofficial Tools
• http://sudarmuthu.com/wordpress/wp-readme/ - Readme Generator
• http://generatewp.com/ - Helps add Features
• http://wppb.io/ & http://wppb.me/ - Full set of starter files for a plugin
Brian Layman
http://eHermitsinc.com
http://thecodecave.com
http://www.slideshare.net/brianlayman
http://twitter.com/brianlayman
@eHermits
My info->your phone, Txt “ehermit” to 50500
Brian@eHermitsInc.com

Contenu connexe

Tendances

Widening your JavaScript Application
Widening your JavaScript ApplicationWidening your JavaScript Application
Widening your JavaScript Application
Alex McPherson
 
Make your Rails console AWESOME (Ruby SG meetup 2016-03-29)
Make your Rails console AWESOME (Ruby SG meetup 2016-03-29)Make your Rails console AWESOME (Ruby SG meetup 2016-03-29)
Make your Rails console AWESOME (Ruby SG meetup 2016-03-29)
Bruce Li
 
Behavior Driven Development - How To Start with Behat
Behavior Driven Development - How To Start with BehatBehavior Driven Development - How To Start with Behat
Behavior Driven Development - How To Start with Behat
imoneytech
 
Making the Mobile Web Work
Making the Mobile Web WorkMaking the Mobile Web Work
Making the Mobile Web Work
Terry Ryan
 

Tendances (20)

Widening your JavaScript Application
Widening your JavaScript ApplicationWidening your JavaScript Application
Widening your JavaScript Application
 
What I wish I knew about Maven years ago
What I wish I knew about Maven years agoWhat I wish I knew about Maven years ago
What I wish I knew about Maven years ago
 
Empowering Non-Profits with WordPress
Empowering Non-Profits with WordPressEmpowering Non-Profits with WordPress
Empowering Non-Profits with WordPress
 
Multisite for the Masses
Multisite for the MassesMultisite for the Masses
Multisite for the Masses
 
Write Your First WordPress Plugin
Write Your First WordPress PluginWrite Your First WordPress Plugin
Write Your First WordPress Plugin
 
How I Learned to Stop Worrying and Backup WordPress
How I Learned to Stop Worrying and Backup WordPressHow I Learned to Stop Worrying and Backup WordPress
How I Learned to Stop Worrying and Backup WordPress
 
The Future Of WordPress Presentation
The Future Of WordPress PresentationThe Future Of WordPress Presentation
The Future Of WordPress Presentation
 
Make your Rails console AWESOME (Ruby SG meetup 2016-03-29)
Make your Rails console AWESOME (Ruby SG meetup 2016-03-29)Make your Rails console AWESOME (Ruby SG meetup 2016-03-29)
Make your Rails console AWESOME (Ruby SG meetup 2016-03-29)
 
Gherkin for test automation in agile
Gherkin for test automation in agileGherkin for test automation in agile
Gherkin for test automation in agile
 
A Universal Automation Framework based on BDD Cucumber and Ruby on Rails - Ph...
A Universal Automation Framework based on BDD Cucumber and Ruby on Rails - Ph...A Universal Automation Framework based on BDD Cucumber and Ruby on Rails - Ph...
A Universal Automation Framework based on BDD Cucumber and Ruby on Rails - Ph...
 
Git your Jekyll on - WebCamp Ljubljana 2015
Git your Jekyll on - WebCamp Ljubljana 2015Git your Jekyll on - WebCamp Ljubljana 2015
Git your Jekyll on - WebCamp Ljubljana 2015
 
Introduction to HTML5 & CSS3
Introduction to HTML5 & CSS3Introduction to HTML5 & CSS3
Introduction to HTML5 & CSS3
 
Behavior Driven Development - How To Start with Behat
Behavior Driven Development - How To Start with BehatBehavior Driven Development - How To Start with Behat
Behavior Driven Development - How To Start with Behat
 
Learning from the Best jQuery Plugins
Learning from the Best jQuery PluginsLearning from the Best jQuery Plugins
Learning from the Best jQuery Plugins
 
Using Firebug & YSlow
Using Firebug & YSlowUsing Firebug & YSlow
Using Firebug & YSlow
 
Making the Mobile Web Work
Making the Mobile Web WorkMaking the Mobile Web Work
Making the Mobile Web Work
 
Web Design Workflow and 
Tools that Make Life Easy
Web Design Workflow and 
Tools that Make Life EasyWeb Design Workflow and 
Tools that Make Life Easy
Web Design Workflow and 
Tools that Make Life Easy
 
Untangling spring week8
Untangling spring week8Untangling spring week8
Untangling spring week8
 
Intro to jQuery - Tulsa Ruby Group
Intro to jQuery - Tulsa Ruby GroupIntro to jQuery - Tulsa Ruby Group
Intro to jQuery - Tulsa Ruby Group
 
WordPress Plugins and Security
WordPress Plugins and SecurityWordPress Plugins and Security
WordPress Plugins and Security
 

En vedette

En vedette (16)

WordCamp Orange County 2016
WordCamp Orange County 2016WordCamp Orange County 2016
WordCamp Orange County 2016
 
Projektowanie i rozwój struktury serwisu z perspektywy SEO i UX
Projektowanie i rozwój struktury serwisu z perspektywy SEO i UXProjektowanie i rozwój struktury serwisu z perspektywy SEO i UX
Projektowanie i rozwój struktury serwisu z perspektywy SEO i UX
 
Cómo sacar el máximo provecho de tu proveedor de hosting
 Cómo sacar el máximo provecho de tu proveedor de hosting Cómo sacar el máximo provecho de tu proveedor de hosting
Cómo sacar el máximo provecho de tu proveedor de hosting
 
Чем может быть полезен стек ELK
Чем может быть полезен стек ELKЧем может быть полезен стек ELK
Чем может быть полезен стек ELK
 
Как опубликовать свою тему в директорию WordPress
Как опубликовать свою тему в директорию WordPressКак опубликовать свою тему в директорию WordPress
Как опубликовать свою тему в директорию WordPress
 
Learning by Doing: 10 Lessons in Pushing your WordPress Development Skills
Learning by Doing: 10 Lessons in Pushing your WordPress Development SkillsLearning by Doing: 10 Lessons in Pushing your WordPress Development Skills
Learning by Doing: 10 Lessons in Pushing your WordPress Development Skills
 
VVV. Сервер для WordPress-разработчика
 VVV. Сервер для WordPress-разработчика VVV. Сервер для WordPress-разработчика
VVV. Сервер для WordPress-разработчика
 
WordCamp Denmark 2016: How to get (more) involved with WordPress
WordCamp Denmark 2016: How to get (more) involved with WordPressWordCamp Denmark 2016: How to get (more) involved with WordPress
WordCamp Denmark 2016: How to get (more) involved with WordPress
 
WordPress en la Educación - WordCamp Bilbao - Fernando Tellado
WordPress en la Educación - WordCamp Bilbao - Fernando TelladoWordPress en la Educación - WordCamp Bilbao - Fernando Tellado
WordPress en la Educación - WordCamp Bilbao - Fernando Tellado
 
Cómo involucrarte (más) con WordPress - WordCamp Bilbao 2016
Cómo involucrarte (más) con WordPress - WordCamp Bilbao 2016Cómo involucrarte (más) con WordPress - WordCamp Bilbao 2016
Cómo involucrarte (más) con WordPress - WordCamp Bilbao 2016
 
Dockerize WordPress on Mac/Windows
Dockerize WordPress on Mac/WindowsDockerize WordPress on Mac/Windows
Dockerize WordPress on Mac/Windows
 
Пожиратели памяти в WordPress
Пожиратели памяти в WordPressПожиратели памяти в WordPress
Пожиратели памяти в WordPress
 
Podcast Presentation for WordCamp.
Podcast Presentation for WordCamp.Podcast Presentation for WordCamp.
Podcast Presentation for WordCamp.
 
What Really Matters in WordPress SEO
What Really Matters in WordPress SEOWhat Really Matters in WordPress SEO
What Really Matters in WordPress SEO
 
Friendlier, Safer WordPress Admin Areas
Friendlier, Safer WordPress Admin AreasFriendlier, Safer WordPress Admin Areas
Friendlier, Safer WordPress Admin Areas
 
Word press for lazy people
Word press for lazy peopleWord press for lazy people
Word press for lazy people
 

Similaire à 2016 WordCamp Pittsburgh - Let's Write a Plugin

Let’s write a plugin
Let’s write a pluginLet’s write a plugin
Let’s write a plugin
Brian Layman
 
Build a Web App with JavaScript and jQuery (5:18:17, Los Angeles)
Build a Web App with JavaScript and jQuery (5:18:17, Los Angeles)Build a Web App with JavaScript and jQuery (5:18:17, Los Angeles)
Build a Web App with JavaScript and jQuery (5:18:17, Los Angeles)
Thinkful
 
Java scriptwidgetdevelopmentjstanbul2012
Java scriptwidgetdevelopmentjstanbul2012Java scriptwidgetdevelopmentjstanbul2012
Java scriptwidgetdevelopmentjstanbul2012
Volkan Özçelik
 
Introduction to Web Components
Introduction to Web ComponentsIntroduction to Web Components
Introduction to Web Components
Rich Bradshaw
 
Web app with j query & javascript (5:4)
Web app with j query & javascript (5:4)Web app with j query & javascript (5:4)
Web app with j query & javascript (5:4)
Thinkful
 

Similaire à 2016 WordCamp Pittsburgh - Let's Write a Plugin (20)

Let’s write a plugin
Let’s write a pluginLet’s write a plugin
Let’s write a plugin
 
Intro to WordPress Plugins
Intro to WordPress PluginsIntro to WordPress Plugins
Intro to 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
 
Decoding Core Contribution - WordCamp San Diego 2013
Decoding Core Contribution - WordCamp San Diego 2013Decoding Core Contribution - WordCamp San Diego 2013
Decoding Core Contribution - WordCamp San Diego 2013
 
Build a Web App with JavaScript and jQuery (5:18:17, Los Angeles)
Build a Web App with JavaScript and jQuery (5:18:17, Los Angeles)Build a Web App with JavaScript and jQuery (5:18:17, Los Angeles)
Build a Web App with JavaScript and jQuery (5:18:17, Los Angeles)
 
External JavaScript Widget Development Best Practices (updated) (v.1.1)
External JavaScript Widget Development Best Practices (updated) (v.1.1) External JavaScript Widget Development Best Practices (updated) (v.1.1)
External JavaScript Widget Development Best Practices (updated) (v.1.1)
 
WordPress Security and Best Practices
WordPress Security and Best PracticesWordPress Security and Best Practices
WordPress Security and Best Practices
 
External JavaScript Widget Development Best Practices
External JavaScript Widget Development Best PracticesExternal JavaScript Widget Development Best Practices
External JavaScript Widget Development Best Practices
 
Java scriptwidgetdevelopmentjstanbul2012
Java scriptwidgetdevelopmentjstanbul2012Java scriptwidgetdevelopmentjstanbul2012
Java scriptwidgetdevelopmentjstanbul2012
 
Introduction to Web Components
Introduction to Web ComponentsIntroduction to Web Components
Introduction to Web Components
 
Web app with j query & javascript (5:4)
Web app with j query & javascript (5:4)Web app with j query & javascript (5:4)
Web app with j query & javascript (5:4)
 
WordPress plugin development
WordPress plugin developmentWordPress plugin development
WordPress plugin development
 
WordPress Hooks (Actions & Filters)
WordPress Hooks (Actions & Filters)WordPress Hooks (Actions & Filters)
WordPress Hooks (Actions & Filters)
 
APIs, now and in the future
APIs, now and in the futureAPIs, now and in the future
APIs, now and in the future
 
OSB15
OSB15OSB15
OSB15
 
Does This Theme Make My Website Look Fat? (Wordcamp SLC 2013)
Does This Theme Make My Website Look Fat? (Wordcamp SLC 2013)Does This Theme Make My Website Look Fat? (Wordcamp SLC 2013)
Does This Theme Make My Website Look Fat? (Wordcamp SLC 2013)
 
Introduction to WordPress Hooks 2016
Introduction to WordPress Hooks 2016Introduction to WordPress Hooks 2016
Introduction to WordPress Hooks 2016
 
Features, Exportables & You
Features, Exportables & YouFeatures, Exportables & You
Features, Exportables & You
 
orcreatehappyusers
orcreatehappyusersorcreatehappyusers
orcreatehappyusers
 
orcreatehappyusers
orcreatehappyusersorcreatehappyusers
orcreatehappyusers
 

Plus de Brian Layman

Neo word press meetup ehermits - how to keep your blog from being hacked 2012
Neo word press meetup   ehermits - how to keep your blog from being hacked 2012Neo word press meetup   ehermits - how to keep your blog from being hacked 2012
Neo word press meetup ehermits - how to keep your blog from being hacked 2012
Brian Layman
 

Plus de Brian Layman (10)

WordPress Rest API
WordPress Rest APIWordPress Rest API
WordPress Rest API
 
Drupal & Joomla & WordPress.. Oh My! A quick round-up of the three most popul...
Drupal & Joomla & WordPress.. Oh My! A quick round-up of the three most popul...Drupal & Joomla & WordPress.. Oh My! A quick round-up of the three most popul...
Drupal & Joomla & WordPress.. Oh My! A quick round-up of the three most popul...
 
Unfailing Love
Unfailing LoveUnfailing Love
Unfailing Love
 
Word Camp North Canton 2013 - Say what? Say that again in plain English...
Word Camp North Canton 2013 - Say what? Say that again in plain English...Word Camp North Canton 2013 - Say what? Say that again in plain English...
Word Camp North Canton 2013 - Say what? Say that again in plain English...
 
WordPress 3.5
WordPress 3.5WordPress 3.5
WordPress 3.5
 
Why WordPress?
Why WordPress?Why WordPress?
Why WordPress?
 
WordPress 3.8 Beta 1
WordPress 3.8 Beta 1WordPress 3.8 Beta 1
WordPress 3.8 Beta 1
 
Brethren - What Does It Mean?
Brethren - What Does It Mean?Brethren - What Does It Mean?
Brethren - What Does It Mean?
 
Neo word press meetup ehermits - how to keep your blog from being hacked 2012
Neo word press meetup   ehermits - how to keep your blog from being hacked 2012Neo word press meetup   ehermits - how to keep your blog from being hacked 2012
Neo word press meetup ehermits - how to keep your blog from being hacked 2012
 
Blog World 2010 - How to Keep Your Blog from Being Hacked
Blog World 2010 - How to Keep Your Blog from Being HackedBlog World 2010 - How to Keep Your Blog from Being Hacked
Blog World 2010 - How to Keep Your Blog from Being Hacked
 

Dernier

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
 

Dernier (20)

Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
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
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
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...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
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...
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
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
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
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
 
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
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 

2016 WordCamp Pittsburgh - Let's Write a Plugin

  • 1. Let’s write a plugin Stupid WordPress tricks Part 0.1A WordCamp Pittsburgh 2016 Brian Layman HTTP://EHERMITSINC.COM http://slideshare.net/brianlayman
  • 2. Introduction • Brian Layman • I work from home • I spend all day on the computer • All best my friends are online • I don’t hang out at parties • I spend my day in a cave like room • Yes, I am an eHermit http://eHermitsInc.com
  • 3. My World (This word cloud replaces one I made on my own back in 2008 in which I foolishly referenced browser versions making it reach end of life when IE9 was no longer in beta. This cloud was ripped and edited from http://swordstudios.net/wp- content/themes/swordtheme/images/word-cloud.png with apologies to Jessie Friedman.
  • 5. Before we start to play • What is a plugin? • What can plugins do? • What do you need to know? • “But I heard plugins make your site slow!” • “But I heard that plugins make your site insecure!”
  • 6. Plugin • A Plugin is a group of php functions that can extend the functionality present in a standard WordPress weblog. These functions may all be defined in one php file, or may be spread among more than one file. Usually, a plugin is a php file that can be uploaded to the "wp- content/plugins" directory on your webserver, where you have installed WordPress. Once you have uploaded the plugin file, you should be able to "turn it on" or Enable it from the "Plugins" page in the administration interface of your weblog. The WordPress source code contains hooks that can be used by plugins. • See also: Hack, Hacking • Related articles: Plugins http://codex.wordpress.org/Glossary
  • 7. Hook • Hooks are specified, by the developer, in Actions and Filters. Here is a (hopefully) complete list of all existing Hooks within WordPress. Because Hooks are required by Actions and Filter you may hear the phrase "Action Hooks" and "Filter Hooks" used from time to time. In technical and strict terms: a Hook is an event, i.e. event as understood by Observer pattern, invoked by the do_action() orapply_filters() call that afterwards triggers all the action or filter functions, previously hooked to that event usingadd_action() or add_filter(), respectively. •See also: Action, Filter •Related articles: Hooks, Actions and Filters, Plugin API/Hooks http://codex.wordpress.org/Glossary
  • 8. Filter In WordPress, a Filter is a function that is associated with an existing Action by specifying any existing Hook. Developers can create custom Filters using the Filter API to replace code from an existing Action. This process is called "hooking". Custom Filters differ from custom Actions because custom Actions allow you to add or remove code from existing Actions. Whereas custom Filters allow you to replace specific data (such as a variable) found within an existing Action. •See also: Action, Hook, Terminology Confusion •Related articles: Filters, Filter Reference, add_filter() http://codex.wordpress.org/Glossary
  • 9. Action • In WordPress; an Action is a PHP function that is executed at specific points throughout the WordPress Core. Developers can create a custom Action using the Action API to add or remove code from an existing Action by specifying any existing Hook. This process is called "hooking". For example: A developer may want to add code to the footer of a Theme. This could be accomplished by writing new function, then Hooking it to the wp_footer Action. Custom Actions differ from custom Filters because custom Actions allow you to add or remove code from existing Actions. Whereas custom Filters allow you to replace specific data (such as a variable) found within an existing Action. •See also: Filter, Hook, Terminology Confusion •Related articles: Actions, Action Reference, add_action() •Forum posts: Filters vs. Actions Discussion and Explanation http://codex.wordpress.org/Glossary
  • 10. Ok – How are we doing?
  • 12. Let’s Play • We’re going to use the tools we have seen to create a plugin • Let’s mess with Dolly’s head a little bit • Using actions • Using filters • Including CSS • Including Scripts
  • 13. Brian did miraculous stuff you can’t see in the downloaded slideshow • Bet you wish you were at Pittsburgh’s first WordCamp • Then you could have seen us do all the fun stuff we did • We’re sorry you missed it • Maybe you can make it next year.. • OK next slide…
  • 14. Figuring out where you messed up • http://codex.wordpress.org/Editing_wp-config.php @ini_set( 'log_errors', On' ); @ini_set( 'error_log', '/home/example/php_error.log' ); @ini_set( 'display_errors', 'On' ); @ini_set( 'error_reporting', E_ALL ); define( 'WP_DEBUG', true ); define( 'WP_DEBUG_LOG', false ); define( 'WP_DEBUG_DISPLAY', true );
  • 15. Doing things right • Data Validation • https://codex.wordpress.org/Data_Validation • esc_attr, wp kses, esc_url • Use $wpdb for database access • get_var, get_row, insert, update, delete • Use prepare for custom queries • $wpdb->query( $wpdb->prepare(“select blah from foo where i= %d”, $myintvar )
  • 16. Plugin Survival Kit • http://wordpress.org/plugins/ - Even if your plugin exists, write it anyway • http://codex.wordpress.org/ - Your guide to all things WordPress • http://codex.wordpress.org/Writing_a_Plugin - A starting point • http://codex.wordpress.org/Plugin_API/Action_Reference - Common actions • http://codex.wordpress.org/Plugin_API/Filter_Reference - List of common Filters • https://developer.wordpress.org/plugins/ - The Plugin Developer handbook
  • 17. Plugin Survival Kit • http://wordpress.org/plugins/about/ - Describes how to release your plugin • https://wordpress.org/plugins/about/readme.txt - The official readme standard • https://wordpress.org/plugins/about/validator/ - Readme Validator • https://wordpress.org/plugins/add/ - Submit your plugin to the repository • https://wordpress.org/plugins/hello-dolly/ - Hello Dolly! • Unofficial Tools • http://sudarmuthu.com/wordpress/wp-readme/ - Readme Generator • http://generatewp.com/ - Helps add Features • http://wppb.io/ & http://wppb.me/ - Full set of starter files for a plugin