SlideShare a Scribd company logo
WordPress Plugin #2
May 14th, 2015
Changwoo
Today’s Topics
1.Hooks in Nutshell
2.Database Tables in Nutshell
Recap
- Your first plugin
- Hello Dolly plugin
- action, and callback
Recap
Plugin Header:
/*
Plugin Name: Hello Dolly
Plugin URI: http://wordpress.org/plugins/hello-dolly/
Description: This is not just a plugin, it symbolizes the hope and enthusiasm of an
entire generation summed up in two words sung most famously by Louis Armstrong: Hello,
Dolly. When activated you will randomly see a lyric from <cite>Hello, Dolly</cite> in
the upper right of your admin screen on every page.
Author: Matt Mullenweg
Version: 1.6
Author URI: http://ma.tt/
*/
Recap
Callback Mechanism:
add_action( ‘admin_notices’, ‘hello_dolly’ );
function hello_dolly() {
...
}
Name of hook
Callback function
WP function for hook
Recap
Planning your own plugin, and ...
submission!
Hooks in Nutshell
Hook: an Event
Plugin programming:
- Hook-driven programming.
- A hook means an event.
Hello dolly’s case
2 actions: admin_notices, admin_head
● admin_notices codex
● admin_head codex
Hello dolly’s case
2 actions: admin_notices, admin_head
Let’s find source code.
$ fgrep -Rn do_action( 'admin_notices' ) *
wp-admin/admin-header.php:238: do_action( 'admin_notices' );
$ fgrep -Rn do_action( 'admin_head' ) *
wp-admin/includes/media.php:491: do_action( 'admin_head' );
wp-admin/includes/template.php:1627:do_action( 'admin_head' );
wp-admin/includes/class-wp-press-this.php:1267: do_action( 'admin_head' );
wp-admin/admin-header.php:125:do_action( 'admin_head' );
show source codes
Hook interface
wp-includes/plugin.php
What is action?
What is filter?
● add_filter()
● has_filter()
● apply_filters()
● add_action()
● has_action()
● do_action()
Task Separation
Themes: visual part
Plugins: functional part
Actions: structural part
Filters: information part
Task Separation
Q. I want to add extra contents to every post to be
displayed. Which one do I have to use?
Q. I want to a add menu page to admin page. Which one?
Q. I want to customize the table columns of pages screen.
Q. I want to do something when a post is updated.
Task Separation (solution)
Q. I want to add extra contents to every post to be
displayed. Which one do I have to use?
Q. I want to a add menu page to admin page. Which one?
Q. I want to customize the table columns of pages screen.
Q. I want to do something when a post is updated.
A. filter. ‘the_content’ hook.
A. action. ‘admin_menu’ hook.
A. filter. ‘manage_pages_columns’ hook.
A. action. ‘post_updated’ hook.
Task separation
Do not have to remember them all.
Moreover, actually,
add_action == add_filter
Action, Filter definition
wp-includes/plugin.php
function add_action($tag, $function_to_add, $priority = 10, $accepted_args = 1) {
return add_filter($tag, $function_to_add, $priority, $accepted_args);
}
add_action() is mere an alias of add_filter()
Then, why add_action() is created?
Because they want to get more detailed code.
They just wanted detailed conception. That’s cool.
do_action, add_action feedback
do_action:
fires registered action
add_action:
loads any actions
No restriction. you can define your own
hooks.
callback functions...
....
..
.
$wp_filter
add_action(
$tag,
$callback,
$priority,
$num_args
);
callback functions...
....
..
.
$wp_filter
add_action(
‘my_hook’,
‘my_callback’,
10,
1
);
callback functions...
....
..
.
my_hook - my_callback
$wp_filter
add_action(
‘my_hook’,
‘my_callback’,
10,
1
);
callback functions...
....
..
.
my_hook - my_callback
$wp_filter
add_action(
‘my_hook’,
‘my_callback’,
10,
1
);
somewhere in your code
...
do_action(
‘my_hook’
);
...
callback functions...
....
..
.
my_hook - my_callback
$wp_filter
add_action(
‘my_hook’,
‘my_callback’,
10,
1
);
somewhere in your code
...
do_action(
‘my_hook’
);
...
callback functions...
....
..
.
my_hook - my_callback
$wp_filter
add_action(
‘my_hook’,
‘my_callback’,
10,
1
);
somewhere in your code
...
do_action(
‘my_hook’
);
...
by my_hook:
my_callback()
do_action
inside of do_action:
● retrieve the callback functions by their tags (hook)
● sort by priority
● call_user_func()
do {
foreach ( (array) current($wp_filter[$tag]) as $the_ )
if ( !is_null($the_['function']) )
call_user_func_array($the_['function'],
array_slice($args, 0, (int) $the_['accepted_args']));
} while ( next($wp_filter[$tag]) !== false );
add_action
function add_filter( $tag, $function_to_add, $priority = 10, $accepted_args = 1 ) {
global $wp_filter, $merged_filters;
$idx = _wp_filter_build_unique_id($tag, $function_to_add, $priority);
$wp_filter[$tag][$priority][$idx] = array('function' => $function_to_add,
'accepted_args' => $accepted_args);
unset( $merged_filters[ $tag ] );
return true;
}
$wp_filter is an array.
Check it out!
Build a plugin that dumps all registered
actions or filters.
Add your own hook and call it.
Download template code and edit.
http://<myip>/wp-admin/ (meetup / 1)
ftp://<myip> (meetup / 1)
Summary
● filter and action are the same. action is alias.
o structure, data separation
● In fact, this is like a fine wrapper for call_user_func.
o do_action() fires callback functions when the hook
is available
o add_action() loads callback functions.
● There are huge amount of hooks: see reference.
● You can also define your own hooks.
Database Tables in Nutshell
Database: the Root
Database: backbone of web apps.
A good app without understanding
its db structure: just an illusion.
Database description
https://codex.wordpress.org/Database_Description
● parent - meta styles
o wp_comments - wp_commentmeta
o wp_user - wp_usermeta
o wp_posts - wp_postmeta
o wp_options
● wp_terms - wp_term_taxonomy - wp_term_relationships
Meta table
Every *meta table has
● meta_key
● meta_value
closely related to “hashing”
Commentmeta structure
Postmeta structure
Usermeta structure
Options structure
Hashing
key - value pair.
key is short / value is often long.
key is searchable.
Hashing often called (implemented) as
“dictionary”, or “associative array”.
Meta key: benefits
Flexible, extendable
Ordinary tables can’t do these:
● Creating fields “on demands”
● This is one reason why WordPress is
a very versaitle, general, and
easy-to-customize CMS.
Meta key sample: user info
You want to add “Kakaotalk ID”
for every user:
just add “kakaotalk_id” meta key.
Meta in edit screen
Does it matter?
Yes! When fresh install,
WordPress: 11+ tables
74 tables
49 tables
79 tables
Jomla:
Drupal:
XpressEngine:
Meta key: Hazards
No type checking, validation
Meta key consistency
Efficiency
Nothing is perfect!
next: terms, taxonomies, ...
Terms and Taxonomies
Terms: a word
Taxonomy: classification of terms
Terms and Taxonomies
iron
??
Home appliance Metal ???
Adding Terms in Posts
Posts have basically two taxonomies:
● tags
● categories
Adding tag/category = adding term
Adding Terms in Posts
<terms>
term_id: 2
name: MyCategory
slug: my-category
term_group: 0
Adding Terms in Posts
<term_taxonomy>
term_taxonomy_id: 2
term_id: 2
taxonomy: category
/ post_tag
description:
parent: 0
count: 0
Category Setting
<term_relationships>
object_id: 1
term_taxonomy_id: 2
term_order: 0
Post ID: 75 term_relationships.object_id
term_relationships.term_taxonomy_id
Post ID: 75 term_relationships.object_id
term_relationships.term_taxonomy_id
Post ID: 75 term_relationships.object_id
term_relationships.term_taxonomy_id
term_taxonomy.term_taxonomy_id
term_taxonomy.term_id
term_taxonomy.taxonomy ★
Post ID: 75 term_relationships.object_id
term_relationships.term_taxonomy_id
term_taxonomy.term_taxonomy_id
term_taxonomy.term_id
term_taxonomy.taxonomy ★
Post ID: 75 term_relationships.object_id
term_relationships.term_taxonomy_id
terms.term_id
terms.name ★
terms.slug
term_taxonomy.term_taxonomy_id
term_taxonomy.term_id
term_taxonomy.taxonomy ★
Post ID: 75 term_relationships.object_id
term_relationships.term_taxonomy_id
terms.term_id
terms.name ★
terms.slug
term_taxonomy.term_taxonomy_id
term_taxonomy.term_id
term_taxonomy.taxonomy ★
Initial Taxonomies
< wp-includes/taxonomy.php >
function register_taxonomy(
$taxonomy, $object_type, $args = array() ) { ... }
function create_initial_taxonomies() {
register_taxonomy( 'category', 'post', array(...) );
register_taxonomy( 'post_tag', 'post', array(...) );
... and so on ...
create_initial_taxonomies() is called in wp-settings.php
Summary
● Wordpress Datbase table uses metadata
style strategy
● meta tables have key / value fields
o flexible, easy to extend
o while it can have some disadvantages
Summary
● Taxonomy: classification of term
● You can add taxonomies (as well as terms)
● Taxonomy can be flat or hierarchical
● term_taxonomy: taxonomy -
term
● term_relationship: posts - taxonomy
Next week
Admin Menu
● Almost every plugin has its menu
● Easy WP Plugin API
Admin Post
● POST type data submission
URL Query
AJAX Data handling
Wordpress Posts in Nutshell

More Related Content

What's hot

Empowering users: modifying the admin experience
Empowering users: modifying the admin experienceEmpowering users: modifying the admin experience
Empowering users: modifying the admin experience
Beth Soderberg
 
Rails 3: Dashing to the Finish
Rails 3: Dashing to the FinishRails 3: Dashing to the Finish
Rails 3: Dashing to the FinishYehuda Katz
 
Dagger 2 vs koin
Dagger 2 vs koinDagger 2 vs koin
Dagger 2 vs koin
Jintin Lin
 
Practical Protocol-Oriented-Programming
Practical Protocol-Oriented-ProgrammingPractical Protocol-Oriented-Programming
Practical Protocol-Oriented-Programming
Natasha Murashev
 
Optimizing Magento by Preloading Data
Optimizing Magento by Preloading DataOptimizing Magento by Preloading Data
Optimizing Magento by Preloading Data
Ivan Chepurnyi
 
Android Sliding Menu dengan Navigation Drawer
Android Sliding Menu dengan Navigation DrawerAndroid Sliding Menu dengan Navigation Drawer
Android Sliding Menu dengan Navigation Drawer
Agus Haryanto
 
Owl: The New Odoo UI Framework
Owl: The New Odoo UI FrameworkOwl: The New Odoo UI Framework
Owl: The New Odoo UI Framework
Odoo
 
Maven plugin guide using Modello Framework
Maven plugin guide using Modello FrameworkMaven plugin guide using Modello Framework
Maven plugin guide using Modello Framework
fulvio russo
 
Love and Loss: A Symfony Security Play
Love and Loss: A Symfony Security PlayLove and Loss: A Symfony Security Play
Love and Loss: A Symfony Security Play
Kris Wallsmith
 
SymfonyCon Berlin 2016 - Symfony Plugin for PhpStorm - 3 years later
SymfonyCon Berlin 2016 - Symfony Plugin for PhpStorm - 3 years laterSymfonyCon Berlin 2016 - Symfony Plugin for PhpStorm - 3 years later
SymfonyCon Berlin 2016 - Symfony Plugin for PhpStorm - 3 years later
Haehnchen
 
#31.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_스프링프레임워크 강좌, 재직자환급교육,실업자국비지원...
#31.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_스프링프레임워크 강좌, 재직자환급교육,실업자국비지원...#31.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_스프링프레임워크 강좌, 재직자환급교육,실업자국비지원...
#31.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_스프링프레임워크 강좌, 재직자환급교육,실업자국비지원...
탑크리에듀(구로디지털단지역3번출구 2분거리)
 
Developing New Widgets for your Views in Owl
Developing New Widgets for your Views in OwlDeveloping New Widgets for your Views in Owl
Developing New Widgets for your Views in Owl
Odoo
 
Matters of State
Matters of StateMatters of State
Matters of State
Kris Wallsmith
 
Curso Symfony - Clase 2
Curso Symfony - Clase 2Curso Symfony - Clase 2
Curso Symfony - Clase 2
Javier Eguiluz
 
Design how your objects talk through mocking
Design how your objects talk through mockingDesign how your objects talk through mocking
Design how your objects talk through mocking
Konstantin Kudryashov
 
OSCON Google App Engine Codelab - July 2010
OSCON Google App Engine Codelab - July 2010OSCON Google App Engine Codelab - July 2010
OSCON Google App Engine Codelab - July 2010
ikailan
 
Curso Symfony - Clase 4
Curso Symfony - Clase 4Curso Symfony - Clase 4
Curso Symfony - Clase 4
Javier Eguiluz
 
React & Redux for noobs
React & Redux for noobsReact & Redux for noobs
React & Redux for noobs
[T]echdencias
 

What's hot (20)

Empowering users: modifying the admin experience
Empowering users: modifying the admin experienceEmpowering users: modifying the admin experience
Empowering users: modifying the admin experience
 
Rails 3: Dashing to the Finish
Rails 3: Dashing to the FinishRails 3: Dashing to the Finish
Rails 3: Dashing to the Finish
 
Dagger 2 vs koin
Dagger 2 vs koinDagger 2 vs koin
Dagger 2 vs koin
 
Practical Protocol-Oriented-Programming
Practical Protocol-Oriented-ProgrammingPractical Protocol-Oriented-Programming
Practical Protocol-Oriented-Programming
 
Optimizing Magento by Preloading Data
Optimizing Magento by Preloading DataOptimizing Magento by Preloading Data
Optimizing Magento by Preloading Data
 
Android Sliding Menu dengan Navigation Drawer
Android Sliding Menu dengan Navigation DrawerAndroid Sliding Menu dengan Navigation Drawer
Android Sliding Menu dengan Navigation Drawer
 
Owl: The New Odoo UI Framework
Owl: The New Odoo UI FrameworkOwl: The New Odoo UI Framework
Owl: The New Odoo UI Framework
 
Maven plugin guide using Modello Framework
Maven plugin guide using Modello FrameworkMaven plugin guide using Modello Framework
Maven plugin guide using Modello Framework
 
Love and Loss: A Symfony Security Play
Love and Loss: A Symfony Security PlayLove and Loss: A Symfony Security Play
Love and Loss: A Symfony Security Play
 
SymfonyCon Berlin 2016 - Symfony Plugin for PhpStorm - 3 years later
SymfonyCon Berlin 2016 - Symfony Plugin for PhpStorm - 3 years laterSymfonyCon Berlin 2016 - Symfony Plugin for PhpStorm - 3 years later
SymfonyCon Berlin 2016 - Symfony Plugin for PhpStorm - 3 years later
 
Extend sdk
Extend sdkExtend sdk
Extend sdk
 
#31.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_스프링프레임워크 강좌, 재직자환급교육,실업자국비지원...
#31.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_스프링프레임워크 강좌, 재직자환급교육,실업자국비지원...#31.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_스프링프레임워크 강좌, 재직자환급교육,실업자국비지원...
#31.스프링프레임워크 & 마이바티스 (Spring Framework, MyBatis)_스프링프레임워크 강좌, 재직자환급교육,실업자국비지원...
 
Developing New Widgets for your Views in Owl
Developing New Widgets for your Views in OwlDeveloping New Widgets for your Views in Owl
Developing New Widgets for your Views in Owl
 
Matters of State
Matters of StateMatters of State
Matters of State
 
Curso Symfony - Clase 2
Curso Symfony - Clase 2Curso Symfony - Clase 2
Curso Symfony - Clase 2
 
Eclipse Tricks
Eclipse TricksEclipse Tricks
Eclipse Tricks
 
Design how your objects talk through mocking
Design how your objects talk through mockingDesign how your objects talk through mocking
Design how your objects talk through mocking
 
OSCON Google App Engine Codelab - July 2010
OSCON Google App Engine Codelab - July 2010OSCON Google App Engine Codelab - July 2010
OSCON Google App Engine Codelab - July 2010
 
Curso Symfony - Clase 4
Curso Symfony - Clase 4Curso Symfony - Clase 4
Curso Symfony - Clase 4
 
React & Redux for noobs
React & Redux for noobsReact & Redux for noobs
React & Redux for noobs
 

Viewers also liked

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
TomAuger
 
WordPress Coding Standards & WP Hooks
WordPress Coding Standards & WP HooksWordPress Coding Standards & WP Hooks
WordPress Coding Standards & WP Hooks
Eunus Hosen
 
WordPress pizza sessie
WordPress pizza sessieWordPress pizza sessie
WordPress pizza sessie
Barry Kooij
 
WordPress hooks - WPLDN July 2013 Meetup
WordPress hooks - WPLDN July 2013 MeetupWordPress hooks - WPLDN July 2013 Meetup
WordPress hooks - WPLDN July 2013 Meetupl3rady
 
Hooks WCSD12
Hooks WCSD12Hooks WCSD12
Hooks WCSD12
Jeffrey Zinn
 
Let’s write a plugin
Let’s write a pluginLet’s write a plugin
Let’s write a pluginBrian Layman
 
Intro to Php Security
Intro to Php SecurityIntro to Php Security
Intro to Php Security
Dave Ross
 
Magento eCommerce And The Next Generation Of PHP
Magento eCommerce And The Next Generation Of PHPMagento eCommerce And The Next Generation Of PHP
Magento eCommerce And The Next Generation Of PHP
varien
 
PHP Security
PHP SecurityPHP Security
PHP Security
manugoel2003
 
Best PHP Frameworks
Best PHP FrameworksBest PHP Frameworks
Best PHP Frameworks
Clixlogix Technologies
 
Web Application Security with PHP
Web Application Security with PHPWeb Application Security with PHP
Web Application Security with PHP
jikbal
 
Designing WordPress - Heart&Sole2011
Designing WordPress - Heart&Sole2011Designing WordPress - Heart&Sole2011
Designing WordPress - Heart&Sole2011
John O'Nolan
 

Viewers also liked (12)

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
 
WordPress Coding Standards & WP Hooks
WordPress Coding Standards & WP HooksWordPress Coding Standards & WP Hooks
WordPress Coding Standards & WP Hooks
 
WordPress pizza sessie
WordPress pizza sessieWordPress pizza sessie
WordPress pizza sessie
 
WordPress hooks - WPLDN July 2013 Meetup
WordPress hooks - WPLDN July 2013 MeetupWordPress hooks - WPLDN July 2013 Meetup
WordPress hooks - WPLDN July 2013 Meetup
 
Hooks WCSD12
Hooks WCSD12Hooks WCSD12
Hooks WCSD12
 
Let’s write a plugin
Let’s write a pluginLet’s write a plugin
Let’s write a plugin
 
Intro to Php Security
Intro to Php SecurityIntro to Php Security
Intro to Php Security
 
Magento eCommerce And The Next Generation Of PHP
Magento eCommerce And The Next Generation Of PHPMagento eCommerce And The Next Generation Of PHP
Magento eCommerce And The Next Generation Of PHP
 
PHP Security
PHP SecurityPHP Security
PHP Security
 
Best PHP Frameworks
Best PHP FrameworksBest PHP Frameworks
Best PHP Frameworks
 
Web Application Security with PHP
Web Application Security with PHPWeb Application Security with PHP
Web Application Security with PHP
 
Designing WordPress - Heart&Sole2011
Designing WordPress - Heart&Sole2011Designing WordPress - Heart&Sole2011
Designing WordPress - Heart&Sole2011
 

Similar to WordPress plugin #2

Demystifying Hooks, Actions & Filters - WordCamp Belfast 2018
Demystifying Hooks, Actions & Filters - WordCamp Belfast 2018Demystifying Hooks, Actions & Filters - WordCamp Belfast 2018
Demystifying Hooks, Actions & Filters - WordCamp Belfast 2018
Damien Carbery
 
WordPress Structure and Best Practices
WordPress Structure and Best PracticesWordPress Structure and Best Practices
WordPress Structure and Best Practices
markparolisi
 
Plug in development
Plug in developmentPlug in development
Plug in developmentLucky Ali
 
WordPress plugin #1
WordPress plugin #1WordPress plugin #1
WordPress plugin #1
giwoolee
 
Write your first WordPress plugin
Write your first WordPress pluginWrite your first WordPress plugin
Write your first WordPress pluginAnthony Montalbano
 
My first WordPress Plugin
My first WordPress PluginMy first WordPress Plugin
My first WordPress Plugin
Abbas Siddiqi
 
How To Write a WordPress Plugin
How To Write a WordPress PluginHow To Write a WordPress Plugin
How To Write a WordPress Plugin
Andy Stratton
 
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
Rakesh Kushwaha
 
WordPress Plugin Basics
WordPress Plugin BasicsWordPress Plugin Basics
WordPress Plugin Basics
Amanda Giles
 
Stop Hacking WordPress, Start Working with it - Charly Leetham - WordCamp Syd...
Stop Hacking WordPress, Start Working with it - Charly Leetham - WordCamp Syd...Stop Hacking WordPress, Start Working with it - Charly Leetham - WordCamp Syd...
Stop Hacking WordPress, Start Working with it - Charly Leetham - WordCamp Syd...
WordCamp Sydney
 
Ruby on rails
Ruby on rails Ruby on rails
Ruby on rails
Mohit Jain
 
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)arcware
 
