Demistying WordPress Plugins For Your Blog

By Lisa @Lisapatb

Plugins – What Are They And What Do They Really Do?

If you search for the term WordPress plugin on Google, you will get more than four million entries. Plugins are an important part of the WordPress system. In this post I will try to deconstruct what is a plugin and how does it help one to enhance WordPress functionality to suit your needs.

So what exactly is a plugin?

Generally plugin is a set of file(s) or modules which contains code that enhance the functionality of a system. For example, if you want your blog readers to export your blog posts as PDF you can use a plugin to do that. The maker of the software where these plugins are used are often not able to create functions that suit every other demand of the user of the product. This is where plugins come into place. They help developer outside of the standard WordPress development to create modules that help to enhance standard functionality.

So how does exactly plugin hook into the main software?

Plugins are set of files in a folder or multiple folders located at a specific folder ( for example “plugins” folder in WordPress) of the software. The main software provide for hooks which allow plugins to latch onto the data and modify it or add some data of their own.

One example could be adding of social media button at the end of content.

WordPress provides a “hook”  called as ‘the_content’ ( also called as filter ) . The plugin subscribes to this filter by just adding one line to its code

Add_filter(‘the_content’,’function_to_output_or_modify_content’);

That’s it!! The function is ’function_to_output_or_modify_content’ is now connected to the WordPress and will receive content and after modification ( adding a social media button at the end of content returns the content back to WordPress

Function  function_to_output_or_modify_content ( $content)

{

Return $content + “social media content”;

}

Often WordPress provides a location (header /content/sidebar) to add some html code . The HTML code can be placed on the location by something called as the “action”. Remember, no data is passed to the action and no data is returned from it.

For example to add some information to WordPress header, ‘wp_head’ hook is called.

Add_action(‘wp_head’,’some_function’);

Function some_function()

{

Echo “‘Hello Friend’;

}

All the plugins that exist for WordPress need to use either a filter or a hook to change the data provided by WordPress.

So what exactly is the benefit of plugins? 

Plugin help to expand the working of current software system ( in this case WordPress) by making it feature rich and also by providing enhancement to WordPress to suit any business need.

What are plugin settings API?

No plugin can just work without providing options that help an end user to configure the things plugin do with data. It could be a number of options for example in the PDF example above to allow only logged in users to download PDF of the post. The plugin settings provides a way for plugin developer to create admin pages and add  options to plugins which provide enhanced feature of the plugin.

More on WordPress plugins API

What role does Javascript play in plugins?

Javascript is a language that is executed on the client side i.e. on the person’s browser who has request the web page by typing the URL on the address bar. Javascript can be used to enhance the experience of the user. For example you have a feedback form on your website. Before you send the form back to the backend, you can validate if the information that is being sent is correct on the browser itself. On heavily loaded servers saving any round trip is very useful both in terms of bandwidth and server load.

WordPress typically uses a library called as JQuery. JQuery has been written in javascript and often serve as platform independent code giving the website same look and feel across multiple browsers and systems. The discussion on JQuery is out of the scope of this article.

If you see too many Javascript files being loaded while calling the page, you can use a cache plugin like WP Super Cache or W3 Total cache to combine them and deliver as one file.

What is a plugin conflict?

A plugin conflict may happen when different plugin use the same name to represent different kind of work. For example save_error is a very common name for a function. If two different plugins from two different vendors use same name as functions to execute similar task, the server will throw up an error.

It is thus responsibility to name the functions ( and classes ) independently for example by tagging them with their own namespaces ( share_juice_save_error is different from another_plugin_save_error).

How can plugin’s performance be measured?

P3P plugin gives a fair idea of plugin’s performance. However you can only know the performance of the plugin when you own the server and there are no other sites competing for the same resource ( CPU, bandwidth). It is not easy to determine performance of individual plugins as there are many factors in the play. The onus is on to developer to reduce database queries and other things to reduce loading time as far as possible. Always make sure that you are using the plugin from reliable sources and authors and take backup before you install the plugin.

Finally, can I code a plugin?

Yes, one needs knowledge of PHP and WordPress API to code a plugin. If your plugin does something on the browser, you will need to learn javascript. Once you know them , coding a plugin is quite easy.

Have you ever tried to make your own plugin via a code?

Top image via Image courtesy of Danilo Rizzuti at FreeDigitalPhotos.net

2nd image via Image courtesy of Boians Cho Joo Young at FreeDigitalPhotos.net