Developing WordPress Plugins

download Developing WordPress Plugins

of 24

  • date post

    08-May-2015
  • Category

    Technology

  • view

    21.633
  • download

    0

Embed Size (px)

description

A talk on developing WordPress plugins, basically an introduction on how to extend the most popular blogging app today. Used for WordCamp Philippines 2008.

Transcript of Developing WordPress Plugins

  • 1.Developing WordPress Plugins Markku Seguerra http://rebelpixel.com

2. What is a WordPress plugin?

    • Little applications used to enhance functionality or add specific functions tailored to a site's specific needs.

3. Some plugins: - Akismet - WordPress Database Backup - WordPress.com Stats - wp-recent-links - Comment Hilite 4. What do you need to make a plugin? - a problem to solve - some PHP knowledge - some spare time - a test server with your test WordPress (XAMPP is good.) 5. Structure: Things to remember - A unique descriptive name - Naming: myplugin.php or /myplugin/ folder - Readme.txt format for wordpress.org/extend/plugins - Plugin home page - File headers (very important!) 6. Headers 7. Include your license details!

    • The GPL (and compatible licenses) is commonly used for plugins.

8. Plugin Programming

    • Before WP 1.2, customizations required altering the core files, causing conflicts among hacks (remember my-hacks.php?) and making upgrades very tedious.

The solution? 9. Plugin API - Enabled "hooks" - Extend functionality without editing the core code - Two categories: Actions and Filters 10. Actions Specific points in the WordPress code that can be used to trigger plugin-specified events and functions. add_action( 'hook_name', 'your_function_name', [priority], [accepted_args] ); 11. Sample action: wp_login function notify_on_login() { // your code here // email to admin, etc... } add_action('wp_login', 'notify_on_login'); 12. Filters Functions that modify text, lists and various types of information that are used and produced by WordPress. add_filter('hook_name', 'your_filter_function', [priority], [accepted_args]); 13. Sample filter: the_content function add_rss_invite() { // output to screen the link to RSS feed // if 1st time visitor } add_filter('the_content', 'add_rss_invite'); 14. Template Tags Plugins can also be used to generate special template tags that display custom content. - Recent comments - Top posts - Ad display 15. Storing Plugin Data - For large amount of data, create your own database table. - For fairly small and/or static data, use built-in WP "Options" capability. add_option($name, $value, $deprecated, $autoload); get_option($option); update_option($option_name, $newvalue); 16. Administration Menus & Pages - There are specific functions to add pages and menu items. add_menu_page(page_title, menu_title, access_level/capability, file, [function]); add_submenu_page();add_options_page(); add_management_page(); add_theme_page(); 17. Other things to consider - Internationalization - WordPress Coding Standards & inline documentation - Function prefixes to avoid name collision - When creating tables, use $wpdb->prefix - Minimize database writes. - Write secure code! (Use nonces, sanitize, etc.) - Be aware of user roles and capabilities. - Stick to the WordPress API to avoid problems! 18. Sample plugin: Strip!