Your SlideShare is downloading. ×
How Not to Build a WordPress Plugin
How Not to Build a WordPress Plugin
How Not to Build a WordPress Plugin
How Not to Build a WordPress Plugin
How Not to Build a WordPress Plugin
How Not to Build a WordPress Plugin
How Not to Build a WordPress Plugin
How Not to Build a WordPress Plugin
How Not to Build a WordPress Plugin
How Not to Build a WordPress Plugin
How Not to Build a WordPress Plugin
How Not to Build a WordPress Plugin
How Not to Build a WordPress Plugin
How Not to Build a WordPress Plugin
How Not to Build a WordPress Plugin
How Not to Build a WordPress Plugin
How Not to Build a WordPress Plugin
How Not to Build a WordPress Plugin
How Not to Build a WordPress Plugin
How Not to Build a WordPress Plugin
How Not to Build a WordPress Plugin
How Not to Build a WordPress Plugin
How Not to Build a WordPress Plugin
How Not to Build a WordPress Plugin
How Not to Build a WordPress Plugin
How Not to Build a WordPress Plugin
How Not to Build a WordPress Plugin
How Not to Build a WordPress Plugin
How Not to Build a WordPress Plugin
How Not to Build a WordPress Plugin
How Not to Build a WordPress Plugin
How Not to Build a WordPress Plugin
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

How Not to Build a WordPress Plugin

18,635

Published on

