Documente Academic
Documente Profesional
Documente Cultură
Plugin Development
Aizat Faiz aizat.faiz@gmail.com
Creative Commons
http://www.flickr.com/photos/kwl/4435490471/
By Attribution
http://www.flickr.com/photos/balakov/4571468943/
Aizat Faiz
aizat.faiz@gmail.com
http://www.flickr.com/photos/byte/3397174843/
WordPress Codex
http://codex.wordpress.org
http://www.google.com.my
What is a Hook?
http://www.flickr.com/photos/kwl/4247555680/
http://www.flickr.com/photos/kwl/4247555680/
http://www.flickr.com/photos/sixteen-miles/3757674953/
http://www.flickr.com/photos/linuxmatt/92802487/
Actions
Filters
Actions
Actions
Actions
Actions = Do Something
Filters
Filters
Filters are
Filters
Filters = Transform
Actions = Do Something
Filters = Transform
1133
1133
hooks
* as of WordPress v2.9
Problem:
Finding the Right Hook for the Right Job
Hard to Recommend
WordPress Codex
http://codex.wordpress.org/Plugin_API/Action_Reference
http://codex.wordpress.org/Plugin_API/Filter_Reference
Your Plugin:
/wp-content/plugins/my-plugin
Inside my-plugin
readme.txt
screenshot-1.png
my-plugin.php
readme.txt
screenshot-1.png
my-plugin.php
Your Plugin Code
4 parts to a plugin
Plugin Header
Hooks
PHP Code
Template Code
File Structure
Plugin Headers
http://codex.wordpress.org/Writing_a_Plugin#Standard_Plugin_Information
Plugin Headers
http://codex.wordpress.org/Writing_a_Plugin#Standard_Plugin_Information
Hooks (Filters)
Hooks (Filters)
PHP Code
Plugin 1
Figure out what you want to do.
the_content (filter)
http://codex.wordpress.org/Plugin_API/Filter_Reference/the_content
add_filter
http://codex.wordpress.org/Plugin_API/Filter_Reference/the_content
add_filter
Hook Name
Callback
http://codex.wordpress.org/Plugin_API#Hook_to_WordPress
Hook Callback
String; or
Hook Callback
String
Calls a function
Array of 2 strings
return
transformation
http://php.net/manual/en/function.preg-replace.php
Plugin 2
Figure out what you want to do.
Hook Priority
http://codex.wordpress.org/Plugin_API#Hook_to_WordPress
Priority
Hook Name
Callback
Priority
(optional)
http://codex.wordpress.org/Plugin_API#Hook_to_WordPress
WordPress2WORDPRESS#the_content
Default Priority
10
smaller numbers = higher priority
larger numbers = lower priority
http://codex.wordpress.org/Plugin_API#Hook_to_WordPress
Therefore
Order of execution:
(10) WordPress2WORDPRESS#the_content
(20) ABolderWordPress#the_content
Plugin 3
Figure out what you want to do.
I want to add a class,
to represent a post
that has more than 10 comments
accepted_args
http://codex.wordpress.org/Plugin_API#Hook_to_WordPress
accepted_args
Hook Name
Callback
Priority
accepted_args
Plugin 4
Figure out what you want to do.
I want to add a
custom stylesheet
init (action)
http://codex.wordpress.org/Plugin_API#Hook_to_WordPress
wp_enqueue_style
WordPress function
Style ID
Style URL
http://codex.wordpress.org/Function_Reference/wp_enqueue_style
Actions Do Something
Actions
Filters
Actions
Actions = Do Something
Filters
Filters = Transform
Actions = Do Something
Filters = Transform
MOAR KITTEHS
kthxbai
Beginning WordPress
Plugin Development
Aizat Faiz aizat.faiz@gmail.com
http://blog.aizatto.com/?p=3729