Wordpress Plugin Development Short Tutorial

28,879
-1

Published on

This is an introduction for those who want to start developing plugins for Wordpress blog engine

Published in: Technology, Art & Photos

Wordpress Plugin Development Short Tutorial

  1. 1. 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” example Wordpress Plugin Development ‐ A Short  11/10/2008 2 Tutorial
  2. 2. Pre‐development issues (1) Wordpress Plugin Directory  code javascript wp‐content plugins your plugin css place your plugin here images Wordpress Plugin Development ‐ A Short  11/10/2008 3 Tutorial
  3. 3. Pre‐development issues (2) 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. Wordpress Plugin Development ‐ A Short  11/10/2008 4 Tutorial
  4. 4. Pre‐development issues (3) File Headers Wordpress Plugin Development ‐ A Short  11/10/2008 5 Tutorial
  5. 5. Wordpress Plugin Hooks (1) Hooks are provided to allow your plugin to 'hook into' the rest of WordPress; that is, to call functions in your plugin at specific times, and thereby set your plugin in motion. Hooks Wordpress Plugin Development ‐ A Short  11/10/2008 6 Tutorial
  6. 6. Wordpress Plugin Hooks (2) Hooks = Actions + Filters Actions are triggered by specific events (e.g. publishing a post ) that take place in WordPress. Your plugin can respond to the event by executing a PHP function Action Event Wordpress Plugin Development ‐ A Short  11/10/2008 7 Tutorial
  7. 7. Wordpress Plugin Hooks (3) Hooks = Actions + Filters Filters - Functions DATA Filters are functions that WordPress passes data through at certain points in execution, just before taking some action with the data such as adding it to the database or sending it to the browser screen. Wordpress Plugin Development ‐ A Short  11/10/2008 8 Tutorial
  8. 8. Adding data to Wordpress database Create tables with plugins There are two types of information you could store • Setup Information: user choices that are entered when the user first sets up your 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 Wordpress Plugin Development ‐ A Short  11/10/2008 9 Tutorial
  9. 9. A simple example $table_name = $wpdb->prefix . quot;liveshoutboxquot;; // check if there is a table with the same name if($wpdb->get_var(quot;show tables like '$table_name'quot;) != $table_name) { // SQL Statement $sql = quot;CREATE TABLE quot; . $table_name . quot; ( 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) );quot;; // Creating the table require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); dbDelta($sql);
  10. 10. A simple example $welcome_name = quot;Mr. Wordpressquot;; $welcome_text = quot;Congratulations, you just completed the installation!quot;; // SQL Statememt $insert = quot;INSERT INTO quot; . $table_name . quot; (time, name, text) quot; . quot;VALUES ('quot; . time() . quot;','quot; . $wpdb->escape($welcome_name) . quot;','quot; . $wpdb->escape($welcome_text) . quot;')quot;; // Adding Data into the table $results = $wpdb->query( $insert );
  11. 11. Adding Administration Menus Create options page Top-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 php functions which are responsible to build the options pages. See an example here http://codex.wordpress.org/Creating_Options_Pages Wordpress Plugin Development ‐ A Short  11/10/2008 12 Tutorial
  12. 12. Hello Dolly example Hello Dolly Lyrics Chose randomly one lyric and place it the upper right of your Administation panels add_action('admin_footer', 'hello_dolly'); Wordpress Plugin Development ‐ A Short  11/10/2008 13 Tutorial
  13. 13. Wordpress Development Community Are you ready to enter into an evolving development community? Wordpress Plugin Development ‐ A Short  11/10/2008 14 Tutorial
  14. 14. Matt Mullenweg Creator of Wordpress.org 14th place The 25 most influential people on the web (2008) Wordpress Plugin Development ‐ A Short  11/10/2008 15 Tutorial
  15. 15. More details on the internet… 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 Wordpress Plugin Development ‐ A Short  11/10/2008 16 Tutorial
  16. 16. THE END Thank you! Wordpress Plugin Development ‐ A Short  11/10/2008 17 Tutorial
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×