Another way to access your plugin functionality is by creating your own template tags, much like bloginfo(), the_title(), and so on. This isn’t hard at all, in fact just by creating a function in your plugin (or in functions.php for that matter), you can access that function by a simple little PHP snippet:
<?php function-name(); ?>
Not very complicated, right? It really isn’t, but that doesn’t mean that it is the best way to include plugin content, even though it is by far the easiest method. By doing this you don’t need to add any hooks or anything, and the function will be executed when the plugin template tag is loaded, which means that you’ll just put it where you want it within your theme files.
There is really just one thing you need to keep in mind before going down this route, and that is usability. Not everybody is comfortable with editing the theme files, and if you intend to release your plugin, or deliver it to a client, then it may not be a good idea to force template file hacking for usage.
Then again, maybe you’ll be doing the deployment yourself, in which case it really doesn’t matter. However, if the end user will have to fiddle with the plugin’s position or perhaps will need to pass parameters to it, then it is probably a better idea to look at other solutions. At other times, just adding functionality using template tags won’t cut it, and you need to overwrite parts of the core WordPress functionality. That’s when you turn to the pluggable functions.
Sometimes you may need to overwrite parts of the WordPress core functionality, but just removing a hook won’t do it. That’s when you turn to pluggable.php, located in wp-includes. Naturally, you won’t hack it, because that would be a tedious thing to manage with updates, but rather you’ll write a plugin that does the override.
Now this is dangerous stuff. First of all, you can only do an override once, so if two plugins do different overrides on the same pluggable function, the site will act up (at best) or break (at worst). This means that two plugins both relying on overriding the same pluggable function can’t be installed at the same time, which is a serious drawback. Therefore, you should probably keep your pluggable function stuffto sites you are in complete control of. Also, to avoid unnecessary errors, you may want to wrap any code pertaining to a plugin relying on these things in a check to see if the function exists:
<?php if (!function_exists('function-name')); ?>
There are, naturally, times when the pluggable functions can come in handy. See the most up-todate list of what functions you can get in this way in the Codex: codex.wordpress.org/ Pluggable_Functions. And use with caution, obviously. Just writing the plugin in the correct way, which is covered next, isn’t enough when you’re nulling out parts of the WordPress core. Don’t be surprised when things stop working or conflicts come out of nowhere when you dive into these things. After all, the Word- Press functionality you’re bypassing is there for a reason.
Strictly speaking, the only thing your plugin really must have is a main PHP file containing the identifying top, and whatever code is needed to get the job done. However, in reality, you should probably take it a few steps further than that. After all, someone will have to work with your plugin, and so it should be as simple and accessible as possible. That means that you should go to great lengths to make the plugin blend in nicely with the WordPress admin interface.
The same goes for whatever parts of the plugin will show to end users. Some plugins add visual functionality, and that should work with as many themes as possible if you intend to release the plugin. Naturally, if you’ve developed a plugin for use with a particular project only, this won’t be an issue. The same goes for localization support; there’s no need for that if there won’t be any language support other than the default one, is there?
Finally, I think every plugin should come with a license, and some sort of instructions as to how the plugin should be used. Readme files are nice and all, but better yet to build the instructions into the actual plugin since a lot of users are reluctant (or just too impatient) to read the attached readme files.
Our website is not responsible for the information contained by this article. Webworldarticles.com is a free articles resource thus practically any visitor can submit an article. However if you notice any copyrighted material, please contact us and we will remove the article(s) in discussion right away.
This article was sent to us by:
Jennifer I. at
05132010
1. Developing Plugins for WordPress MU
All articles in this directory are property of their respective authors. Additionally, read our Privacy Policy
© 2010 WebWorldarticles.com - All Rights Reserved.