Developing Plugins For WordPress

40 %
60 %
Information about Developing Plugins For WordPress
Technology

Published on March 11, 2009

Author: gamerz

Source: slideshare.net

Description

My presentation on Developing Plugins for WordPress during Singapore PHP User Group Meetup in June 2008

DEVELOPING PLUGINS FOR WORDPRESS Lester Chan | http://lesterchan.net

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

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

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

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

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 ’);

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 ’);

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

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

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

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

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 */ ?>

<?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

*/

?>

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 ');

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 ');

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 '));

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 '));

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()

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()

Modifying Content function demo_content ($content) { return ‘Start of post’.$content.’End of post’; } Use Filter: the_content add_filter('the_content', ' demo_content ');

function demo_content ($content) { return ‘Start of post’.$content.’End of post’; }

Use Filter: the_content

add_filter('the_content', ' demo_content ');

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 ');

Loading The Translation:

function demo_textdomain () { load_plugin_textdomain(' wp-demo ', 'wp- content/plugins/wp-demo'); }

Use Hook: init

add_action('init', ' demo_textdomain ');

Translating Plugin Printing the text Instead of <?php echo ‘Testing’; ?> Use <?php _e(‘Testing’, ‘ wp-demo ’); ?> Return the text <?php __(‘Testing’, ‘ wp-demo ’); ?>

Printing the text

Instead of

<?php echo ‘Testing’; ?>

Use

<?php _e(‘Testing’, ‘ wp-demo ’); ?>

Return the text

<?php __(‘Testing’, ‘ wp-demo ’); ?>

Translating Plugin Poedit http://www.poedit.net/ Tutorial http://lc.sg/q

Poedit

http://www.poedit.net/

Tutorial

http://lc.sg/q

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

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

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>‘; }

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>‘; }

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; … }

add_action('activate_ wp-demo/wp-demo.php ', ' create_demo_table ');

global $wpdb;

$wpdb->demo = $wpdb->prefix.'demo';

function create_demo_table () { global $wpdb; … }

THANK YOU ANY QUESTIONS

Add a comment

Related presentations

Related pages

develop — Schlagwörter — WordPress Plugins

A framework to ease up the process of developing new plugins for wordpress. Von: (0) Zuletzt aktualisiert: vor 5 Jahren 453 Downloads Kompatibel bis zu: 3.2.1.
Read more

Writing a Plugin « WordPress Codex

WordPress Plugin: A WordPress Plugin ... WordPress Plugin Hooks. Many WordPress Plugins accomplish their goals by connecting to one or more WordPress ...
Read more

development — Schlagwörter — WordPress Plugins

See which plugins are slowing down your site. ... WordPress Website Security Protection: Firewall Security, Login Security, Database Security ...
Read more

oPlugins | Development WordPress Plugins

We are developing Premium WordPress Plugins and providing outstanding support for our products. We are designing WordPress plugins to provide solutions for ...
Read more

developing — Tags — WordPress Plugins

This plugin adds an additional authentication layer to your WordPress installation to put the site into a demo- or maintainance-mode. By: Roland Rust.
Read more

Managing Plugins « WordPress Codex

Managing Plugins. Languages: English ... WordPress Plugins are composed of PHP scripts that extend the functionality of WordPress. ... Developing Plugins.
Read more

WordPress Plugins

Plugins extend and expand the functionality of WordPress. 46,284 plugins with 1,376,115,750 total downloads are at your fingertips.
Read more

WordPress Plugins - developingwp.com

WordPress Plugin are set of programming codes written mostly in PHP to improve, extend and expand functionality each WordPress website. Best plugins for WP
Read more

Developing for the WordPress.org Plugin Directory - SitePoint

The official WordPress.org Plugin Directory is home to an amazing collection of useful plugins, it’s usually the first place WordPress users look when ...
Read more

iCanWP | WordPress Plugins & Websites

Here at iCanWP we specialize in making the most simple and easy to use WordPress Plugins & Websites.
Read more