I have reached a point with the plugin that I am developing where I have been many times before. Most of the core functionality is done and I am deciding how to expose that to the users. Do I offer template tags or settings?
I am a big fan of the WordPress theme system and there is a good argument for suggesting that plugins should look to expand on the great work that has already been done by offering template tags wherever there is additional reader-facing content.
There are obviously some exceptions to this, there is no point creating a new tag for content that is modified in a certain way, just hook into the current tag, and plugins like the excellent Ajax Edit Comments that add content where the placement is a given (buttons below the comment text), but on the whole should we be aiming to create tags or not?
Here is the example from the plugin I am working on right now:
My plugin adds extra fields for the commenters to complete to show things such as which version of WordPress they are using. When their comment is displayed this information is displayed with the comment. I have included a test comment below just for fun.
The extra statement, that this comment relates to WordPress version x, is added with a comment tag right now, but I could just as easily provide an admin panel with the option to include it above or below the comment, and asking what separators and introductory text should be used.
So the question is this: is there a preferred method that plugin authors should aim for? Should we be avoiding admin panels when the same functionality can be produced using a template tag, as with most of the standard content, or should we be aiming for as seamless an experience as possible where no editing is necessary?
The third option, of course, is that there shouldn’t be a preferred method, but I dismiss that one. I feel there should be a target.
(__)
`
Andrew Rickmann
Trisha,
I do agree with you. I am coming round to the fact that making things as easy as possible is the best solution.
The technical, ordered, part of me though wants to extend WordPress so that my plugin works in the same way as the core, but it seems that isn’t the best thing for the users.
(__)
`
Trisha
I think adding a Settings would be better – the reason is that if you offer a template tag that needs to be inserted into a Theme file then SOME users will not be able to do this without messing up their Theme (a small minority, granted) however that still presents two other problems: 1) if the user switches Themes they will need to update every Theme they want to use, and 2) if the plugin is deactivated (for any reason) then the Theme can break – an invalid function call can prevent parts of the Theme’s files and styles from loading……..
(__)
`
Andrew Rickmann
That’s a pretty interesting idea Kristin. One of my plugins uses ouput buffering to modify the code before it is output. In theory, it would be just as easy to load the file as a string, identify the relevent template tags, insert content before then and then eval the whole page.
I don’t think that is an ideal solution though, it is probably better for users to make a choice one way or another.
I have opted to go for the admin page simply because it is easier to explain to users.
(__)
`
Kristin K. Wangen
The in-between could be to automagically add the code to the template, when the plugin is activated, and just tell your users that this is how it works.
(__)
`
Andrew Rickmann
Kristin, that was what I was thinking but it did occur to me that an admin page for every plugin might get overwhealming and that adding lots of processing where you could just insert the tags could have an adverse effect if every plugin does it.
(__)
`
Kristin K. Wangen
I think that you should as far as possible try to avoid any editing of template files. In my experience most people prefer the “upload the plugin and activate, and that’s all”-method.
I think the best solution would be both; you have an option page for the output, but if you want to edit template files you can do that.
(__)
`
Andrew Rickmann
This is the sample comment.
You can see above that I am using WordPress 2.5.x. The statement is added using a template tag. Should I be aiming to add it automatically using choices from the admin panel? or are template tags a good thing?