0% found this document useful (0 votes)
68 views26 pages

Wordpress Plugin Development: By: Muhammad Noman Khalid

This document discusses WordPress plugin development. It begins with an introduction to plugins, explaining that plugins allow modification and customization of WordPress without changing core code. It then covers reasons for writing plugins like solving problems or extending functionality. The document discusses how plugins work and load in WordPress. It provides an example of a simple "Hello World" style plugin. Finally, it lists several WordPress APIs that are useful for plugin development like the Plugin API, Shortcode API, and others.

Uploaded by

Abdullah Javed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
68 views26 pages

Wordpress Plugin Development: By: Muhammad Noman Khalid

This document discusses WordPress plugin development. It begins with an introduction to plugins, explaining that plugins allow modification and customization of WordPress without changing core code. It then covers reasons for writing plugins like solving problems or extending functionality. The document discusses how plugins work and load in WordPress. It provides an example of a simple "Hello World" style plugin. Finally, it lists several WordPress APIs that are useful for plugin development like the Plugin API, Shortcode API, and others.

Uploaded by

Abdullah Javed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 26

WordPress Plugin Development

Lecture 14

By : Muhammad Noman
Khalid
Department of Computer Science
Bahria University Karachi Campus

1
What is a Plugin?
WordPress Plugins allow easy modification, customization,
and enhancement to a WordPress blog. Instead of changing
the core programming of WordPress, you can add
functionality with WordPress Plugins. Here is a basic
definition:
WordPress Plugin: A WordPress Plugin is a program, or a set
of one or more functions, written in the PHP scripting
language, that adds a specific set of features or services to the
WordPress weblog, which can be seamlessly integrated with
the weblog using access points and methods provided by the
WordPress Plugin Application Program Interface (API).
http://codex.wordpress.org/Writing_a_Plugin
Why Do We Write a Plugin?
Solve a problem
Extend existing functionality
Save time
Portability
Make money (???)
How does plug-in works?
As shown in the figure, the host application
provides services which the plug-in can
use, including a way for plug-ins to
register themselves with the host
application and a protocol for the
exchange of data with plug-ins. Plug-
ins depend on the services provided by
the host application and do not usually
work by themselves. Conversely, the
host application operates independently
of the plug-ins, making it possible for
end-users to add and update plug-ins
dynamically without needing to make
changes to the host application.

http://en.wikipedia.org/wiki/Plug-in_%28computing%29
When Plugins are Loaded
WP Folder Structure
Starting Your First Plugin
STEP 1: Create a new folder inside the folder wp-content/plugins/ and
named it related to your plugin name
STEP 2: Creating a new plugin you’ll need to start with a simple PHP file.
This can be named anything but should generally reflect your plug-in’s official name.
STEP 3: On the top your PHP file put some information about your plugin. The first lines of
your plug-in must be comment information for the parsing engine.
This is extremely important as WordPress will be unable to process your file without.
Below is an example code snippet.
Starting Your First Plugin
STEP 4: Save your PHP file.
STEP 5: Your are done. Your plugin is ready.

Now go to dash board plugin list. You will see you plugin name in the list
Activate your plugin.
A Real Example
Create a PHP file with following codes and save that into the plugins folder with
any name , I named it my-floating-bar.php . Now active this plugin and go to your
site home page. You will see a red colored bar with some moving texts
Some Necessary Topics to Learn
•Custom Post Types •Creating Tables with Plugins
•Custom Taxonomy •Playing With Database Query(WP
•Custom Metabox DB)
•Post Meta
•Custom Queries
•WordPress API
Plugin API(*****)
•WP Query
Shortcode API •AJAX in Plugins 
Widgets API •WP Nonce
Options API •Translation(i18n)
Settings API
•AJAX  in WordPress
Dashboard
Widgets API •WordPress Cookies
Quicktags API •WordPress Feeds
Rewrite API •XML-RPC
Transients API •WordPress Coding Standards 
•Global Variables
•WP Media Library
•Plugin and Content Directories
•Adding Administration Menus
•Creating Options Pages
WordPress API
Plugin API  Dashboard Widgets
Shortcode API API
Widgets API  Quicktags API
Options API  Rewrite API
Settings API
 Transients API
Plugin API
Hooks, Actions, and Filters to use in your Plugins
Hooks are provided by WordPress 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. There are two kinds of hooks:

1.Actions 2. Filters
Actions and filters allow you add your own functionality or modify your site’s
behavior by hooking a callback function onto a specific tag in the core code,
setting priorities and using parameters and arguments passed to the callback
function.

Detail:
http://codex.wordpress.org/Plugin_API

Codex Action Reference)


Codex Filter Reference)
The Beginner's Guide to WordPress Actions and Filters
Actions Hooks
Actions allow you to run your own function at a specific point in the processing of the
WordPress. Action hooks are essentially placeholders. Wherever an action hook is
placed, it will execute any code that has been “hooked” to it.
For example, you might want to do something when a post is published.
You may want to send an email with detail about your published post. You may want
to add your own HTML/JS code on the footer section of your website.

