wordpress plugin development short tutorial
DESCRIPTION
This is an introduction for those who want to start developing plugins for Wordpress blog engineTRANSCRIPT
The first steps…• Pre‐development issues
– Wordpress Plugin Directory– Plugin and File Names– File Headers
• Wordpress Plugin Hooks – Actions – Filters
• Adding data to wordpress database– Creating tables with plugins
• Adding Administration Menus– Creating options page
• “Hello Dolly” example11/10/2008 2
Wordpress Plugin Development ‐ A Short Tutorial
Pre‐development issues (1)Wordpress Plugin Directory
11/10/2008 3Wordpress Plugin Development ‐ A Short
Tutorial
wp‐content plugins your plugin
code
javascript
css
imagesplace your plugin here
Pre‐development issues (2)
11/10/2008Wordpress Plugin Development ‐ A Short
Tutorial4
Plugin and File Names
Choose your plugin’s name carefully. Think about what the plugin will do, and make a, hopefully unique, name for it.
It is good for the names of your php files to be derived from your chosen plugin name.
Pre‐development issues (3)
11/10/2008Wordpress Plugin Development ‐ A Short
Tutorial5
File Headers
Wordpress Plugin Hooks (1)
11/10/2008Wordpress Plugin Development ‐ A Short
Tutorial6
Hooks are provided to allow your plugin to 'hook into' the restof WordPress; that is, to call functions in your plugin at specifictimes, and thereby set your plugin in motion.
Hooks
Wordpress Plugin Hooks (2)
11/10/2008Wordpress Plugin Development ‐ A Short
Tutorial7
Hooks = Actions + Filters
Actions are triggered by specific events (e.g. publishing a post ) that take place in WordPress. Your plugin can respondto the event by executing a PHP function
EventAction
Wordpress Plugin Hooks (3)
11/10/2008Wordpress Plugin Development ‐ A Short
Tutorial8
Hooks = Actions + Filters
DATA
Filters - Functions
Filters are functions that WordPress passes data throughat certain points in execution, just before taking someaction with the data such as adding it to the database orsending it to the browser screen.
Adding data to Wordpress database
11/10/2008Wordpress Plugin Development ‐ A Short
Tutorial9
Create tables with pluginsThere are two types of information you could store
• Setup Information: user choices that are entered when the user first sets upyour plugin.
• Data: information that is added as the user continues to use your plugin
Steps…
1. Write a PHP function that creates the table.
2. Ensure that WordPress calls the function when the plugin is activated.
3. Create an upgrade function, if a new version of your plugin needs to have a different table structure.
http://codex.wordpress.org/Creating_Tables_with_Plugins#Create_Database_Tables
$table_name = $wpdb->prefix . "liveshoutbox";
// check if there is a table with the same nameif($wpdb->get_var("show tables like '$table_name'") != $table_name) {
// SQL Statement$sql = "CREATE TABLE " . $table_name . " (
id mediumint(9) NOT NULL AUTO_INCREMENT,
time bigint(11) DEFAULT '0' NOT NULL,
name tinytext NOT NULL,
text text NOT NULL,
url VARCHAR(55) NOT NULL,
UNIQUE KEY id (id)
);";
// Creating the tablerequire_once(ABSPATH . 'wp-admin/includes/upgrade.php');
dbDelta($sql);
A simple example
$welcome_name = "Mr. Wordpress"; $welcome_text = "Congratulations, you just completed the installation!";
// SQL Statememt$insert = "INSERT INTO " . $table_name . " (time, name, text) " . "VALUES ('" . time() . "','" . $wpdb->escape($welcome_name) . "','" . $wpdb->escape($welcome_text) .
"')";
// Adding Data into the table$results = $wpdb->query( $insert );
A simple example
Adding Administration Menus
11/10/2008Wordpress Plugin Development ‐ A Short
Tutorial12
Create options pageTop-level menus: Settings, Manage, Plugins, Presentation, Write, Users
Admin Menu Functions
• add_menu_page: create a top-level menu
• add_submenu_page: define one or more sub-menu pages
In the above wordpress functions the developers defined the name of their phpfunctions which are responsible to build the options pages.
See an example here
http://codex.wordpress.org/Creating_Options_Pages
Hello Dolly example
11/10/2008Wordpress Plugin Development ‐ A Short
Tutorial13
Hello Dolly Lyrics Chose randomly one lyric and place it the upper right of your Administationpanels
add_action('admin_footer', 'hello_dolly');
Wordpress Development Community
11/10/2008Wordpress Plugin Development ‐ A Short
Tutorial14
Are you ready to enter into an evolving development community?
Matt Mullenweg
11/10/2008Wordpress Plugin Development ‐ A Short
Tutorial15
Creator of Wordpress.org
14th place The 25 most influential people on the web
(2008)
More details on the internet…
11/10/2008Wordpress Plugin Development ‐ A Short
Tutorial16
The truth is out there…
http://codex.wordpress.org/Writing_a_Plugin#WordPress_Plugin_Hooks
http://codex.wordpress.org/Plugin_API
http://codex.wordpress.org/Creating_Tables_with_Plugins
http://codex.wordpress.org/Adding_Administration_Menus
11/10/2008Wordpress Plugin Development ‐ A Short
Tutorial17
THE END
Thank you!