WordPress Plugin development
WordPress Plugin developmentWordPress Plugin development
WordPress Plugin development
Mostafa Soufi
 
WordPress Hooks Action & Filters
WordPress Hooks Action & FiltersWordPress Hooks Action & Filters
WordPress Hooks Action & Filters
Nirav Mehta
 
Intro to WordPress Plugin Development
Intro to WordPress Plugin DevelopmentIntro to WordPress Plugin Development
Intro to WordPress Plugin Development
Brad Williams
 
Word press Plugins by WordPress Experts
Word press Plugins by WordPress ExpertsWord press Plugins by WordPress Experts
Word press Plugins by WordPress Experts
Yameen Khan
 
WordPress Plugins
WordPress PluginsWordPress Plugins
Working With The Symfony Admin Generator
Working With The Symfony Admin GeneratorWorking With The Symfony Admin Generator
Working With The Symfony Admin Generator
John Cleveley
 
Magento++
Magento++Magento++
Creating Your First WordPress Plugin
Creating Your First WordPress PluginCreating Your First WordPress Plugin
Creating Your First WordPress Plugin
Brad Williams
 

Similar to WordPress plugin #2 (20)

Demystifying Hooks, Actions & Filters - WordCamp Belfast 2018
Demystifying Hooks, Actions & Filters - WordCamp Belfast 2018Demystifying Hooks, Actions & Filters - WordCamp Belfast 2018
Demystifying Hooks, Actions & Filters - WordCamp Belfast 2018
 
