SlideShare uma empresa Scribd logo
1 de 23
Intro To Plugin
Development
Emptying out functions.php
Intro To Plugin Development
Topher DeRosia
@topher1kenobe
Hi, my name is Topher
I’m a WordPress developer from
Grand Rapids MI
@topher1kenobe
Intro To Plugin Development
Topher DeRosia
@topher1kenobe
“Just put this code in your theme’s
functions.php file…”
JUST SAY NO
Intro To Plugin Development
Topher DeRosia
@topher1kenobe
Plugins are packages of code that
affect your site’s functionality.
Themes are packages of code that
affect your site’s design.
DO NOT MIX.
Intro To Plugin Development
Topher DeRosia
@topher1kenobe
Plugins are either single files or
folders in /wp-content/plugins
Intro To Plugin Development
Topher DeRosia
@topher1kenobe
Typically inside each plugin folder is a file
with the same name as the folder, plus any
other files it needs.
Intro To Plugin Development
Topher DeRosia
@topher1kenobe
In the top of every main plugin file is a header
block with information about the plugin.
Intro To Plugin Development
Topher DeRosia
@topher1kenobe
The only option absolutely required is the
“Plugin Name”. The others are merely
strongly recommended.
VERY strongly recommended:
License: GNU General Public License v2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Tags: custom-header, custom-menu, editor-style,
featured-images (etc)
Intro To Plugin Development
Topher DeRosia
@topher1kenobe
The Secret Sauce:
Any code you might have put into
functions.php in your theme could
go into a plugin.*
*with a few exceptions
Intro To Plugin Development
Topher DeRosia
@topher1kenobe
Example:
<?php
/*
Plugin Name: Topher’s Little Plugin
Description: Does things I want to my site
Version: 1.0
Author: Topher
*/
// 220 pixels wide by 180 pixels tall, hard crop mode
add_image_size( 'custom-size', 220, 180, true );
?> Intro To Plugin Development
Topher DeRosia
@topher1kenobe
Longer Example:
<?php
/*
Plugin Name: Topher’s Little Plugin
Description: Does things I want to my site
Version: 1.0
Author: Topher
*/
// 220 pixels wide by 180 pixels tall, hard crop mode
add_image_size( 'custom-size', 220, 180, true );
// Make shortcodes work inside text widgets
add_filter('widget_text', 'do_shortcode');
// Fix styling in old content
function phlog_scripts() {
wp_enqueue_style( 'phlog_styles', plugins_url( '/css/phlog.css' , __FILE__ ) );
}
add_action( 'wp_enqueue_scripts', 'phlog_scripts' );
?> Intro To Plugin Development
Topher DeRosia
@topher1kenobe
Explanation:
function phlog_scripts() {
wp_enqueue_style( 'phlog_styles', plugins_url( '/css/phlog.css' , __FILE__ ) );
}
add_action( 'wp_enqueue_scripts', 'phlog_scripts' );
I made a function called `phlog_scripts()`
Inside it is a function that properly enqueues a CSS file.
wp_enqueue_style takes 2 arguments, a name I made up and the path
to the CSS file.
The path to the CSS file is determined with the WordPress function
plugins_url().
Intro To Plugin Development
Topher DeRosia
@topher1kenobe
Releasing a Plugin
A plugin built for release on WordPress.org must meet a list of
requirements. The requirements are listed at
https://developer.wordpress.org/plugins/wordpress-org/
Best practices are found in the WordPress Plugin Handbook
https://developer.wordpress.org/plugins/
Intro To Plugin Development
Topher DeRosia
@topher1kenobe
mu-plugins: mu == must use
Plugins that are stored in mu-plugins are automatically activated, and
cannot be deactivated. The main file of a plugin must be stored
directly in the /mu-plugins/ directory, OR be included.
Intro To Plugin Development
Topher DeRosia
@topher1kenobe
mu-plugins
Intro To Plugin Development
Topher DeRosia
@topher1kenobe
mu-plugins
To convert a regular plugin to mu-plugins, put it in the /mu-plugins
directory and then make a new, single-file plugin that looks like this:
<?php
/*
Plugin Name: mu-plugins inclusion plugin
Description: Includes the main files of any plugins that are in mu-plugins
Author: Topher
Version: 1.0
*/
// include widget_logic
include WP_CONTENT_DIR . '/mu-plugins/widget-logic/widget_logic.php';
?>
Intro To Plugin Development
Topher DeRosia
@topher1kenobe
Extra Credit: WP-CLI
WP-CLI is the command line tool for WordPress. It can create an
empty plugin with the proper header in place:
wp scaffold plugin --prompt
This will ask questions like this:
1/4 <slug>: topher-test
2/4 [--plugin_name=<title>]: Topher's Test
3/4 [--skip-tests] (Y/n): Y
4/4 [--activate] (Y/n): Y
Success: Created /home/topher1/topher1kenobe.com/wp-content/plugins/topher-test
1/1 <plugin>: topher-test
Success: Created test files.
Intro To Plugin Development
Topher DeRosia
@topher1kenobe
Real World Example
Easy Digital Downloads - Customer Contact
Intro To Plugin Development
Topher DeRosia
@topher1kenobe
Easy Digital Downloads - Customer Contact
<?php
/*
Plugin Name: Easy Digital Downloads - Customer Contact
Version: 1.0
Description: Creates a tab on the Customer page for sending an email to that customer.
Author: Topher
Author URI: http://topher1kenobe.com
Plugin URI: http://topher1kenobe.com
Text Domain: edd-customer-contact
Domain Path: /languages
License: GNU General Public License v2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
*/
Intro To Plugin Development
Topher DeRosia
@topher1kenobe
Easy Digital Downloads - Customer Contact
Comment everything!
Docblock
/**
* Contact a customer
*
* @since 2.3
* @param array $args The $_POST array being passeed
* @return int Whether it was a successful email
*/
Inline
// make sure we're allowed to be here at all
if ( ! is_admin() || ! current_user_can( $customer_edit_role ) ) {
wp_die( __( 'You do not have permission to contact this customer.', 'edd' ) );
} Intro To Plugin Development
Topher DeRosia
@topher1kenobe
Easy Digital Downloads - Customer Contact
Insert Code Review Here
Intro To Plugin Development
Topher DeRosia
@topher1kenobe
Easy Digital Downloads - Customer Contact
Get Help
From other developers (Slack, Stack Overflow, friends)
From parent plugin developer (if making an Addon they probably want to
help)
From documentation (https://developer.wordpress.org/plugins/)
From code (read through plugins doing similar things)
Intro To Plugin Development
Topher DeRosia
@topher1kenobe
THANKS FOR
LISTENING
Intro To Plugin Development
Topher DeRosia
@topher1kenobe
http://topher1kenobe.com
Follow me @topher1kenobe

Mais conteúdo relacionado

Mais procurados

Week 12 - Search Engine Optimization
Week 12 -  Search Engine OptimizationWeek 12 -  Search Engine Optimization
Week 12 - Search Engine Optimization
henri_makembe
 
Week 11 - Hosting and Migration
Week 11 - Hosting and MigrationWeek 11 - Hosting and Migration
Week 11 - Hosting and Migration
henri_makembe
 
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
 
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
 
Meetup child-themes
Meetup child-themesMeetup child-themes
Meetup child-themes
DaisyOlsen
 
Plugins at WordCamp Phoenix
Plugins at WordCamp PhoenixPlugins at WordCamp Phoenix
Plugins at WordCamp Phoenix
Andrew Ryno
 

Mais procurados (20)

Week 12 - Search Engine Optimization
Week 12 -  Search Engine OptimizationWeek 12 -  Search Engine Optimization
Week 12 - Search Engine Optimization
 
Week 11 - Hosting and Migration
Week 11 - Hosting and MigrationWeek 11 - Hosting and Migration
Week 11 - Hosting and Migration
 
Reno-Tahoe WordCamp 2011 - WordPress End User Security - Dre Armeda
Reno-Tahoe WordCamp 2011 - WordPress End User Security - Dre ArmedaReno-Tahoe WordCamp 2011 - WordPress End User Security - Dre Armeda
Reno-Tahoe WordCamp 2011 - WordPress End User Security - Dre Armeda
 
Week 7 introduction to theme development
Week 7   introduction to theme developmentWeek 7   introduction to theme development
Week 7 introduction to theme development
 
Intro to WordPress Plugin Development
Intro to WordPress Plugin DevelopmentIntro to WordPress Plugin Development
Intro to WordPress Plugin Development
 
Step by step guide for creating wordpress plugin
Step by step guide for creating wordpress pluginStep by step guide for creating wordpress plugin
Step by step guide for creating wordpress plugin
 
Building the basics (WordPress Ottawa 2014)
Building the basics (WordPress Ottawa 2014)Building the basics (WordPress Ottawa 2014)
Building the basics (WordPress Ottawa 2014)
 
Elastic: Why WYSIWYG is the future of WordPress themes — WordCamp NYC 2009
Elastic: Why WYSIWYG is the future of WordPress themes — WordCamp NYC 2009Elastic: Why WYSIWYG is the future of WordPress themes — WordCamp NYC 2009
Elastic: Why WYSIWYG is the future of WordPress themes — WordCamp NYC 2009
 
Don't Fear the Custom Theme: How to build a custom WordPress theme with only ...
Don't Fear the Custom Theme: How to build a custom WordPress theme with only ...Don't Fear the Custom Theme: How to build a custom WordPress theme with only ...
Don't Fear the Custom Theme: How to build a custom WordPress theme with only ...
 
Meetup child-themes
Meetup child-themesMeetup child-themes
Meetup child-themes
 
The Future Of WordPress Presentation
The Future Of WordPress PresentationThe Future Of WordPress Presentation
The Future Of WordPress Presentation
 
Plugins at WordCamp Phoenix
Plugins at WordCamp PhoenixPlugins at WordCamp Phoenix
Plugins at WordCamp Phoenix
 
WordPress Theme Development for Designers
WordPress Theme Development for DesignersWordPress Theme Development for Designers
WordPress Theme Development for Designers
 
WordPress Standardized Loop API
WordPress Standardized Loop APIWordPress Standardized Loop API
WordPress Standardized Loop API
 
Wordpress Plugin Development Short Tutorial
Wordpress Plugin Development Short TutorialWordpress Plugin Development Short Tutorial
Wordpress Plugin Development Short Tutorial
 
WordPress Plugin Development For Beginners
WordPress Plugin Development For BeginnersWordPress Plugin Development For Beginners
WordPress Plugin Development For Beginners
 
WordPress plugin development
WordPress plugin developmentWordPress plugin development
WordPress plugin development
 
Secure All The Things!
Secure All The Things!Secure All The Things!
Secure All The Things!
 
DrupalEasy: Intro to Theme Development
DrupalEasy: Intro to Theme DevelopmentDrupalEasy: Intro to Theme Development
DrupalEasy: Intro to Theme Development
 
PHPをさわらず作る!デザイナーさんのためのWordPress【超!初級】
PHPをさわらず作る!デザイナーさんのためのWordPress【超!初級】PHPをさわらず作る!デザイナーさんのためのWordPress【超!初級】
PHPをさわらず作る!デザイナーさんのためのWordPress【超!初級】
 

Semelhante a Intro to Plugin Development, Miami WordCamp, 2015

Plug in development
Plug in developmentPlug in development
Plug in development
Lucky Ali
 
Wordpress Custom Child theme
Wordpress Custom Child themeWordpress Custom Child theme
Wordpress Custom Child theme
YouSaf HasSan
 

Semelhante a Intro to Plugin Development, Miami WordCamp, 2015 (20)

Getting started with WordPress development
Getting started with WordPress developmentGetting started with WordPress development
Getting started with WordPress development
 
Creating Your First WordPress Plugin
Creating Your First WordPress PluginCreating Your First WordPress Plugin
Creating Your First WordPress Plugin
 
WordPress theme development from scratch : ICT MeetUp 2013 Nepal
WordPress theme development from scratch : ICT MeetUp 2013 NepalWordPress theme development from scratch : ICT MeetUp 2013 Nepal
WordPress theme development from scratch : ICT MeetUp 2013 Nepal
 
Plugin development demystified 2017
Plugin development demystified 2017Plugin development demystified 2017
Plugin development demystified 2017
 
Plugin Development Practices
Plugin Development PracticesPlugin Development Practices
Plugin Development Practices
 
Theming 101
Theming 101Theming 101
Theming 101
 
WordPress basic fundamental of plugin development and creating shortcode
WordPress basic fundamental of plugin development and creating shortcodeWordPress basic fundamental of plugin development and creating shortcode
WordPress basic fundamental of plugin development and creating shortcode
 
Extending WordPress
Extending WordPressExtending WordPress
Extending WordPress
 
How to make a WordPress theme
How to make a WordPress themeHow to make a WordPress theme
How to make a WordPress theme
 
WordPress Theme Workshop: Part 3
WordPress Theme Workshop: Part 3WordPress Theme Workshop: Part 3
WordPress Theme Workshop: Part 3
 
Word press Plugins by WordPress Experts
Word press Plugins by WordPress ExpertsWord press Plugins by WordPress Experts
Word press Plugins by WordPress Experts
 
Plug in development
Plug in developmentPlug in development
Plug in development
 
Childthemes ottawa-word camp-1919
Childthemes ottawa-word camp-1919Childthemes ottawa-word camp-1919
Childthemes ottawa-word camp-1919
 
WordPress Plugins
WordPress PluginsWordPress Plugins
WordPress Plugins
 
PSD to WordPress
PSD to WordPressPSD to WordPress
PSD to WordPress
 
Now That's What I Call WordPress Security 2010
Now That's What I Call WordPress Security 2010Now That's What I Call WordPress Security 2010
Now That's What I Call WordPress Security 2010
 
Wordpress Custom Child theme
Wordpress Custom Child themeWordpress Custom Child theme
Wordpress Custom Child theme
 
Introduction to WordPress Hooks 2016
Introduction to WordPress Hooks 2016Introduction to WordPress Hooks 2016
Introduction to WordPress Hooks 2016
 
WordPress Structure and Best Practices
WordPress Structure and Best PracticesWordPress Structure and Best Practices
WordPress Structure and Best Practices
 
Best practices in WordPress Development
Best practices in WordPress DevelopmentBest practices in WordPress Development
Best practices in WordPress Development
 

Mais de topher1kenobe

Mais de topher1kenobe (13)

How To Increase Ecommerce Conversions
How To Increase Ecommerce ConversionsHow To Increase Ecommerce Conversions
How To Increase Ecommerce Conversions
 
Build Ecommerce Sites With Confidence (Demystifying Ecommerce), WordCamp Los ...
Build Ecommerce Sites With Confidence (Demystifying Ecommerce), WordCamp Los ...Build Ecommerce Sites With Confidence (Demystifying Ecommerce), WordCamp Los ...
Build Ecommerce Sites With Confidence (Demystifying Ecommerce), WordCamp Los ...
 
Build Ecommerce Sites With Confidence (Demystifying Ecommerce)
Build Ecommerce Sites With Confidence (Demystifying Ecommerce)Build Ecommerce Sites With Confidence (Demystifying Ecommerce)
Build Ecommerce Sites With Confidence (Demystifying Ecommerce)
 
6 Ecommerce Trends Altering the Ecommerce Landscape, and changing which strat...
6 Ecommerce Trends Altering the Ecommerce Landscape, and changing which strat...6 Ecommerce Trends Altering the Ecommerce Landscape, and changing which strat...
6 Ecommerce Trends Altering the Ecommerce Landscape, and changing which strat...
 
Introduction to the WordPress Transients API
Introduction to the WordPress Transients APIIntroduction to the WordPress Transients API
Introduction to the WordPress Transients API
 
Talking to Other Sites with the WP HTTP API
Talking to Other Sites with the WP HTTP APITalking to Other Sites with the WP HTTP API
Talking to Other Sites with the WP HTTP API
 
What’s a REST API and why should I care?
What’s a REST API and why should I care?What’s a REST API and why should I care?
What’s a REST API and why should I care?
 
Working with WP_Query in WordPress
Working with WP_Query in WordPressWorking with WP_Query in WordPress
Working with WP_Query in WordPress
 
HeroPress: A Case Study
HeroPress: A Case StudyHeroPress: A Case Study
HeroPress: A Case Study
 
Custom Database Queries in WordPress
Custom Database Queries in WordPressCustom Database Queries in WordPress
Custom Database Queries in WordPress
 
Introduction to WordPress Child Theming, WordCamp Kansas City, 2015
Introduction to WordPress Child Theming, WordCamp Kansas City, 2015Introduction to WordPress Child Theming, WordCamp Kansas City, 2015
Introduction to WordPress Child Theming, WordCamp Kansas City, 2015
 
WordCamp Ann Arbor 2014: Site Caching, From Nothing to Everything
WordCamp Ann Arbor 2014: Site Caching, From Nothing to EverythingWordCamp Ann Arbor 2014: Site Caching, From Nothing to Everything
WordCamp Ann Arbor 2014: Site Caching, From Nothing to Everything
 
Command Line Awesome, WordCamp Grand Rapids 2014
Command Line Awesome, WordCamp Grand Rapids 2014Command Line Awesome, WordCamp Grand Rapids 2014
Command Line Awesome, WordCamp Grand Rapids 2014
 

Último

Lucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRL
Lucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRLLucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRL
Lucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRL
imonikaupta
 
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝
soniya singh
 
Call Girls In Ashram Chowk Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Ashram Chowk Delhi 💯Call Us 🔝8264348440🔝Call Girls In Ashram Chowk Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Ashram Chowk Delhi 💯Call Us 🔝8264348440🔝
soniya singh
 
CALL ON ➥8923113531 🔝Call Girls Lucknow Lucknow best sexual service Online
CALL ON ➥8923113531 🔝Call Girls Lucknow Lucknow best sexual service OnlineCALL ON ➥8923113531 🔝Call Girls Lucknow Lucknow best sexual service Online
CALL ON ➥8923113531 🔝Call Girls Lucknow Lucknow best sexual service Online
anilsa9823
 
Low Rate Young Call Girls in Sector 63 Mamura Noida ✔️☆9289244007✔️☆ Female E...
Low Rate Young Call Girls in Sector 63 Mamura Noida ✔️☆9289244007✔️☆ Female E...Low Rate Young Call Girls in Sector 63 Mamura Noida ✔️☆9289244007✔️☆ Female E...
Low Rate Young Call Girls in Sector 63 Mamura Noida ✔️☆9289244007✔️☆ Female E...
SofiyaSharma5
 

Último (20)

Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Shahpur Jat Escort Service Delhi N.C.R.
 
Lucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRL
Lucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRLLucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRL
Lucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRL
 
Enjoy Night⚡Call Girls Dlf City Phase 3 Gurgaon >༒8448380779 Escort Service
Enjoy Night⚡Call Girls Dlf City Phase 3 Gurgaon >༒8448380779 Escort ServiceEnjoy Night⚡Call Girls Dlf City Phase 3 Gurgaon >༒8448380779 Escort Service
Enjoy Night⚡Call Girls Dlf City Phase 3 Gurgaon >༒8448380779 Escort Service
 
Russian Call girl in Ajman +971563133746 Ajman Call girl Service
Russian Call girl in Ajman +971563133746 Ajman Call girl ServiceRussian Call girl in Ajman +971563133746 Ajman Call girl Service
Russian Call girl in Ajman +971563133746 Ajman Call girl Service
 
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝
 
Hire↠Young Call Girls in Tilak nagar (Delhi) ☎️ 9205541914 ☎️ Independent Esc...
Hire↠Young Call Girls in Tilak nagar (Delhi) ☎️ 9205541914 ☎️ Independent Esc...Hire↠Young Call Girls in Tilak nagar (Delhi) ☎️ 9205541914 ☎️ Independent Esc...
Hire↠Young Call Girls in Tilak nagar (Delhi) ☎️ 9205541914 ☎️ Independent Esc...
 
Call Now ☎ 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.Call Now ☎ 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.
 
Call Girls In Ashram Chowk Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Ashram Chowk Delhi 💯Call Us 🔝8264348440🔝Call Girls In Ashram Chowk Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Ashram Chowk Delhi 💯Call Us 🔝8264348440🔝
 
Call Girls Dubai Prolapsed O525547819 Call Girls In Dubai Princes$
Call Girls Dubai Prolapsed O525547819 Call Girls In Dubai Princes$Call Girls Dubai Prolapsed O525547819 Call Girls In Dubai Princes$
Call Girls Dubai Prolapsed O525547819 Call Girls In Dubai Princes$
 
Pune Airport ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready...
Pune Airport ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready...Pune Airport ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready...
Pune Airport ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready...
 
𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...
𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...
𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...
 
VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting High Prof...
VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting  High Prof...VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting  High Prof...
VIP Model Call Girls Hadapsar ( Pune ) Call ON 9905417584 Starting High Prof...
 
✂️ 👅 Independent Andheri Escorts With Room Vashi Call Girls 💃 9004004663
✂️ 👅 Independent Andheri Escorts With Room Vashi Call Girls 💃 9004004663✂️ 👅 Independent Andheri Escorts With Room Vashi Call Girls 💃 9004004663
✂️ 👅 Independent Andheri Escorts With Room Vashi Call Girls 💃 9004004663
 
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark Web
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark WebGDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark Web
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark Web
 
Moving Beyond Twitter/X and Facebook - Social Media for local news providers
Moving Beyond Twitter/X and Facebook - Social Media for local news providersMoving Beyond Twitter/X and Facebook - Social Media for local news providers
Moving Beyond Twitter/X and Facebook - Social Media for local news providers
 
Call Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service Available
Call Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service AvailableCall Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service Available
Call Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service Available
 
CALL ON ➥8923113531 🔝Call Girls Lucknow Lucknow best sexual service Online
CALL ON ➥8923113531 🔝Call Girls Lucknow Lucknow best sexual service OnlineCALL ON ➥8923113531 🔝Call Girls Lucknow Lucknow best sexual service Online
CALL ON ➥8923113531 🔝Call Girls Lucknow Lucknow best sexual service Online
 
INDIVIDUAL ASSIGNMENT #3 CBG, PRESENTATION.
INDIVIDUAL ASSIGNMENT #3 CBG, PRESENTATION.INDIVIDUAL ASSIGNMENT #3 CBG, PRESENTATION.
INDIVIDUAL ASSIGNMENT #3 CBG, PRESENTATION.
 
Low Rate Young Call Girls in Sector 63 Mamura Noida ✔️☆9289244007✔️☆ Female E...
Low Rate Young Call Girls in Sector 63 Mamura Noida ✔️☆9289244007✔️☆ Female E...Low Rate Young Call Girls in Sector 63 Mamura Noida ✔️☆9289244007✔️☆ Female E...
Low Rate Young Call Girls in Sector 63 Mamura Noida ✔️☆9289244007✔️☆ Female E...
 
@9999965857 🫦 Sexy Desi Call Girls Laxmi Nagar 💓 High Profile Escorts Delhi 🫶
@9999965857 🫦 Sexy Desi Call Girls Laxmi Nagar 💓 High Profile Escorts Delhi 🫶@9999965857 🫦 Sexy Desi Call Girls Laxmi Nagar 💓 High Profile Escorts Delhi 🫶
@9999965857 🫦 Sexy Desi Call Girls Laxmi Nagar 💓 High Profile Escorts Delhi 🫶
 

Intro to Plugin Development, Miami WordCamp, 2015

  • 1. Intro To Plugin Development Emptying out functions.php Intro To Plugin Development Topher DeRosia @topher1kenobe
  • 2. Hi, my name is Topher I’m a WordPress developer from Grand Rapids MI @topher1kenobe Intro To Plugin Development Topher DeRosia @topher1kenobe
  • 3. “Just put this code in your theme’s functions.php file…” JUST SAY NO Intro To Plugin Development Topher DeRosia @topher1kenobe
  • 4. Plugins are packages of code that affect your site’s functionality. Themes are packages of code that affect your site’s design. DO NOT MIX. Intro To Plugin Development Topher DeRosia @topher1kenobe
  • 5. Plugins are either single files or folders in /wp-content/plugins Intro To Plugin Development Topher DeRosia @topher1kenobe
  • 6. Typically inside each plugin folder is a file with the same name as the folder, plus any other files it needs. Intro To Plugin Development Topher DeRosia @topher1kenobe
  • 7. In the top of every main plugin file is a header block with information about the plugin. Intro To Plugin Development Topher DeRosia @topher1kenobe
  • 8. The only option absolutely required is the “Plugin Name”. The others are merely strongly recommended. VERY strongly recommended: License: GNU General Public License v2 or later License URI: http://www.gnu.org/licenses/gpl-2.0.html Tags: custom-header, custom-menu, editor-style, featured-images (etc) Intro To Plugin Development Topher DeRosia @topher1kenobe
  • 9. The Secret Sauce: Any code you might have put into functions.php in your theme could go into a plugin.* *with a few exceptions Intro To Plugin Development Topher DeRosia @topher1kenobe
  • 10. Example: <?php /* Plugin Name: Topher’s Little Plugin Description: Does things I want to my site Version: 1.0 Author: Topher */ // 220 pixels wide by 180 pixels tall, hard crop mode add_image_size( 'custom-size', 220, 180, true ); ?> Intro To Plugin Development Topher DeRosia @topher1kenobe
  • 11. Longer Example: <?php /* Plugin Name: Topher’s Little Plugin Description: Does things I want to my site Version: 1.0 Author: Topher */ // 220 pixels wide by 180 pixels tall, hard crop mode add_image_size( 'custom-size', 220, 180, true ); // Make shortcodes work inside text widgets add_filter('widget_text', 'do_shortcode'); // Fix styling in old content function phlog_scripts() { wp_enqueue_style( 'phlog_styles', plugins_url( '/css/phlog.css' , __FILE__ ) ); } add_action( 'wp_enqueue_scripts', 'phlog_scripts' ); ?> Intro To Plugin Development Topher DeRosia @topher1kenobe
  • 12. Explanation: function phlog_scripts() { wp_enqueue_style( 'phlog_styles', plugins_url( '/css/phlog.css' , __FILE__ ) ); } add_action( 'wp_enqueue_scripts', 'phlog_scripts' ); I made a function called `phlog_scripts()` Inside it is a function that properly enqueues a CSS file. wp_enqueue_style takes 2 arguments, a name I made up and the path to the CSS file. The path to the CSS file is determined with the WordPress function plugins_url(). Intro To Plugin Development Topher DeRosia @topher1kenobe
  • 13. Releasing a Plugin A plugin built for release on WordPress.org must meet a list of requirements. The requirements are listed at https://developer.wordpress.org/plugins/wordpress-org/ Best practices are found in the WordPress Plugin Handbook https://developer.wordpress.org/plugins/ Intro To Plugin Development Topher DeRosia @topher1kenobe
  • 14. mu-plugins: mu == must use Plugins that are stored in mu-plugins are automatically activated, and cannot be deactivated. The main file of a plugin must be stored directly in the /mu-plugins/ directory, OR be included. Intro To Plugin Development Topher DeRosia @topher1kenobe
  • 15. mu-plugins Intro To Plugin Development Topher DeRosia @topher1kenobe
  • 16. mu-plugins To convert a regular plugin to mu-plugins, put it in the /mu-plugins directory and then make a new, single-file plugin that looks like this: <?php /* Plugin Name: mu-plugins inclusion plugin Description: Includes the main files of any plugins that are in mu-plugins Author: Topher Version: 1.0 */ // include widget_logic include WP_CONTENT_DIR . '/mu-plugins/widget-logic/widget_logic.php'; ?> Intro To Plugin Development Topher DeRosia @topher1kenobe
  • 17. Extra Credit: WP-CLI WP-CLI is the command line tool for WordPress. It can create an empty plugin with the proper header in place: wp scaffold plugin --prompt This will ask questions like this: 1/4 <slug>: topher-test 2/4 [--plugin_name=<title>]: Topher's Test 3/4 [--skip-tests] (Y/n): Y 4/4 [--activate] (Y/n): Y Success: Created /home/topher1/topher1kenobe.com/wp-content/plugins/topher-test 1/1 <plugin>: topher-test Success: Created test files. Intro To Plugin Development Topher DeRosia @topher1kenobe
  • 18. Real World Example Easy Digital Downloads - Customer Contact Intro To Plugin Development Topher DeRosia @topher1kenobe
  • 19. Easy Digital Downloads - Customer Contact <?php /* Plugin Name: Easy Digital Downloads - Customer Contact Version: 1.0 Description: Creates a tab on the Customer page for sending an email to that customer. Author: Topher Author URI: http://topher1kenobe.com Plugin URI: http://topher1kenobe.com Text Domain: edd-customer-contact Domain Path: /languages License: GNU General Public License v2 or later License URI: http://www.gnu.org/licenses/gpl-2.0.html */ Intro To Plugin Development Topher DeRosia @topher1kenobe
  • 20. Easy Digital Downloads - Customer Contact Comment everything! Docblock /** * Contact a customer * * @since 2.3 * @param array $args The $_POST array being passeed * @return int Whether it was a successful email */ Inline // make sure we're allowed to be here at all if ( ! is_admin() || ! current_user_can( $customer_edit_role ) ) { wp_die( __( 'You do not have permission to contact this customer.', 'edd' ) ); } Intro To Plugin Development Topher DeRosia @topher1kenobe
  • 21. Easy Digital Downloads - Customer Contact Insert Code Review Here Intro To Plugin Development Topher DeRosia @topher1kenobe
  • 22. Easy Digital Downloads - Customer Contact Get Help From other developers (Slack, Stack Overflow, friends) From parent plugin developer (if making an Addon they probably want to help) From documentation (https://developer.wordpress.org/plugins/) From code (read through plugins doing similar things) Intro To Plugin Development Topher DeRosia @topher1kenobe
  • 23. THANKS FOR LISTENING Intro To Plugin Development Topher DeRosia @topher1kenobe http://topher1kenobe.com Follow me @topher1kenobe