an easy start guide for
Plugin Development
WordPress Meet-up!
on 2014/05/29!
in Bangkok, Thailand!
by Shinichi Nishikawa
about Me
❖ ผมชื่อชิน (Shinichi Nishikawa)!
❖ อยู่ที่กรุงเทพฯปีครึ่ง
Lived in Bangkok for half a year!
❖ สร้าง themes และ plugin ให้ลูกค้า
Building themes and plugins for customers!
❖ ผมชอบเขียนบล็อก เขียนหนังสือเกี่ยวกับ WordPress และจัด
WordPress Events ที่ญี่ปุ่นด้วย.
I write blogs with WP, I write books of WP, I ran WP events
Challenge
❖ ผมจะสอนวิธีทำpluginอย่างง่าย
I will try to explain how to make plugins as easy as
possible.!
❖ หากคุณมีคำถาม คุณถามได้ทุกเวลา
Don’t hesitate to ask questions any time!!
❖ คุณสามารถดาวน์โหลด presentation และ codesนี้ได้
Presentation and codes online will be uploaded.
Menu
❖ plugin ขั้นพื้นฐาน
Plugin basic!
❖ WordPress ทำงานอย่างไร
How WordPress works!
❖ plugin ทำงานกับ WordPress อย่างไร
How plugins work together with WordPress!
❖ ผมมีตัวอย่างpluginง่ายๆ3แบบ ที่จะทำให้คุณเข้าใจ
You will see 3 example plugins and understand them
After session
❖ คุณสามารถจะทำpluginอย่างง่ายได้
You can make a simple plugin!
❖ คุณจะรู้ว่าpluginทำหน้าที่อะไร
You will know what plugins do!
❖ คุณจะชอบWordPressมากขึ้น
You will be more interested in WordPress core
WordPress Process
request: example.com/category/food
User sees the page.
Get DB info from
wp-config.php
connect to DB
load core functions
load plugins
load functions.php
template file
decided.
(category.php)
query from URL
get post(s)
data from DB
category.php!
header.php
loop
sidebar.php
footer.php
WordPress Process
request: example.com/wp-login.php
User sees the page.
WordPress process
WordPress Processes can be …
!
✓ displaying home page
✓ displaying admin page
✓ displaying login page
✓ or any other things WordPress does
action
❖ Action is to do something.!
✓ to echo something!
✓ to save something!
✓ to redirect somewhere
filter
❖ Filter is to change something!
✓ change original text to your text!
✓ change original html to your html!
✓ change original php values to your values.
How hooks look like
apply_filters( ‘location1’, $value );
do_action( ‘location2’ );
filter hook
action hook
How hooks look like
❖ apply_filters( ‘location_name’, $value );!
❖ do_action( ‘location_name’ );
Plugin Hook Concept
add_filter( ‘location1’, ‘func1’ );
function func1($value){
// make a filter here
return $value
}
add_action( ‘location2’, ‘func2’ );
function func2(){
// do something
}
apply_filters( ‘location1’, $value ); do_action( ‘location2’ );
Plugin Hook Concept
Plugin is a set of add_action() & add_filter()
add_filter( ‘location1’, ‘func1’ );
function func1($value){
// make a filter here
return $value
}
add_action( ‘location2’, ‘func2’ );
function func2(){
// do something
}
apply_filters( ‘location1’, $value ); do_action( ‘location2’ );
Plugin Hook Concept
Large plugins have many functions in them.
apply_filters( ‘location1’, $value ); do_action( ‘location2’ );
ใจเย็นๆ
request: example.com/category/food
User sees the page.
Get DB info from
wp-config.php
connect to DB
load core functions
load plugins
load functions.php
template file
decided.
(category.php)
query from URL
get post(s)
data from DB
category.php!
header.php
loop
sidebar.php
footer.php
wp_head();
wp_footer();
สุภาพ
request: example.com/category/food
User sees the page.
Get DB info from
wp-config.php
connect to DB
load core functions
load plugins
load functions.php
template file
decided.
(category.php)
query from URL
get post(s)
data from DB
category.php!
header.php
loop
sidebar.php
footer.php
apply_filters(
‘the_content’,
$content
);
สบายใจ login
request: example.com/wp-login.php
User sees the page.
check cookies
see ssl
condition
check errors
show logo
& message<html>
</head>
show <form>
do_action(‘login_footer’);
!
in plugin: echo <video>
display login footer
do_action(‘login_head’);
!
in plugin: echo <style>