WordPress Structure and Best Practices
WordPress Structure and Best PracticesWordPress Structure and Best Practices
WordPress Structure and Best Practices
 
Plug in development
Plug in developmentPlug in development
Plug in development
 
WordPress plugin #1
WordPress plugin #1WordPress plugin #1
WordPress plugin #1
 
Write your first WordPress plugin
Write your first WordPress pluginWrite your first WordPress plugin
Write your first WordPress plugin
 
My first WordPress Plugin
My first WordPress PluginMy first WordPress Plugin
My 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
 
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
 
WordPress Plugin Basics
WordPress Plugin BasicsWordPress Plugin Basics
WordPress Plugin Basics
 
Stop Hacking WordPress, Start Working with it - Charly Leetham - WordCamp Syd...
Stop Hacking WordPress, Start Working with it - Charly Leetham - WordCamp Syd...Stop Hacking WordPress, Start Working with it - Charly Leetham - WordCamp Syd...
Stop Hacking WordPress, Start Working with it - Charly Leetham - WordCamp Syd...
 
Ruby on rails
Ruby on rails Ruby on rails
Ruby on rails
 
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)
 
WordPress Plugin development
WordPress Plugin developmentWordPress Plugin development
WordPress Plugin development
 
WordPress Hooks Action & Filters
WordPress Hooks Action & FiltersWordPress Hooks Action & Filters
WordPress Hooks Action & Filters
 