Some example of Action hooks:


wp_head, wp_footer, publish_post , save_post , the_post , More

How to use action hooks?


We can hook our own function at a particular point by using add_action function.
add_action( $hook_name, $my_function_to_add, $priority, $accepted_args );
WordPress will call my function on the specific point by using do_action() function.

Example:
add_action( “wp_footer”, “my_floating_bar”);
Filter Hooks
Filters allow you to intercept and modify data as it is processed.
For example, you might want not to show any post title more than 60 characters.
Then you just need to modify the post title by using your custom function with the
filter hook for post title.
Some example of Filter hooks:
the_content  , the_title  , wp_title  , the_date  , the_time  , the_permalink  , More

How to use action hooks?


We can modify particular data with our own function by using add_filter function.
add_filter( $tag, $function_to_add, $priority, $accepted_args );

WordPress will pass specific data through my function by using apply_filters function.

Example:
add_filter( “the_title”, “my_title_limit”);
Shortcode API
Introduced in WordPress 2.5 is the Shortcode API, a simple set of functions
for creating macro codes for use in post content. The average user acting as
editor has the ability to publish dynamic content using macros, without the
need for programming skills.
Example: The following shortcode (in the post/page content) would add a
photo gallery into the page
[gallery]
Detail Guide and Tutorial:
1.http://codex.wordpress.org/Shortcode_API
2.
http://www.smashingmagazine.com/2012/05/01/wordpr
ess-shortcodes-complete-guide/
Widgets API
Widgets were originally designed to provide a simple and easy-
to-use way of giving design and structure control of the
WordPress Theme to the user, which is now available on
properly "widgetized" WordPress Themes to include the
header, footer, and elsewhere in the WordPress design and
structure.
Detail Guide and Tutorials:
1. http://codex.wordpress.org/WordPress_Widgets
2. http://wpengineer.com/1023/wordpress-built-a-widget/
3. http://code.tutsplus.com/tutorials/writing-maintainable-wordpress-wid
gets-part-1-of-2--wp-20348
4. http://justintadlock.com/archives/2009/05/26/the-complete-guide-to-cr
eating-widgets-in-wordpress-28
Options API
The Options API is a simple and standardized way
of storing data in the database. The API makes it
easy to create, access, update, and delete options.
All the data is stored in the wp_options table
under a given custom name. This page contains the
technical documentation needed to use the Options
API. A list of default options can be found in the
Option Reference.
Detail Guide and Tutorials:
http://codex.wordpress.org/Options_API
Settings API
The Settings API,allows admin pages containing settings
forms to be managed semi-automatically. It lets you
define settings pages, sections within those pages
and fields within the sections.
Detail Guide and Tutorials:
1. http://codex.wordpress.org/Settings_API
2. http://code.tutsplus.com/tutorials/the-complete-guid
e-to-the-wordpress-settings-api-part-1-what-it-is-w
hy-it-matters--wp-24060
3. http://tutorialzine.com/2012/11/option-panel-wordp
ress-plugin-settings-api/
Dashboard Widgets API
The Dashboard Widgets API makes it very simple to add
new widgets to the administration dashboard.
Detail Guide and Tutorials:
1. http://codex.wordpress.org/Dashboard_Widgets_API
2. http://code.tutsplus.com/tutorials/how-to-build-custo
m-dashboard-widgets--wp-29778
3. http://www.wpbeginner.com/wp-themes/how-to-add-c
ustom-dashboard-widgets-in-wordpress/
Quicktags API
The Quicktags API allows you to include additional
buttons in the Text (HTML) mode of the WordPress
editor.
Detail Guide and Tutorials:
1. http://codex.wordpress.org/Quicktags_API
2. http://www.wpexplorer.com/adding-wordpress-custom
-quicktags/
Rewrite API
WordPress allows theme and plugin developers to
programmatically specify new, custom rewrite rules
Example:
http://wpressians.net/meetup/7th-meetup/speakers/
Detail Guide and Tutorials:
1. http://codex.wordpress.org/Rewrite_API
2. http://codex.wordpress.org/Class_Reference/WP_Re
write
3. http://code.tutsplus.com/articles/the-rewrite-api-the-
basics--wp-25474
Transients API
WordPress Transients API, which offers a simple and
standardized way of storing cached data in the database
temporarily by giving it a custom name and a timeframe after
which it will expire and be deleted

Detail: http://codex.wordpress.org/Transients_API
Tutorials And Books
Tutorials:
http://codex.wordpress.org/Writing_a_Plugin
How to Create a WordPress Plugin
Top 6 WordPress Plugin Development Tutorials
2 Essential Guides and Resources

Books:
WordPress Plugin Development (Beginner's Guide)
Professional WordPress Plugin Development
Questions?
THANK YOU

You might also like