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