Intro to WordPress Plugin Development
Intro to WordPress Plugin DevelopmentIntro to WordPress Plugin Development
Intro to WordPress Plugin Development
 
Word press Plugins by WordPress Experts
Word press Plugins by WordPress ExpertsWord press Plugins by WordPress Experts
Word press Plugins by WordPress Experts
 
WordPress Plugins
WordPress PluginsWordPress Plugins
WordPress Plugins
 
Working With The Symfony Admin Generator
Working With The Symfony Admin GeneratorWorking With The Symfony Admin Generator
Working With The Symfony Admin Generator
 
Magento++
Magento++Magento++
Magento++
 
Creating Your First WordPress Plugin
Creating Your First WordPress PluginCreating Your First WordPress Plugin
Creating Your First WordPress Plugin
 

Recently uploaded

Italy Agriculture Equipment Market Outlook to 2027
Italy Agriculture Equipment Market Outlook to 2027Italy Agriculture Equipment Market Outlook to 2027
Italy Agriculture Equipment Market Outlook to 2027
harveenkaur52
 
一比一原版(CSU毕业证)加利福尼亚州立大学毕业证成绩单专业办理
一比一原版(CSU毕业证)加利福尼亚州立大学毕业证成绩单专业办理一比一原版(CSU毕业证)加利福尼亚州立大学毕业证成绩单专业办理
一比一原版(CSU毕业证)加利福尼亚州立大学毕业证成绩单专业办理
ufdana
 
