Tag or Function for WP Plugin
As far as I know, there are two ways to output the result of your plugin queries in Wordpress. One is to use the function call to echo/print the result and the other is to use add_filter function of WP which uses tags to append the result to the content. If coded correctly, there are no noticeable difference in the final result. However, in terms of performance (regarding speed and number of queries) there may seem a bit of overhead in using the add_filter function (and subsequently a tag).
When I first wrote (copied is a more accurate term) KG Archives Plugin for WP, I went for the add_filter approach to output the result of my queries. One reason for going that path is that the plugin written this way can be easily installed by novice and those without PHP background users. Good examples of this type of plugin are WP ContactForm and KG Archives plugin I have here. As of WP ContactForm’s case, it can be easily added to any page by just clicking the “Quicktags” above the post textarea. There are not much coding involve just uploading the files and activating the plugin.
The add_filter as I found out (while fixing the huge queries problem KG Archives is generating) has one drawback: the plugin is queried everytime blog contents are displayed. It gets queried on pages where it is not displayed. For example, KG Archives generates archives on my archives page but if you read the posts, the KG Archives plugin is still queried, it is just not being displayed in the resulting output.
My solution is that I have added a test on whether the page being called is the page where the plugin should do its work, if not, then exit the function. This way the rest of the code will not execute.
On the other hand, direct function calls to the plugin can be used and the problem will go away. It does not append the result to WP’s content variable but is echoed out directly. This also has a drawback, however. There is a need to open or , sometimes, create a template file and call the function directly. This approach is making newcomers feel uncomfortable as they find it hackish.
Like the first time I came to Wordpress world, I just download a theme and start blogging. The template system was hard to comprehend. And there are people whose concern is to blog only. These are the type of people who are used to the notion of they’ll only use softwares and tools that “just works”. They can’t even secure their desktop PC’s let alone hack the template of their chosen blogging tool.