wordpress plugin development a starter guide for beginners

27
WordPress Plugin Development A Starter Guide For Beginners

Upload: coleen-hopkins

Post on 01-Jan-2016

226 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: WordPress Plugin Development A Starter Guide For Beginners

WordPress Plugin Development

A Starter Guide For Beginners

Page 2: WordPress Plugin Development A Starter Guide For Beginners

Md Jahidul Islam (oneTarek)Senior Executive , Development

A. R. CommunicationsBlog: onetarek.com

Facebook: fb.com/oneTarek

Page 3: WordPress Plugin Development A Starter Guide For Beginners

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

Page 4: WordPress Plugin Development A Starter Guide For Beginners

Why Do We Write a Plugin?

Solve a problem Extend existing functionality Save time PortabilityMake money (???)

Page 5: WordPress Plugin Development A Starter Guide For Beginners

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

Page 6: WordPress Plugin Development A Starter Guide For Beginners
Page 7: WordPress Plugin Development A Starter Guide For Beginners

When Plugins are Loaded

Page 8: WordPress Plugin Development A Starter Guide For Beginners

WP Folder Structure

Page 9: WordPress Plugin Development A Starter Guide For Beginners

Starting Your First PluginSTEP 1: Create a new folder inside the folder wp-content/plugins/ and named it related to your plugin nameSTEP 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.

Page 10: WordPress Plugin Development A Starter Guide For Beginners

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 listActivate your plugin.

Page 11: WordPress Plugin Development A Starter Guide For Beginners

A Real ExampleCreate a PHP file with following codes and save that into the plugins folder withany 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

Page 12: WordPress Plugin Development A Starter Guide For Beginners

Some Necessary Topics to Learn•Custom Post Types•Custom Taxonomy•Custom Metabox•Post Meta•WordPress API

Plugin API(*****)

Shortcode API

Widgets API

Options API

Settings API

Dashboard Widgets API

Quicktags API

Rewrite API

Transients API•Global Variables•WP Media Library•Plugin and Content Directories•Adding Administration Menus•Creating Options Pages

• Creating Tables with Plugins• Playing With Database Query(WPDB)• Custom Queries• WP Query • AJAX in Plugins  • WP Nonce• Translation(i18n)• AJAX  in WordPress• WordPress Cookies • WordPress Feeds • XML-RPC• WordPress Coding Standards 

Page 13: WordPress Plugin Development A Starter Guide For Beginners

WordPress API

Plugin API Shortcode API Widgets API Options API Settings API

Dashboard Widgets API

Quicktags API Rewrite API Transients API

Page 14: WordPress Plugin Development A Starter Guide For Beginners

Plugin API

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

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. FiltersActions 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.

Hooks, Actions, and Filters to use in your Plugins

Codex Action Reference) Codex Filter Reference)The Beginner's Guide to WordPress Actions and Filters

Page 15: WordPress Plugin Development A Starter Guide For Beginners

Actions HooksActions 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 isplaced, 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 wantto 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”);

Page 16: WordPress Plugin Development A Starter Guide For Beginners

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 thefilter 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”);

Page 17: WordPress Plugin Development A Starter Guide For Beginners

Shortcode APIIntroduced 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_API2.

http://www.smashingmagazine.com/2012/05/01/wordpress-shortcodes-complete-guide/

Page 18: WordPress Plugin Development A Starter Guide For Beginners

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_Widgets2. http://wpengineer.com/1023/wordpress-built-a-widget/3. http://code.tutsplus.com/tutorials/writing-maintainable-wordpress-w

idgets-part-1-of-2--wp-203484. http://justintadlock.com/archives/2009/05/26/the-complete-guide-to

-creating-widgets-in-wordpress-28

Page 19: WordPress Plugin Development A Starter Guide For Beginners

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

Page 20: WordPress Plugin Development A Starter Guide For Beginners

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-guide-to-the-wordpress-settings-api-part-1-what-it-is-why-it-matters--wp-24060

3. http://tutorialzine.com/2012/11/option-panel-wordpress-plugin-settings-api/

Page 21: WordPress Plugin Development A Starter Guide For Beginners

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-custom-dashboard-widgets--wp-29778

3. http://www.wpbeginner.com/wp-themes/how-to-add-custom-dashboard-widgets-in-wordpress/

Page 22: WordPress Plugin Development A Starter Guide For Beginners

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/

Page 23: WordPress Plugin Development A Starter Guide For Beginners

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_Rewrite

3. http://code.tutsplus.com/articles/the-rewrite-api-the-basics--wp-25474

Page 24: WordPress Plugin Development A Starter Guide For Beginners

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

Page 25: WordPress Plugin Development A Starter Guide For Beginners

Tutorials And Books

Tutorials:http://codex.wordpress.org/Writing_a_PluginHow to Create a WordPress PluginTop 6 WordPress Plugin Development Tutorials2 Essential Guides and Resources

Books:WordPress Plugin Development (Beginner's Guide)Professional WordPress Plugin Development

Page 26: WordPress Plugin Development A Starter Guide For Beginners

Questions?

Page 27: WordPress Plugin Development A Starter Guide For Beginners

THANK YOU