假文凭国外(Adelaide毕业证)澳大利亚国立大学毕业证成绩单办理
假文凭国外(Adelaide毕业证)澳大利亚国立大学毕业证成绩单办理假文凭国外(Adelaide毕业证)澳大利亚国立大学毕业证成绩单办理
假文凭国外(Adelaide毕业证)澳大利亚国立大学毕业证成绩单办理
cuobya
 
Search Result Showing My Post is Now Buried
Search Result Showing My Post is Now BuriedSearch Result Showing My Post is Now Buried
Search Result Showing My Post is Now Buried
Trish Parr
 
guildmasters guide to ravnica Dungeons & Dragons 5...
guildmasters guide to ravnica Dungeons & Dragons 5...guildmasters guide to ravnica Dungeons & Dragons 5...
guildmasters guide to ravnica Dungeons & Dragons 5...
Rogerio Filho
 
Internet of Things in Manufacturing: Revolutionizing Efficiency & Quality | C...
Internet of Things in Manufacturing: Revolutionizing Efficiency & Quality | C...Internet of Things in Manufacturing: Revolutionizing Efficiency & Quality | C...
Internet of Things in Manufacturing: Revolutionizing Efficiency & Quality | C...
CIOWomenMagazine
 
Meet up Milano 14 _ Axpo Italia_ Migration from Mule3 (On-prem) to.pdf
Meet up Milano 14 _ Axpo Italia_ Migration from Mule3 (On-prem) to.pdfMeet up Milano 14 _ Axpo Italia_ Migration from Mule3 (On-prem) to.pdf
Meet up Milano 14 _ Axpo Italia_ Migration from Mule3 (On-prem) to.pdf
Florence Consulting
 
7 Best Cloud Hosting Services to Try Out in 2024
7 Best Cloud Hosting Services to Try Out in 20247 Best Cloud Hosting Services to Try Out in 2024
7 Best Cloud Hosting Services to Try Out in 2024
Danica Gill
 
test test test test testtest test testtest test testtest test testtest test ...
test test  test test testtest test testtest test testtest test testtest test ...test test  test test testtest test testtest test testtest test testtest test ...
test test test test testtest test testtest test testtest test testtest test ...
Arif0071
 
Bài tập unit 1 English in the world.docx
Bài tập unit 1 English in the world.docxBài tập unit 1 English in the world.docx
Bài tập unit 1 English in the world.docx
nhiyenphan2005
 
一比一原版(LBS毕业证)伦敦商学院毕业证成绩单专业办理
一比一原版(LBS毕业证)伦敦商学院毕业证成绩单专业办理一比一原版(LBS毕业证)伦敦商学院毕业证成绩单专业办理
一比一原版(LBS毕业证)伦敦商学院毕业证成绩单专业办理
eutxy
 
2.Cellular Networks_The final stage of connectivity is achieved by segmenting...
2.Cellular Networks_The final stage of connectivity is achieved by segmenting...2.Cellular Networks_The final stage of connectivity is achieved by segmenting...
2.Cellular Networks_The final stage of connectivity is achieved by segmenting...
JeyaPerumal1
 
1比1复刻(bath毕业证书)英国巴斯大学毕业证学位证原版一模一样
1比1复刻(bath毕业证书)英国巴斯大学毕业证学位证原版一模一样1比1复刻(bath毕业证书)英国巴斯大学毕业证学位证原版一模一样
1比1复刻(bath毕业证书)英国巴斯大学毕业证学位证原版一模一样
3ipehhoa
 
APNIC Foundation, presented by Ellisha Heppner at the PNG DNS Forum 2024
APNIC Foundation, presented by Ellisha Heppner at the PNG DNS Forum 2024APNIC Foundation, presented by Ellisha Heppner at the PNG DNS Forum 2024
APNIC Foundation, presented by Ellisha Heppner at the PNG DNS Forum 2024
APNIC
 
