Presentation is loading. Please wait.

Presentation is loading. Please wait.

WordPress Plugin Development A Starter Guide For Beginners.

Similar presentations


Presentation on theme: "WordPress Plugin Development A Starter Guide For Beginners."— Presentation transcript:

1 WordPress Plugin Development A Starter Guide For Beginners

2 Md Jahidul Islam (oneTarek) Senior Executive, Development A. R. Communications Blog: onetarek.comonetarek.com Facebook: fb.com/oneTarekfb.com/oneTarek

3 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

4 Why Do We Write a Plugin? Solve a problem Extend existing functionality Save time Portability Make money (???)

5 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

6

7 When Plugins are Loaded

8 WP Folder Structure

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

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

11 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

12 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)Playing With Database Query(WPDB) Custom Queries WP Query AJAX in Plugins WP Nonce Translation(i18n)Translation AJAX in WordPressAJAX WordPress Cookies WordPress Feeds XML-RPC WordPress Coding Standards

13 WordPress API Plugin API Shortcode API Widgets API Options API Settings API Dashboard Widgets API Quicktags API Rewrite API Transients API

14 Plugin API Detail: http://codex.wordpress.org/Plugin_API HooksHooks 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. FiltersActionsFilters 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. Hooks, Actions, and Filters to use in your Plugins Codex Action Reference)Action Reference Codex Filter Reference)Filter Reference The Beginner's Guide to WordPress Actions and Filters

15 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, MoreMore How to use action hooks? We can hook our own function at a particular point by using add_action function.add_action 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.do_action() Example: add_action( “wp_footer”, “my_floating_bar”);

16 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, MoreMore How to use action hooks? We can modify particular data with our own function by using add_filter function.add_filter add_filter( $tag, $function_to_add, $priority, $accepted_args ); WordPress will pass specific data through my function by using apply_filters function.apply_filters Example: add_filter( “the_title”, “my_title_limit”);

17 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_APIhttp://codex.wordpress.org/Shortcode_API 2.http://www.smashingmagazine.com/2012/05/01/w ordpress-shortcodes-complete-guide/http://www.smashingmagazine.com/2012/05/01/w ordpress-shortcodes-complete-guide/

18 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_Widgetshttp://codex.wordpress.org/WordPress_Widgets 2.http://wpengineer.com/1023/wordpress-built-a-widget/http://wpengineer.com/1023/wordpress-built-a-widget/ 3.http://code.tutsplus.com/tutorials/writing-maintainable-wordpress- widgets-part-1-of-2--wp-20348http://code.tutsplus.com/tutorials/writing-maintainable-wordpress- widgets-part-1-of-2--wp-20348 4.http://justintadlock.com/archives/2009/05/26/the-complete-guide- to-creating-widgets-in-wordpress-28http://justintadlock.com/archives/2009/05/26/the-complete-guide- to-creating-widgets-in-wordpress-28

19 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.wp_optionsOption Reference Detail Guide and Tutorials: http://codex.wordpress.org/Options_API

20 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_APIhttp://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-24060http://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/http://tutorialzine.com/2012/11/option-panel- wordpress-plugin-settings-api/

21 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_APIhttp://codex.wordpress.org/Dashboard_Widgets_API 2.http://code.tutsplus.com/tutorials/how-to-build-custom- dashboard-widgets--wp-29778http://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/http://www.wpbeginner.com/wp-themes/how-to-add- custom-dashboard-widgets-in-wordpress/

22 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_APIhttp://codex.wordpress.org/Quicktags_API 2.http://www.wpexplorer.com/adding-wordpress-custom- quicktags/http://www.wpexplorer.com/adding-wordpress-custom- quicktags/

23 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_APIhttp://codex.wordpress.org/Rewrite_API 2.http://codex.wordpress.org/Class_Reference/WP_Rew ritehttp://codex.wordpress.org/Class_Reference/WP_Rew rite 3.http://code.tutsplus.com/articles/the-rewrite-api-the- basics--wp-25474http://code.tutsplus.com/articles/the-rewrite-api-the- basics--wp-25474

24 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_APIhttp://codex.wordpress.org/Transients_API

25 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

26 Questions?

27 THANK YOU


Download ppt "WordPress Plugin Development A Starter Guide For Beginners."

Similar presentations


Ads by Google