SlideShare uma empresa Scribd logo
1 de 22
Baixar para ler offline
Best practices for
plugin development
Create a WordPress plugin from
scratch
Andrea Sciamanna
present
● Lead developer for WPML
● responsible and active
developer of the WPML
plugin and add-ons
past
● Web and desktop application
developer (mostly using .net
framework)
Agenda
● Quick introduction about:
a. code readability
b. documentation
c. patterns
● Some references
● Creating a WordPress plugin from scratch
● (time allowing) Introducing IDEs and OOP
Code readability
1. Use coding standards
a. Use WordPress PHP Coding Standards: http://goo.
gl/FTMm0a
b. Comment with PhpDOC: http://www.phpdoc.org
c. Don't repeat yourself (DRY): http://blog.codinghorror.
com/curlys-law-do-one-thing
d. Don’t go crazy trying to follow standards: just get used
to them.
References
● WordPress Codex: http://codex.wordpress.org
● Stack Overflow: http://stackoverflow.com
○ WordPress Development: http://wordpress.
stackexchange.com
● Google: seriously, do I need to tell you?
Create a WordPress
plugin from scratch
A “Fancy” plugin for your galleries
Integrate Fancybox in the standard WordPress
gallery.
Planned Functionalities
● Show images in a Fancybox/lightbox, rather
than opening them in a different page
● Do not interfere with the active theme
● Make it “SEO proof”
● Pseudo-Watermark images without modifying
them
● Allow some customization
Goals
● Learn how to:
○ enqueue scripts and styles
○ use actions and filters
○ use WordPress Settings API
● Learn best practices, of course!
● ...and the Fancybox plugin
Standard plugin structure
● Single file: unique file name (my-own-plugin.
php)
● Complex structure:
○ unique folder name (/wp-content/plugins/my-own-
plugin/)
○ bootstrap script: plugin.php or any name
● Main plugin file: Standard Plugin Information
● readme.txt file
Skeleton
Main plugin file
● Define useful constants, for later use:
○ Plugin version
○ Plugin path
○ Plugin folder
○ Plugin URL
● Include dependencies
○ Shared functions
○ Core class
○ Options class
➔ Remember to namespace
your functions, by either
using unique plugins, or
unique class names
➔ Do not use actual PHP
namespaces!
Hooks
● What are they?
○ Actions -> They do things
○ Filters -> They return something
● How they must be used?
○ “Hook” a filter, or action to a custom function
● When?
○ At the right time: it’s a bit tricky and needs practices,
some cheat sheet, or asking the community
Hook to some actions and filters
● The loader class: why?
○ Decoupling functionalities
○ Specialized classes
● Hook to actions:
○ ‘plugins_loaded’ -> the actual entry point (usually)
○ ‘wp_enqueue_scripts’ -> scripts and CSS goes here
● Hook to filters:
○ ‘wp_get_attachment_link’
Implement hooks
● Hook to actions
○ Add scripts and styles
■ Main script and styles
■ Fancybox, helpers and more
■ Pass data to scripts: wp_enqueue_script()
● Hook to filters
○ Tweak the gallery item link
Plugin options definitions and handling
● Implement plugin options
○ A new class => a new file
○ The options loader class
WP Settings API
● WP Settings API
○ register_setting()
○ add_settings_section()
○ add_settings_field()
○ callbacks
○ options_do_page
● Some thoughts about the APIs:
○ Counterintuitive
○ Old
Honestly, we ought to take the time to learn the Settings API however the steep the learning curve,
and start working with it. It is the definitive way to go about creating options pages, and it is the current
version of the API that we have available.
Tom McFarlin (http://tommcfarlin.com/wordpress-settings-api-wrapper)
Plugin options page
● Show the plugin options page
○ OTGS_Fancybox_Gallery_Options::get_setting static
method: why is static?
○ Add a menu item in “Settings” menu
○ Add some javascript and enqueue the script in the
back-end
Refine the main class
● Handle plugin options
● Take advantage of $wp_object_cache in
OTGS_Fancybox_Gallery::
get_attachment_link
The main gallery.js
● Do not use $ (in WordPress)!
● Implement jquery.fancybox()
● Cache jQuery elements
● Play with plugin options
Test it
Questions?

Mais conteúdo relacionado

Destaque

Best practices in WordPress Development
Best practices in WordPress DevelopmentBest practices in WordPress Development
Best practices in WordPress DevelopmentMindfire Solutions
 
Best Practices for WordPress in Enterprise
Best Practices for WordPress in EnterpriseBest Practices for WordPress in Enterprise
Best Practices for WordPress in EnterpriseTaylor Lovett
 
Best Practices for WordPress
Best Practices for WordPressBest Practices for WordPress
Best Practices for WordPressTaylor Lovett
 
Saving Time with WP-CLI
Saving Time with WP-CLISaving Time with WP-CLI
Saving Time with WP-CLITaylor Lovett
 
Sanitizing, Validating and Escaping in WordPress Themes and Plugins
Sanitizing, Validating and Escaping in WordPress Themes and PluginsSanitizing, Validating and Escaping in WordPress Themes and Plugins
Sanitizing, Validating and Escaping in WordPress Themes and PluginsMicah Wood
 
Installing WordPress on AWS
Installing WordPress on AWSInstalling WordPress on AWS
Installing WordPress on AWSManish Jain
 

Destaque (6)

Best practices in WordPress Development
Best practices in WordPress DevelopmentBest practices in WordPress Development
Best practices in WordPress Development
 
Best Practices for WordPress in Enterprise
Best Practices for WordPress in EnterpriseBest Practices for WordPress in Enterprise
Best Practices for WordPress in Enterprise
 
Best Practices for WordPress
Best Practices for WordPressBest Practices for WordPress
Best Practices for WordPress
 
Saving Time with WP-CLI
Saving Time with WP-CLISaving Time with WP-CLI
Saving Time with WP-CLI
 
Sanitizing, Validating and Escaping in WordPress Themes and Plugins
Sanitizing, Validating and Escaping in WordPress Themes and PluginsSanitizing, Validating and Escaping in WordPress Themes and Plugins
Sanitizing, Validating and Escaping in WordPress Themes and Plugins
 
Installing WordPress on AWS
Installing WordPress on AWSInstalling WordPress on AWS
Installing WordPress on AWS
 

Semelhante a Saigon Wordpress Meetup - Best practices for plugin development - A WordPress plugin from scratch - Andrea

Developing word press professionally
Developing word press professionallyDeveloping word press professionally
Developing word press professionallyAustin Gil
 
GDI WordPress 2 January 2012
GDI WordPress 2 January 2012 GDI WordPress 2 January 2012
GDI WordPress 2 January 2012 pamselle
 
Pentester++
Pentester++Pentester++
Pentester++CTruncer
 
Plugin development demystified 2017
Plugin development demystified 2017Plugin development demystified 2017
Plugin development demystified 2017ylefebvre
 
WPSessions Composer for WordPress Plugin Development
WPSessions Composer for WordPress Plugin DevelopmentWPSessions Composer for WordPress Plugin Development
WPSessions Composer for WordPress Plugin DevelopmentCaldera Labs
 
Alice Phieu - WordPress For Beginners
Alice Phieu - WordPress For BeginnersAlice Phieu - WordPress For Beginners
Alice Phieu - WordPress For BeginnersAlice Phieu
 
Jbake workshop (Greach 2019)
Jbake workshop (Greach 2019)Jbake workshop (Greach 2019)
Jbake workshop (Greach 2019)Mario García
 
Contributing to Apache Airflow | Journey to becoming Airflow's leading contri...
Contributing to Apache Airflow | Journey to becoming Airflow's leading contri...Contributing to Apache Airflow | Journey to becoming Airflow's leading contri...
Contributing to Apache Airflow | Journey to becoming Airflow's leading contri...Kaxil Naik
 
Monster JavaScript Course - 50+ projects and applications
Monster JavaScript Course - 50+ projects and applicationsMonster JavaScript Course - 50+ projects and applications
Monster JavaScript Course - 50+ projects and applicationsLaurence Svekis ✔
 
WordPress: After The Install
WordPress: After The InstallWordPress: After The Install
WordPress: After The InstallWordPress NYC
 
A New CLI for Spring Developer Productivity
A New CLI for Spring Developer ProductivityA New CLI for Spring Developer Productivity
A New CLI for Spring Developer ProductivityVMware Tanzu
 
Gutenberg Extended
Gutenberg ExtendedGutenberg Extended
Gutenberg ExtendedSören Wrede
 
WordPress 101 Saturday Session
WordPress 101 Saturday SessionWordPress 101 Saturday Session
WordPress 101 Saturday Sessionpamselle
 
WordPress Theme Development: Part 2
WordPress Theme Development: Part 2WordPress Theme Development: Part 2
WordPress Theme Development: Part 2Josh Lee
 
Cypress report
Cypress reportCypress report
Cypress reportAdarsh
 
Creating a Smooth Development Workflow for High-Quality Modular Open-Source P...
Creating a Smooth Development Workflow for High-Quality Modular Open-Source P...Creating a Smooth Development Workflow for High-Quality Modular Open-Source P...
Creating a Smooth Development Workflow for High-Quality Modular Open-Source P...Pantheon
 
Django interview Questions| Edureka
Django interview  Questions| EdurekaDjango interview  Questions| Edureka
Django interview Questions| EdurekaEdureka!
 

Semelhante a Saigon Wordpress Meetup - Best practices for plugin development - A WordPress plugin from scratch - Andrea (20)

Developing word press professionally
Developing word press professionallyDeveloping word press professionally
Developing word press professionally
 
GDI WordPress 2 January 2012
GDI WordPress 2 January 2012 GDI WordPress 2 January 2012
GDI WordPress 2 January 2012
 
Pentester++
Pentester++Pentester++
Pentester++
 
It4k12 wordpress
It4k12 wordpressIt4k12 wordpress
It4k12 wordpress
 
Plugin development demystified 2017
Plugin development demystified 2017Plugin development demystified 2017
Plugin development demystified 2017
 
WPSessions Composer for WordPress Plugin Development
WPSessions Composer for WordPress Plugin DevelopmentWPSessions Composer for WordPress Plugin Development
WPSessions Composer for WordPress Plugin Development
 
Alice Phieu - WordPress For Beginners
Alice Phieu - WordPress For BeginnersAlice Phieu - WordPress For Beginners
Alice Phieu - WordPress For Beginners
 
Jbake workshop (Greach 2019)
Jbake workshop (Greach 2019)Jbake workshop (Greach 2019)
Jbake workshop (Greach 2019)
 
Contributing to Apache Airflow | Journey to becoming Airflow's leading contri...
Contributing to Apache Airflow | Journey to becoming Airflow's leading contri...Contributing to Apache Airflow | Journey to becoming Airflow's leading contri...
Contributing to Apache Airflow | Journey to becoming Airflow's leading contri...
 
Monster JavaScript Course - 50+ projects and applications
Monster JavaScript Course - 50+ projects and applicationsMonster JavaScript Course - 50+ projects and applications
Monster JavaScript Course - 50+ projects and applications
 
WordPress: After The Install
WordPress: After The InstallWordPress: After The Install
WordPress: After The Install
 
A New CLI for Spring Developer Productivity
A New CLI for Spring Developer ProductivityA New CLI for Spring Developer Productivity
A New CLI for Spring Developer Productivity
 
Code-Hub
Code-HubCode-Hub
Code-Hub
 
CollegeDiveIn presentation
CollegeDiveIn presentationCollegeDiveIn presentation
CollegeDiveIn presentation
 
Gutenberg Extended
Gutenberg ExtendedGutenberg Extended
Gutenberg Extended
 
WordPress 101 Saturday Session
WordPress 101 Saturday SessionWordPress 101 Saturday Session
WordPress 101 Saturday Session
 
WordPress Theme Development: Part 2
WordPress Theme Development: Part 2WordPress Theme Development: Part 2
WordPress Theme Development: Part 2
 
Cypress report
Cypress reportCypress report
Cypress report
 
Creating a Smooth Development Workflow for High-Quality Modular Open-Source P...
Creating a Smooth Development Workflow for High-Quality Modular Open-Source P...Creating a Smooth Development Workflow for High-Quality Modular Open-Source P...
Creating a Smooth Development Workflow for High-Quality Modular Open-Source P...
 
Django interview Questions| Edureka
Django interview  Questions| EdurekaDjango interview  Questions| Edureka
Django interview Questions| Edureka
 

Mais de Triết Sài Gòn

Hạnh Phúc Tùy Cách Nhìn
Hạnh Phúc Tùy Cách NhìnHạnh Phúc Tùy Cách Nhìn
Hạnh Phúc Tùy Cách NhìnTriết Sài Gòn
 
Saigon Wordpress Meetup - Themes Wordpress Meetup
Saigon Wordpress Meetup - Themes Wordpress MeetupSaigon Wordpress Meetup - Themes Wordpress Meetup
Saigon Wordpress Meetup - Themes Wordpress MeetupTriết Sài Gòn
 
Saigon Wordpress Meetup - How customers and developers understand each others...
Saigon Wordpress Meetup - How customers and developers understand each others...Saigon Wordpress Meetup - How customers and developers understand each others...
Saigon Wordpress Meetup - How customers and developers understand each others...Triết Sài Gòn
 
Saigon Wordpress Meetup - Building Sites With WordPress Opening Remarks - Dat...
Saigon Wordpress Meetup - Building Sites With WordPress Opening Remarks - Dat...Saigon Wordpress Meetup - Building Sites With WordPress Opening Remarks - Dat...
Saigon Wordpress Meetup - Building Sites With WordPress Opening Remarks - Dat...Triết Sài Gòn
 
Saigon Wordpress Meetup - Building a business around a WordPress plugin - Amir
Saigon Wordpress Meetup - Building a business around a WordPress plugin - AmirSaigon Wordpress Meetup - Building a business around a WordPress plugin - Amir
Saigon Wordpress Meetup - Building a business around a WordPress plugin - AmirTriết Sài Gòn
 
Saigon Wordpress Meetup - Wordpress HTML Text Widget - Thien Anh
Saigon Wordpress Meetup - Wordpress HTML Text Widget - Thien AnhSaigon Wordpress Meetup - Wordpress HTML Text Widget - Thien Anh
Saigon Wordpress Meetup - Wordpress HTML Text Widget - Thien AnhTriết Sài Gòn
 

Mais de Triết Sài Gòn (6)

Hạnh Phúc Tùy Cách Nhìn
Hạnh Phúc Tùy Cách NhìnHạnh Phúc Tùy Cách Nhìn
Hạnh Phúc Tùy Cách Nhìn
 
Saigon Wordpress Meetup - Themes Wordpress Meetup
Saigon Wordpress Meetup - Themes Wordpress MeetupSaigon Wordpress Meetup - Themes Wordpress Meetup
Saigon Wordpress Meetup - Themes Wordpress Meetup
 
Saigon Wordpress Meetup - How customers and developers understand each others...
Saigon Wordpress Meetup - How customers and developers understand each others...Saigon Wordpress Meetup - How customers and developers understand each others...
Saigon Wordpress Meetup - How customers and developers understand each others...
 
Saigon Wordpress Meetup - Building Sites With WordPress Opening Remarks - Dat...
Saigon Wordpress Meetup - Building Sites With WordPress Opening Remarks - Dat...Saigon Wordpress Meetup - Building Sites With WordPress Opening Remarks - Dat...
Saigon Wordpress Meetup - Building Sites With WordPress Opening Remarks - Dat...
 
Saigon Wordpress Meetup - Building a business around a WordPress plugin - Amir
Saigon Wordpress Meetup - Building a business around a WordPress plugin - AmirSaigon Wordpress Meetup - Building a business around a WordPress plugin - Amir
Saigon Wordpress Meetup - Building a business around a WordPress plugin - Amir
 
Saigon Wordpress Meetup - Wordpress HTML Text Widget - Thien Anh
Saigon Wordpress Meetup - Wordpress HTML Text Widget - Thien AnhSaigon Wordpress Meetup - Wordpress HTML Text Widget - Thien Anh
Saigon Wordpress Meetup - Wordpress HTML Text Widget - Thien Anh
 

Último

20240507 QFM013 Machine Intelligence Reading List April 2024.pdf
20240507 QFM013 Machine Intelligence Reading List April 2024.pdf20240507 QFM013 Machine Intelligence Reading List April 2024.pdf
20240507 QFM013 Machine Intelligence Reading List April 2024.pdfMatthew Sinclair
 
Russian Escort Abu Dhabi 0503464457 Abu DHabi Escorts
Russian Escort Abu Dhabi 0503464457 Abu DHabi EscortsRussian Escort Abu Dhabi 0503464457 Abu DHabi Escorts
Russian Escort Abu Dhabi 0503464457 Abu DHabi EscortsMonica Sydney
 
20240508 QFM014 Elixir Reading List April 2024.pdf
20240508 QFM014 Elixir Reading List April 2024.pdf20240508 QFM014 Elixir Reading List April 2024.pdf
20240508 QFM014 Elixir Reading List April 2024.pdfMatthew Sinclair
 
APNIC Updates presented by Paul Wilson at ARIN 53
APNIC Updates presented by Paul Wilson at ARIN 53APNIC Updates presented by Paul Wilson at ARIN 53
APNIC Updates presented by Paul Wilson at ARIN 53APNIC
 
Story Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr
Story Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrStory Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr
Story Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrHenryBriggs2
 
Top profile Call Girls In Dindigul [ 7014168258 ] Call Me For Genuine Models ...
Top profile Call Girls In Dindigul [ 7014168258 ] Call Me For Genuine Models ...Top profile Call Girls In Dindigul [ 7014168258 ] Call Me For Genuine Models ...
Top profile Call Girls In Dindigul [ 7014168258 ] Call Me For Genuine Models ...gajnagarg
 
一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样
一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样
一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样ayvbos
 
APNIC Policy Roundup, presented by Sunny Chendi at the 5th ICANN APAC-TWNIC E...
APNIC Policy Roundup, presented by Sunny Chendi at the 5th ICANN APAC-TWNIC E...APNIC Policy Roundup, presented by Sunny Chendi at the 5th ICANN APAC-TWNIC E...
APNIC Policy Roundup, presented by Sunny Chendi at the 5th ICANN APAC-TWNIC E...APNIC
 
一比一原版(Flinders毕业证书)弗林德斯大学毕业证原件一模一样
一比一原版(Flinders毕业证书)弗林德斯大学毕业证原件一模一样一比一原版(Flinders毕业证书)弗林德斯大学毕业证原件一模一样
一比一原版(Flinders毕业证书)弗林德斯大学毕业证原件一模一样ayvbos
 
在线制作约克大学毕业证(yu毕业证)在读证明认证可查
在线制作约克大学毕业证(yu毕业证)在读证明认证可查在线制作约克大学毕业证(yu毕业证)在读证明认证可查
在线制作约克大学毕业证(yu毕业证)在读证明认证可查ydyuyu
 
"Boost Your Digital Presence: Partner with a Leading SEO Agency"
"Boost Your Digital Presence: Partner with a Leading SEO Agency""Boost Your Digital Presence: Partner with a Leading SEO Agency"
"Boost Your Digital Presence: Partner with a Leading SEO Agency"growthgrids
 
75539-Cyber Security Challenges PPT.pptx
75539-Cyber Security Challenges PPT.pptx75539-Cyber Security Challenges PPT.pptx
75539-Cyber Security Challenges PPT.pptxAsmae Rabhi
 
Power point inglese - educazione civica di Nuria Iuzzolino
Power point inglese - educazione civica di Nuria IuzzolinoPower point inglese - educazione civica di Nuria Iuzzolino
Power point inglese - educazione civica di Nuria Iuzzolinonuriaiuzzolino1
 
Nagercoil Escorts Service Girl ^ 9332606886, WhatsApp Anytime Nagercoil
Nagercoil Escorts Service Girl ^ 9332606886, WhatsApp Anytime NagercoilNagercoil Escorts Service Girl ^ 9332606886, WhatsApp Anytime Nagercoil
Nagercoil Escorts Service Girl ^ 9332606886, WhatsApp Anytime Nagercoilmeghakumariji156
 
Vip Firozabad Phone 8250092165 Escorts Service At 6k To 30k Along With Ac Room
Vip Firozabad Phone 8250092165 Escorts Service At 6k To 30k Along With Ac RoomVip Firozabad Phone 8250092165 Escorts Service At 6k To 30k Along With Ac Room
Vip Firozabad Phone 8250092165 Escorts Service At 6k To 30k Along With Ac Roommeghakumariji156
 
Russian Call girls in Abu Dhabi 0508644382 Abu Dhabi Call girls
Russian Call girls in Abu Dhabi 0508644382 Abu Dhabi Call girlsRussian Call girls in Abu Dhabi 0508644382 Abu Dhabi Call girls
Russian Call girls in Abu Dhabi 0508644382 Abu Dhabi Call girlsMonica Sydney
 
Trump Diapers Over Dems t shirts Sweatshirt
Trump Diapers Over Dems t shirts SweatshirtTrump Diapers Over Dems t shirts Sweatshirt
Trump Diapers Over Dems t shirts Sweatshirtrahman018755
 
Meaning of On page SEO & its process in detail.
Meaning of On page SEO & its process in detail.Meaning of On page SEO & its process in detail.
Meaning of On page SEO & its process in detail.krishnachandrapal52
 
Microsoft Azure Arc Customer Deck Microsoft
Microsoft Azure Arc Customer Deck MicrosoftMicrosoft Azure Arc Customer Deck Microsoft
Microsoft Azure Arc Customer Deck MicrosoftAanSulistiyo
 
哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查
哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查
哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查ydyuyu
 

Último (20)

20240507 QFM013 Machine Intelligence Reading List April 2024.pdf
20240507 QFM013 Machine Intelligence Reading List April 2024.pdf20240507 QFM013 Machine Intelligence Reading List April 2024.pdf
20240507 QFM013 Machine Intelligence Reading List April 2024.pdf
 
Russian Escort Abu Dhabi 0503464457 Abu DHabi Escorts
Russian Escort Abu Dhabi 0503464457 Abu DHabi EscortsRussian Escort Abu Dhabi 0503464457 Abu DHabi Escorts
Russian Escort Abu Dhabi 0503464457 Abu DHabi Escorts
 
20240508 QFM014 Elixir Reading List April 2024.pdf
20240508 QFM014 Elixir Reading List April 2024.pdf20240508 QFM014 Elixir Reading List April 2024.pdf
20240508 QFM014 Elixir Reading List April 2024.pdf
 
APNIC Updates presented by Paul Wilson at ARIN 53
APNIC Updates presented by Paul Wilson at ARIN 53APNIC Updates presented by Paul Wilson at ARIN 53
APNIC Updates presented by Paul Wilson at ARIN 53
 
Story Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr
Story Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrStory Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr
Story Board.pptxrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr
 
Top profile Call Girls In Dindigul [ 7014168258 ] Call Me For Genuine Models ...
Top profile Call Girls In Dindigul [ 7014168258 ] Call Me For Genuine Models ...Top profile Call Girls In Dindigul [ 7014168258 ] Call Me For Genuine Models ...
Top profile Call Girls In Dindigul [ 7014168258 ] Call Me For Genuine Models ...
 
一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样
一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样
一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样
 
APNIC Policy Roundup, presented by Sunny Chendi at the 5th ICANN APAC-TWNIC E...
APNIC Policy Roundup, presented by Sunny Chendi at the 5th ICANN APAC-TWNIC E...APNIC Policy Roundup, presented by Sunny Chendi at the 5th ICANN APAC-TWNIC E...
APNIC Policy Roundup, presented by Sunny Chendi at the 5th ICANN APAC-TWNIC E...
 
一比一原版(Flinders毕业证书)弗林德斯大学毕业证原件一模一样
一比一原版(Flinders毕业证书)弗林德斯大学毕业证原件一模一样一比一原版(Flinders毕业证书)弗林德斯大学毕业证原件一模一样
一比一原版(Flinders毕业证书)弗林德斯大学毕业证原件一模一样
 
在线制作约克大学毕业证(yu毕业证)在读证明认证可查
在线制作约克大学毕业证(yu毕业证)在读证明认证可查在线制作约克大学毕业证(yu毕业证)在读证明认证可查
在线制作约克大学毕业证(yu毕业证)在读证明认证可查
 
"Boost Your Digital Presence: Partner with a Leading SEO Agency"
"Boost Your Digital Presence: Partner with a Leading SEO Agency""Boost Your Digital Presence: Partner with a Leading SEO Agency"
"Boost Your Digital Presence: Partner with a Leading SEO Agency"
 
75539-Cyber Security Challenges PPT.pptx
75539-Cyber Security Challenges PPT.pptx75539-Cyber Security Challenges PPT.pptx
75539-Cyber Security Challenges PPT.pptx
 
Power point inglese - educazione civica di Nuria Iuzzolino
Power point inglese - educazione civica di Nuria IuzzolinoPower point inglese - educazione civica di Nuria Iuzzolino
Power point inglese - educazione civica di Nuria Iuzzolino
 
Nagercoil Escorts Service Girl ^ 9332606886, WhatsApp Anytime Nagercoil
Nagercoil Escorts Service Girl ^ 9332606886, WhatsApp Anytime NagercoilNagercoil Escorts Service Girl ^ 9332606886, WhatsApp Anytime Nagercoil
Nagercoil Escorts Service Girl ^ 9332606886, WhatsApp Anytime Nagercoil
 
Vip Firozabad Phone 8250092165 Escorts Service At 6k To 30k Along With Ac Room
Vip Firozabad Phone 8250092165 Escorts Service At 6k To 30k Along With Ac RoomVip Firozabad Phone 8250092165 Escorts Service At 6k To 30k Along With Ac Room
Vip Firozabad Phone 8250092165 Escorts Service At 6k To 30k Along With Ac Room
 
Russian Call girls in Abu Dhabi 0508644382 Abu Dhabi Call girls
Russian Call girls in Abu Dhabi 0508644382 Abu Dhabi Call girlsRussian Call girls in Abu Dhabi 0508644382 Abu Dhabi Call girls
Russian Call girls in Abu Dhabi 0508644382 Abu Dhabi Call girls
 
Trump Diapers Over Dems t shirts Sweatshirt
Trump Diapers Over Dems t shirts SweatshirtTrump Diapers Over Dems t shirts Sweatshirt
Trump Diapers Over Dems t shirts Sweatshirt
 
Meaning of On page SEO & its process in detail.
Meaning of On page SEO & its process in detail.Meaning of On page SEO & its process in detail.
Meaning of On page SEO & its process in detail.
 
Microsoft Azure Arc Customer Deck Microsoft
Microsoft Azure Arc Customer Deck MicrosoftMicrosoft Azure Arc Customer Deck Microsoft
Microsoft Azure Arc Customer Deck Microsoft
 
哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查
哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查
哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查
 

Saigon Wordpress Meetup - Best practices for plugin development - A WordPress plugin from scratch - Andrea

  • 1. Best practices for plugin development Create a WordPress plugin from scratch
  • 2. Andrea Sciamanna present ● Lead developer for WPML ● responsible and active developer of the WPML plugin and add-ons past ● Web and desktop application developer (mostly using .net framework)
  • 3. Agenda ● Quick introduction about: a. code readability b. documentation c. patterns ● Some references ● Creating a WordPress plugin from scratch ● (time allowing) Introducing IDEs and OOP
  • 4. Code readability 1. Use coding standards a. Use WordPress PHP Coding Standards: http://goo. gl/FTMm0a b. Comment with PhpDOC: http://www.phpdoc.org c. Don't repeat yourself (DRY): http://blog.codinghorror. com/curlys-law-do-one-thing d. Don’t go crazy trying to follow standards: just get used to them.
  • 5. References ● WordPress Codex: http://codex.wordpress.org ● Stack Overflow: http://stackoverflow.com ○ WordPress Development: http://wordpress. stackexchange.com ● Google: seriously, do I need to tell you?
  • 7. A “Fancy” plugin for your galleries Integrate Fancybox in the standard WordPress gallery.
  • 8. Planned Functionalities ● Show images in a Fancybox/lightbox, rather than opening them in a different page ● Do not interfere with the active theme ● Make it “SEO proof” ● Pseudo-Watermark images without modifying them ● Allow some customization
  • 9. Goals ● Learn how to: ○ enqueue scripts and styles ○ use actions and filters ○ use WordPress Settings API ● Learn best practices, of course! ● ...and the Fancybox plugin
  • 10. Standard plugin structure ● Single file: unique file name (my-own-plugin. php) ● Complex structure: ○ unique folder name (/wp-content/plugins/my-own- plugin/) ○ bootstrap script: plugin.php or any name ● Main plugin file: Standard Plugin Information ● readme.txt file
  • 12. Main plugin file ● Define useful constants, for later use: ○ Plugin version ○ Plugin path ○ Plugin folder ○ Plugin URL ● Include dependencies ○ Shared functions ○ Core class ○ Options class ➔ Remember to namespace your functions, by either using unique plugins, or unique class names ➔ Do not use actual PHP namespaces!
  • 13. Hooks ● What are they? ○ Actions -> They do things ○ Filters -> They return something ● How they must be used? ○ “Hook” a filter, or action to a custom function ● When? ○ At the right time: it’s a bit tricky and needs practices, some cheat sheet, or asking the community
  • 14. Hook to some actions and filters ● The loader class: why? ○ Decoupling functionalities ○ Specialized classes ● Hook to actions: ○ ‘plugins_loaded’ -> the actual entry point (usually) ○ ‘wp_enqueue_scripts’ -> scripts and CSS goes here ● Hook to filters: ○ ‘wp_get_attachment_link’
  • 15. Implement hooks ● Hook to actions ○ Add scripts and styles ■ Main script and styles ■ Fancybox, helpers and more ■ Pass data to scripts: wp_enqueue_script() ● Hook to filters ○ Tweak the gallery item link
  • 16. Plugin options definitions and handling ● Implement plugin options ○ A new class => a new file ○ The options loader class
  • 17. WP Settings API ● WP Settings API ○ register_setting() ○ add_settings_section() ○ add_settings_field() ○ callbacks ○ options_do_page ● Some thoughts about the APIs: ○ Counterintuitive ○ Old Honestly, we ought to take the time to learn the Settings API however the steep the learning curve, and start working with it. It is the definitive way to go about creating options pages, and it is the current version of the API that we have available. Tom McFarlin (http://tommcfarlin.com/wordpress-settings-api-wrapper)
  • 18. Plugin options page ● Show the plugin options page ○ OTGS_Fancybox_Gallery_Options::get_setting static method: why is static? ○ Add a menu item in “Settings” menu ○ Add some javascript and enqueue the script in the back-end
  • 19. Refine the main class ● Handle plugin options ● Take advantage of $wp_object_cache in OTGS_Fancybox_Gallery:: get_attachment_link
  • 20. The main gallery.js ● Do not use $ (in WordPress)! ● Implement jquery.fancybox() ● Cache jQuery elements ● Play with plugin options