重新申请毕业证书(RMIT毕业证)皇家墨尔本理工大学毕业证成绩单精仿办理
重新申请毕业证书(RMIT毕业证)皇家墨尔本理工大学毕业证成绩单精仿办理重新申请毕业证书(RMIT毕业证)皇家墨尔本理工大学毕业证成绩单精仿办理
重新申请毕业证书(RMIT毕业证)皇家墨尔本理工大学毕业证成绩单精仿办理
vmemo1
 
How to Use Contact Form 7 Like a Pro.pptx
How to Use Contact Form 7 Like a Pro.pptxHow to Use Contact Form 7 Like a Pro.pptx
How to Use Contact Form 7 Like a Pro.pptx
Gal Baras
 
JAVIER LASA-EXPERIENCIA digital 1986-2024.pdf
JAVIER LASA-EXPERIENCIA digital 1986-2024.pdfJAVIER LASA-EXPERIENCIA digital 1986-2024.pdf
JAVIER LASA-EXPERIENCIA digital 1986-2024.pdf
Javier Lasa
 
Bridging the Digital Gap Brad Spiegel Macon, GA Initiative.pptx
Bridging the Digital Gap Brad Spiegel Macon, GA Initiative.pptxBridging the Digital Gap Brad Spiegel Macon, GA Initiative.pptx
Bridging the Digital Gap Brad Spiegel Macon, GA Initiative.pptx
Brad Spiegel Macon GA
 
急速办(bedfordhire毕业证书)英国贝德福特大学毕业证成绩单原版一模一样
急速办(bedfordhire毕业证书)英国贝德福特大学毕业证成绩单原版一模一样急速办(bedfordhire毕业证书)英国贝德福特大学毕业证成绩单原版一模一样
急速办(bedfordhire毕业证书)英国贝德福特大学毕业证成绩单原版一模一样
3ipehhoa
 
可查真实(Monash毕业证)西澳大学毕业证成绩单退学买
可查真实(Monash毕业证)西澳大学毕业证成绩单退学买可查真实(Monash毕业证)西澳大学毕业证成绩单退学买
可查真实(Monash毕业证)西澳大学毕业证成绩单退学买
cuobya
 

Recently uploaded (20)

Italy Agriculture Equipment Market Outlook to 2027
Italy Agriculture Equipment Market Outlook to 2027Italy Agriculture Equipment Market Outlook to 2027
Italy Agriculture Equipment Market Outlook to 2027
 
一比一原版(CSU毕业证)加利福尼亚州立大学毕业证成绩单专业办理
一比一原版(CSU毕业证)加利福尼亚州立大学毕业证成绩单专业办理一比一原版(CSU毕业证)加利福尼亚州立大学毕业证成绩单专业办理
一比一原版(CSU毕业证)加利福尼亚州立大学毕业证成绩单专业办理
 
假文凭国外(Adelaide毕业证)澳大利亚国立大学毕业证成绩单办理
假文凭国外(Adelaide毕业证)澳大利亚国立大学毕业证成绩单办理假文凭国外(Adelaide毕业证)澳大利亚国立大学毕业证成绩单办理
假文凭国外(Adelaide毕业证)澳大利亚国立大学毕业证成绩单办理
 
Search Result Showing My Post is Now Buried
Search Result Showing My Post is Now BuriedSearch Result Showing My Post is Now Buried
Search Result Showing My Post is Now Buried
 
guildmasters guide to ravnica Dungeons & Dragons 5...
guildmasters guide to ravnica Dungeons & Dragons 5...guildmasters guide to ravnica Dungeons & Dragons 5...
guildmasters guide to ravnica Dungeons & Dragons 5...
 
Internet of Things in Manufacturing: Revolutionizing Efficiency & Quality | C...
Internet of Things in Manufacturing: Revolutionizing Efficiency & Quality | C...Internet of Things in Manufacturing: Revolutionizing Efficiency & Quality | C...
Internet of Things in Manufacturing: Revolutionizing Efficiency & Quality | C...
 
Meet up Milano 14 _ Axpo Italia_ Migration from Mule3 (On-prem) to.pdf
Meet up Milano 14 _ Axpo Italia_ Migration from Mule3 (On-prem) to.pdfMeet up Milano 14 _ Axpo Italia_ Migration from Mule3 (On-prem) to.pdf
Meet up Milano 14 _ Axpo Italia_ Migration from Mule3 (On-prem) to.pdf
 
7 Best Cloud Hosting Services to Try Out in 2024
7 Best Cloud Hosting Services to Try Out in 20247 Best Cloud Hosting Services to Try Out in 2024
7 Best Cloud Hosting Services to Try Out in 2024
 
test test test test testtest test testtest test testtest test testtest test ...
test test  test test testtest test testtest test testtest test testtest test ...test test  test test testtest test testtest test testtest test testtest test ...
test test test test testtest test testtest test testtest test testtest test ...
 
Bài tập unit 1 English in the world.docx
Bài tập unit 1 English in the world.docxBài tập unit 1 English in the world.docx
Bài tập unit 1 English in the world.docx
 
一比一原版(LBS毕业证)伦敦商学院毕业证成绩单专业办理
一比一原版(LBS毕业证)伦敦商学院毕业证成绩单专业办理一比一原版(LBS毕业证)伦敦商学院毕业证成绩单专业办理
一比一原版(LBS毕业证)伦敦商学院毕业证成绩单专业办理
 
2.Cellular Networks_The final stage of connectivity is achieved by segmenting...
2.Cellular Networks_The final stage of connectivity is achieved by segmenting...2.Cellular Networks_The final stage of connectivity is achieved by segmenting...
2.Cellular Networks_The final stage of connectivity is achieved by segmenting...
 
