Developing Plugins For WordPress

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

0 comments

Post a comment

    Post a comment
    Embed Video
    Edit your comment Cancel

    Favorites, Groups & Events

    Developing Plugins For WordPress - Presentation Transcript

    1. DEVELOPING PLUGINS FOR WORDPRESS Lester Chan | http://lesterchan.net
    2. Agenda
      • Introduction
      • Developing Plugin
        • WP API: Filters/Hooks
        • Plugin Path
        • Plugin Details
        • Inserting CSS/Javascript
        • Modifying Content
        • Translating Plugin Text To Other Languages
        • Shortcode API
        • Activating The Plugin
    3. Introduction
      • Name
        • Lester Chan
      • Website
        • http://lesterchan.net
      • Experience
        • Developing WordPress Plugins the day WP is born
        • Developed 16 WP plugins to date
          • WP-Polls, WP-PostRatings, WP-PostViews, WP-Print, WP-Email, WP-Useronline, etc
    4. WP:API Filters/Hooks
      • Filters
        • Filters allows your plugin to modify data that passes through WordPress at specific locations
          • Eg: post title, post date, post content
          • add_filter(‘ location ’, ‘ plugin_function_name ’);
      • Hooks
        • Hooks allows you to execute your plugin function at specific location when WordPress is being executed
          • Eg: Init, header, footer
          • add_action(‘ location ’, ‘ plugin_function_name ’);
    5. Plugin Path
      • All WordPress plugins are placed in:
        • /wp-content/plugins/
      • Example:
        • Name: WP-Demo
        • Nice Name: wp-demo
      • Placing your plugin in:
        • /wp-content/plugins/wp-demo.php
        • /wp-content/plugins/wp-demo/wp-demo.php
    6. Plugin Path
      • My naming convention style:
        • /wp-content/plugins/wp-demo/
          • wp-demo.php
          • demo-css.css
          • demo-js.js
          • demo-js-packed.js
          • demo-options.php
          • demo-uninstall.php
    7. Plugin Details
      • <?php
      • /*
      • Plugin Name: WP-Demo
      • Plugin URI: http://lesterchan.net/wp-demo/
      • Description: This is a demo plugin
      • Version: 1.00
      • Author: Lester Chan
      • Author URI: http://lesterchan.net
      • */
      • ?>
    8. Inserting CSS/Javascript
      • Inserting CSS:
        • function print_css () { echo '<link rel=&quot;stylesheet&quot; href=&quot;'.get_option('siteurl').'/wp-content/plugins/wp- demo/demo-css.css&quot; type=&quot;text/css&quot; media=&quot;screen&quot; />‘; }
        • Use Hook: wp_head
          • add_action('wp_head', ‘ print_css ');
    9. Inserting CSS/Javascript
      • Inserting Javascript:
        • Use Hook: wp_head
        • Use 2 WP Functions:
          • wp_register_script()
          • wp_print_scripts()
      • wp_register_script(' wp-demo ', '/wp-content/plugins/wp-demo/demo-js-packed.js', false, '1.00');
      • wp_print_scripts(array(' jquery ', ' wp-demo '));
    10. Inserting CSS/Javascript
      • Advantages of using register/print script:
        • Print only once
      • Good practice to compress/obfuscate Javascript
        • Smaller File Size
        • Load Faster
        • http://dean.edwards.name/packer/
      • WordPress 2.6
        • wp_register_style()
        • wp_print_styles()
    11. Modifying Content
      • function demo_content ($content) { return ‘Start of post’.$content.’End of post’; }
      • Use Filter: the_content
        • add_filter('the_content', ' demo_content ');
    12. Translating Plugin
      • Loading The Translation:
        • function demo_textdomain () { load_plugin_textdomain(' wp-demo ', 'wp- content/plugins/wp-demo'); }
        • Use Hook: init
          • add_action('init', ' demo_textdomain ');
    13. Translating Plugin
      • Printing the text
        • Instead of
          • <?php echo ‘Testing’; ?>
        • Use
          • <?php _e(‘Testing’, ‘ wp-demo ’); ?>
      • Return the text
        • <?php __(‘Testing’, ‘ wp-demo ’); ?>
    14. Translating Plugin
      • Poedit
        • http://www.poedit.net/
      • Tutorial
        • http://lc.sg/q
    15. ShortCode API
      • What is ShortCode API?
        • Shortcode API, a simple set of functions for creating macro codes for use in post content.
        • Example: [demo id=“1”]
          • Is able to retrieve a demo record of ID 1 and embed the results into the post content
    16. ShortCode API
      • Implementation
        • [ demo id=“1”]
        • add_shortcode(' demo ', ' demo_shortcode '); function demo_shortcode ($atts) { extract(shortcode_atts( array('id' => 0), $atts)); return get_demo_by_id ($id); }
      • Get Demo By ID Function
        • function get_demo_by_id ($id) { // Perform Database Query return '<p>ID:'. $id.'</p>‘; }
    17. Activating The Plugin
      • add_action('activate_ wp-demo/wp-demo.php ', ' create_demo_table ');
      • global $wpdb;
      • $wpdb->demo = $wpdb->prefix.'demo';
      • function create_demo_table () { global $wpdb; … }
    18. THANK YOU ANY QUESTIONS

    + Lester ChanLester Chan, 8 months ago

    custom

    643 views, 0 favs, 0 embeds more stats

    My presentation on Developing Plugins for WordPress more

    More info about this document

    © All Rights Reserved

    Go to text version

    • Total Views 643
      • 643 on SlideShare
      • 0 from embeds
    • Comments 0
    • Favorites 0
    • Downloads 8
    Most viewed embeds

    more

    All embeds

    less

    Flagged as inappropriate Flag as inappropriate
    Flag as inappropriate

    Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

    Cancel
    File a copyright complaint
    Having problems? Go to our helpdesk?

    Categories