Published in: Technology, Business
2 Comments
13 Likes
Statistics
Notes
  • Thank you for sharing !

    http://www.e-rachat-credits.fr/
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • This is an awesome slideshow! I couldn't get calling my plugins directly to work under wpmu, and this showed me how to do it right... Thanks!
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
No Downloads
Views
Total Views
18,635
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
134
Comments
2
Likes
13
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. How Not to Build a WordPress Plugin
    • Will Norris < http://willnorris.com />
  • 2.
    • Upgradability
    • Performance
    • Security
    • Extensibility
  • 3. Unique Function Names
  • 4. Function Name Prefix
    • wcpdx_activate()
    • wcpdx_deactivate()
    • wcpdx_uninstall()
  • 5. Class
    • class WordCampPDX {
    • function activate()
    • function deactivate()
    • function uninstall()
    • }
  • 6. Never Assume File Location
  • 7. Traditional Directory Layout
    • example.com/
    • wordpress/
    • wp-config.php
    • wp-content/
    • plugins/
    • themes/
  • 8. Non-Traditional Layout (since WP 2.6)
    • example.com/
    • wordpress/
    • wp-config.php
    • wordpress-content/
    • plugins/
    • themes/
  • 9. Plugin URL
    • ur doin it wrong:
    • <img src=”<?php bloginfo(‘wpurl’) ?>/wp-content/plugins/wcpdx/logo.png” ?>
    • dats bedder:
    • <img src=”<?php echo WP_PLUGIN_URL ?>/wcpdx/logo.png ?>”/>
    • you haz it:
    • <img src=”<?php echo plugins_url(‘logo.png’, __FILE__) ?>” />
  • 10. Plugin URL
    • plugins_url()
        • supports WPMU plugin directory
        • auto detects SSL
        • supports renamed plugin directory
        • calls ‘plugins_url’ filter
  • 11. Friends of plugins_url()
    • site_url()
    • admin_url()
    • includes_url()
    • content_url()
    • no home_url() (why not?)
  • 12. Including Files
    • ur doin it wrong:
    • include ‘../../wp-content/...’
    • dats bedder:
    • include ABSPATH . ‘wp-content/...’
    • you haz it:
    • include WP_CONTENT_DIR . ‘/...’
  • 13. Find the Right Hook
    • Load as late as possible, but no later
  • 14. Admin Hooks
    • ur doin it wrong:
    • add_action(‘admin_init’, ‘wcpdx_admin_init’)
    • add_action(‘admin_head’, ‘wcpdx_admin_head’)
    • you haz it:
    • $hookname = add_options_page( ... )
    • add_action(“admin_load-$hookname”, ‘wcpdx_admin_init’)
    • add_action(“admin_head-$hookname”, ‘wcpdx_admin_head’)
  • 15. Styles and Scripts
    • ur doin it wrong:
    • <script rel=”<?php echo plugins_url(‘wcpdx.js’, __FILE__) ?>”></script>
    • you haz it:
    • wp_enqueue_script(‘wcpdx’, plugins_url(‘wcpdx.js’, __FILE__))
    • wp_enqueue_style(‘wcpdx’, plugins_url(‘wcpdx.css’, __FILE__))
  • 16. Styles and Scripts
    • wp_register_* and wp_enqueue_*
        • support dependencies
        • push scripts to footer
        • caching support based on version
        • (one day) server side concatenation
  • 17. Add your own hooks
    • A strategically placed hook covers a multitude of sins.
  • 18. Custom Hooks
    • Can do everything core WP hooks do:
        • event notification (actions)
        • massage data (the_content)
        • replace values (stylesheet)
        • extend functionality (http_api_curl)
        • replace functionality
  • 19. Custom Hooks
    • do_action(‘my-action’)
    • do_action(‘my-action’, $a, $b)
    • do_action_ref_array(‘my-action’, array($wcpdx))
    • apply_filters(‘my-filter’, $wcpdx)
    • apply_filters(‘my-filter’, $wcpdx, $a, $b)
  • 20. Custom Tables
  • 21. Designed for Flexibility
    • WordPress database supports
        • custom options
        • arbitrary metadata for posts, users, and comments (2.9)
        • custom taxonomies
        • custom post types
  • 22. Custom Post Types
    • Used by WordPress core for
        • posts
        • pages
        • revisions
        • attachments
  • 23. If it walks like a duck...
    • author
    • date and time
    • title
    • content
    • comments
    • categories and tags
    • permalink
    • order
    • hierarchy
    • (additional arbitrary metadata)
  • 24. Admin Settings Pages
  • 25. Admin Settings Pages
    • Don’t waste time processing manually
    • register_setting( ‘wcpdx’, ‘my-option’ )
    • http://codex.wordpress.org/Settings_API
    • http://codex.wordpress.org/Creating_Options_Pages# Register_Settings
  • 26. Admin Settings Pages
    • Do you really need a dedicated page?
    • Add options to any built-in settings page
    • add_settings_field( ... )
  • 27. Direct Plugin Files
  • 28. Direct Plugin File Calls
    • Direct HTTP request to plugin file ajax.php:
    • echo ‘<script type=”text/javascript”>
    • jQuery.get(“‘ . plugins_url(‘ajax.php’, __FILE__) . ‘”);
    • // do something with AJAX data
    • </script>’;
  • 29. Direct Plugin File Calls
    • If ajax.php includes anything similar to:
    • require_once(‘../../../wp-load.php’);
    • ur doin it wrong
  • 30. WordPress Requests
    • Permalink URL:
    • http://example.com/2009/01/hello-world
    • becomes:
    • http://example.com/index.php?
    • year=2009&
    • monthnum=01&
    • name=hello-world
  • 31. Custom WP Request
    • Instead of making an AJAX call to:
    • http://example.com/wp-content/plugins/wcpdx/ajax.php
    • we want a URL like:
    • http://example.com/index.php?wcpdx=ajax-handler
  • 32. Custom WP Requests
    • function wcpdx_parse_request($wp) {
    • // only process requests with &quot;wcpdx=ajax-handler&quot;
    • if (array_key_exists('wcpdx', $wp->query_vars)
    • && $wp->query_vars['wcpdx'] == 'ajax-handler') {
    • // process the request.
    • }
    • }
    • add_action('parse_request', 'wcpdx_parse_request');
    • function wcpdx_query_vars($vars) {
    • $vars[] = 'wcpdx';
    • return $vars;
    • }
    • add_filter('query_vars', 'wcpdx_query_vars');

×