1比1复刻(bath毕业证书)英国巴斯大学毕业证学位证原版一模一样
1比1复刻(bath毕业证书)英国巴斯大学毕业证学位证原版一模一样1比1复刻(bath毕业证书)英国巴斯大学毕业证学位证原版一模一样
1比1复刻(bath毕业证书)英国巴斯大学毕业证学位证原版一模一样
 
APNIC Foundation, presented by Ellisha Heppner at the PNG DNS Forum 2024
APNIC Foundation, presented by Ellisha Heppner at the PNG DNS Forum 2024APNIC Foundation, presented by Ellisha Heppner at the PNG DNS Forum 2024
APNIC Foundation, presented by Ellisha Heppner at the PNG DNS Forum 2024
 
重新申请毕业证书(RMIT毕业证)皇家墨尔本理工大学毕业证成绩单精仿办理
重新申请毕业证书(RMIT毕业证)皇家墨尔本理工大学毕业证成绩单精仿办理重新申请毕业证书(RMIT毕业证)皇家墨尔本理工大学毕业证成绩单精仿办理
重新申请毕业证书(RMIT毕业证)皇家墨尔本理工大学毕业证成绩单精仿办理
 
How to Use Contact Form 7 Like a Pro.pptx
How to Use Contact Form 7 Like a Pro.pptxHow to Use Contact Form 7 Like a Pro.pptx
How to Use Contact Form 7 Like a Pro.pptx
 
JAVIER LASA-EXPERIENCIA digital 1986-2024.pdf
JAVIER LASA-EXPERIENCIA digital 1986-2024.pdfJAVIER LASA-EXPERIENCIA digital 1986-2024.pdf
JAVIER LASA-EXPERIENCIA digital 1986-2024.pdf
 
Bridging the Digital Gap Brad Spiegel Macon, GA Initiative.pptx
Bridging the Digital Gap Brad Spiegel Macon, GA Initiative.pptxBridging the Digital Gap Brad Spiegel Macon, GA Initiative.pptx
Bridging the Digital Gap Brad Spiegel Macon, GA Initiative.pptx
 
急速办(bedfordhire毕业证书)英国贝德福特大学毕业证成绩单原版一模一样
急速办(bedfordhire毕业证书)英国贝德福特大学毕业证成绩单原版一模一样急速办(bedfordhire毕业证书)英国贝德福特大学毕业证成绩单原版一模一样
急速办(bedfordhire毕业证书)英国贝德福特大学毕业证成绩单原版一模一样
 
可查真实(Monash毕业证)西澳大学毕业证成绩单退学买
可查真实(Monash毕业证)西澳大学毕业证成绩单退学买可查真实(Monash毕业证)西澳大学毕业证成绩单退学买
可查真实(Monash毕业证)西澳大学毕业证成绩单退学买
 

