3. Reference Book
Professional WordPress Plugin Development
Brad Williams, Ozh Richard, Justin Tadlock
ISBN: 978-0-470-91622-3
Paperback
552 pages
March 2011
4. Introducing WP Plugin
Plug-in or add-in:
an software to add
a specific feature to
an existing software.
Everyone knows it.
8. Requirement
1.PHP 5.4+ programming skill
2.Knowledge of MySQL database
server:
a. You should understand WPDB structure
3.HTML, Javascript, CSS:
a. You need to take care of client side
16. Basic: functions
(option) type hinting is available
(not for scalars: int, bool, string, ...)
function foo(array $x) {
...
}
foo(array()); // OK
foo(5); // ERROR
foo(NULL); // ERROR
17. Advanced: class
Functions are not enough.
You will need more advanced
programmaing techniques.
Q. Do you know what is “class”?
Q. Then, what is “object”
22. Class: a service plan
class Car {
public $name;
public $max_speed;
public $color;
private $cost;
public function honk() { … }
private function engine_ignite() {
...
}
}
23. Class: a service plan
class Car {
public $name;
public $max_speed;
public $color;
private $cost;
public function honk() { … }
private function engine_ignite() {
...
}
}
24. Class: a service plan
class Car {
public $name;
public $max_speed;
public $color;
private $cost;
public function honk() { … }
private function engine_ignite() {
...
}
}
25. Why class?
● Easily modularized
● Can be extended
o DRY: Don’t Repeat Yourself
27. Class in Modern Programming
Class is important to modern
programming, OOP.
Almost all advanced topics are
closely related to classes.
next, cb func.
28. Callback function
Plugins extend WordPress.
- Plugins do extra tasks for core.
- Core runs plugins.
- So there will be a ‘protocol’.
29. Callback function
Imagine the protocol
- Wordpress core knows every
possible situation.
- But the detail has not been known
exactly
30. Callback function
- So plugins throw “to do list” to
the core.
- Then core runs as the list says.
TO-DO LIST: callback function
33. Environment setting
We all must in the same AP.
Add a line below to /etc/hosts:
<ip> wp-meetup
Check http://wp-meetup/ is valid, and you can login as
guest/guest.
Check ftp://wp-meetup is valid.
You can login as meetup/1.
You an upload your plugin here.
34. Hello, World! Plugin
Create your first plugin!
1. create a plugin directory “hello-world-<your-name>”
2. in the directory, create main file:
hello-world.php
3. Add file header and edit it!
4. Upload your plugin directory to wp-meetup via FTP
5. Access http://wp-meetup, login, and check out your
fresh plugin.
36. /*
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/
*/
37. There are just 3 function definitions and 2 add_action()
calls:
● hello_dolly_get_lyric(): get any random lyric
● dolly_css(): callback. add style tag
● hello_dolly(): callback of admin_notices.
● add_action( 'admin_notices', 'hello_dolly' );
● add_action( 'admin_head', 'dolly_css' );