WordPress plugin #2

  • 1. WordPress Plugin #2 May 14th, 2015 Changwoo
  • 2. Today’s Topics 1.Hooks in Nutshell 2.Database Tables in Nutshell
  • 3. Recap - Your first plugin - Hello Dolly plugin - action, and callback
  • 4. Recap Plugin Header: /* Plugin Name: Hello Dolly Plugin URI: http://wordpress.org/plugins/hello-dolly/ Description: This is not just a plugin, it symbolizes the hope and enthusiasm of an entire generation summed up in two words sung most famously by Louis Armstrong: Hello, Dolly. When activated you will randomly see a lyric from <cite>Hello, Dolly</cite> in the upper right of your admin screen on every page. Author: Matt Mullenweg Version: 1.6 Author URI: http://ma.tt/ */
  • 5. Recap Callback Mechanism: add_action( ‘admin_notices’, ‘hello_dolly’ ); function hello_dolly() { ... } Name of hook Callback function WP function for hook
  • 6. Recap Planning your own plugin, and ... submission!
  • 8. Hook: an Event Plugin programming: - Hook-driven programming. - A hook means an event.
  • 9. Hello dolly’s case 2 actions: admin_notices, admin_head ● admin_notices codex ● admin_head codex
  • 10. Hello dolly’s case 2 actions: admin_notices, admin_head Let’s find source code. $ fgrep -Rn do_action( 'admin_notices' ) * wp-admin/admin-header.php:238: do_action( 'admin_notices' ); $ fgrep -Rn do_action( 'admin_head' ) * wp-admin/includes/media.php:491: do_action( 'admin_head' ); wp-admin/includes/template.php:1627:do_action( 'admin_head' ); wp-admin/includes/class-wp-press-this.php:1267: do_action( 'admin_head' ); wp-admin/admin-header.php:125:do_action( 'admin_head' ); show source codes
  • 11. Hook interface wp-includes/plugin.php What is action? What is filter? ● add_filter() ● has_filter() ● apply_filters() ● add_action() ● has_action() ● do_action()
  • 12. Task Separation Themes: visual part Plugins: functional part Actions: structural part Filters: information part
  • 13. Task Separation Q. I want to add extra contents to every post to be displayed. Which one do I have to use? Q. I want to a add menu page to admin page. Which one? Q. I want to customize the table columns of pages screen. Q. I want to do something when a post is updated.
  • 14. Task Separation (solution) Q. I want to add extra contents to every post to be displayed. Which one do I have to use? Q. I want to a add menu page to admin page. Which one? Q. I want to customize the table columns of pages screen. Q. I want to do something when a post is updated. A. filter. ‘the_content’ hook. A. action. ‘admin_menu’ hook. A. filter. ‘manage_pages_columns’ hook. A. action. ‘post_updated’ hook.
  • 15. Task separation Do not have to remember them all. Moreover, actually, add_action == add_filter
  • 16. Action, Filter definition wp-includes/plugin.php function add_action($tag, $function_to_add, $priority = 10, $accepted_args = 1) { return add_filter($tag, $function_to_add, $priority, $accepted_args); } add_action() is mere an alias of add_filter() Then, why add_action() is created? Because they want to get more detailed code. They just wanted detailed conception. That’s cool.
  • 17. do_action, add_action feedback do_action: fires registered action add_action: loads any actions No restriction. you can define your own hooks.
  • 20. callback functions... .... .. . my_hook - my_callback $wp_filter add_action( ‘my_hook’, ‘my_callback’, 10, 1 );
  • 21. callback functions... .... .. . my_hook - my_callback $wp_filter add_action( ‘my_hook’, ‘my_callback’, 10, 1 ); somewhere in your code ... do_action( ‘my_hook’ ); ...
  • 22. callback functions... .... .. . my_hook - my_callback $wp_filter add_action( ‘my_hook’, ‘my_callback’, 10, 1 ); somewhere in your code ... do_action( ‘my_hook’ ); ...
  • 23. callback functions... .... .. . my_hook - my_callback $wp_filter add_action( ‘my_hook’, ‘my_callback’, 10, 1 ); somewhere in your code ... do_action( ‘my_hook’ ); ... by my_hook: my_callback()
  • 24. do_action inside of do_action: ● retrieve the callback functions by their tags (hook) ● sort by priority ● call_user_func() do { foreach ( (array) current($wp_filter[$tag]) as $the_ ) if ( !is_null($the_['function']) ) call_user_func_array($the_['function'], array_slice($args, 0, (int) $the_['accepted_args'])); } while ( next($wp_filter[$tag]) !== false );
  • 25. add_action function add_filter( $tag, $function_to_add, $priority = 10, $accepted_args = 1 ) { global $wp_filter, $merged_filters; $idx = _wp_filter_build_unique_id($tag, $function_to_add, $priority); $wp_filter[$tag][$priority][$idx] = array('function' => $function_to_add, 'accepted_args' => $accepted_args); unset( $merged_filters[ $tag ] ); return true; } $wp_filter is an array.
  • 26. Check it out! Build a plugin that dumps all registered actions or filters. Add your own hook and call it. Download template code and edit. http://<myip>/wp-admin/ (meetup / 1) ftp://<myip> (meetup / 1)
  • 27. Summary ● filter and action are the same. action is alias. o structure, data separation ● In fact, this is like a fine wrapper for call_user_func. o do_action() fires callback functions when the hook is available o add_action() loads callback functions. ● There are huge amount of hooks: see reference. ● You can also define your own hooks.
  • 28. Database Tables in Nutshell
  • 29. Database: the Root Database: backbone of web apps. A good app without understanding its db structure: just an illusion.
  • 30. Database description https://codex.wordpress.org/Database_Description ● parent - meta styles o wp_comments - wp_commentmeta o wp_user - wp_usermeta o wp_posts - wp_postmeta o wp_options ● wp_terms - wp_term_taxonomy - wp_term_relationships
  • 31. Meta table Every *meta table has ● meta_key ● meta_value closely related to “hashing”
  • 36. Hashing key - value pair. key is short / value is often long. key is searchable. Hashing often called (implemented) as “dictionary”, or “associative array”.
  • 37. Meta key: benefits Flexible, extendable Ordinary tables can’t do these: ● Creating fields “on demands” ● This is one reason why WordPress is a very versaitle, general, and easy-to-customize CMS.
  • 38. Meta key sample: user info You want to add “Kakaotalk ID” for every user: just add “kakaotalk_id” meta key.
  • 39. Meta in edit screen
  • 40. Does it matter? Yes! When fresh install, WordPress: 11+ tables 74 tables 49 tables 79 tables Jomla: Drupal: XpressEngine:
  • 41. Meta key: Hazards No type checking, validation Meta key consistency Efficiency Nothing is perfect! next: terms, taxonomies, ...
  • 42. Terms and Taxonomies Terms: a word Taxonomy: classification of terms
  • 43. Terms and Taxonomies iron ?? Home appliance Metal ???
  • 44. Adding Terms in Posts Posts have basically two taxonomies: ● tags ● categories Adding tag/category = adding term
  • 45. Adding Terms in Posts <terms> term_id: 2 name: MyCategory slug: my-category term_group: 0
  • 46. Adding Terms in Posts <term_taxonomy> term_taxonomy_id: 2 term_id: 2 taxonomy: category / post_tag description: parent: 0 count: 0
  • 48. Post ID: 75 term_relationships.object_id term_relationships.term_taxonomy_id
  • 49. Post ID: 75 term_relationships.object_id term_relationships.term_taxonomy_id
  • 50. Post ID: 75 term_relationships.object_id term_relationships.term_taxonomy_id term_taxonomy.term_taxonomy_id term_taxonomy.term_id term_taxonomy.taxonomy ★
  • 51. Post ID: 75 term_relationships.object_id term_relationships.term_taxonomy_id term_taxonomy.term_taxonomy_id term_taxonomy.term_id term_taxonomy.taxonomy ★
  • 52. Post ID: 75 term_relationships.object_id term_relationships.term_taxonomy_id terms.term_id terms.name ★ terms.slug term_taxonomy.term_taxonomy_id term_taxonomy.term_id term_taxonomy.taxonomy ★
  • 53. Post ID: 75 term_relationships.object_id term_relationships.term_taxonomy_id terms.term_id terms.name ★ terms.slug term_taxonomy.term_taxonomy_id term_taxonomy.term_id term_taxonomy.taxonomy ★
  • 54. Initial Taxonomies < wp-includes/taxonomy.php > function register_taxonomy( $taxonomy, $object_type, $args = array() ) { ... } function create_initial_taxonomies() { register_taxonomy( 'category', 'post', array(...) ); register_taxonomy( 'post_tag', 'post', array(...) ); ... and so on ... create_initial_taxonomies() is called in wp-settings.php
  • 55. Summary ● Wordpress Datbase table uses metadata style strategy ● meta tables have key / value fields o flexible, easy to extend o while it can have some disadvantages
  • 56. Summary ● Taxonomy: classification of term ● You can add taxonomies (as well as terms) ● Taxonomy can be flat or hierarchical ● term_taxonomy: taxonomy - term ● term_relationship: posts - taxonomy
  • 57. Next week Admin Menu ● Almost every plugin has its menu ● Easy WP Plugin API Admin Post ● POST type data submission URL Query AJAX Data handling Wordpress Posts in Nutshell