The fertile playground of a WordPress developer
Balancing Tags

I’ve been meaning to incorporate the force_balance_tags() function into a few plugins that I’ve created which sample text from posts, but haven’t gotten to it yet. Well, today’s the day, and I’m going to experiment by writing some stuff in italics to see if it screws up my formatting on the page that uses the plugin.

The balance tags function is supposed to check a string of text for all the HTML tags used in that string to determine if there are unclosed tags. We shall see if this works or not. I have to write enough text that the closing tag is past the sample point, which in this case is eighty characters. If it works, everything on the page should look fine. If it does not, everything below my widget should be in italics. We shall see. . . .

You can clearly see that the formatting of this post was just silly and useless from a normal reading perspective.  But what has been proven here is that using the force_balance_tags() function will balance any and all tags and prevent a plugin from ruining your formatting by leaving tags open.  This is a very highly useful function that I plan to implement much, much more often in the future.

Fun With Plugin Development

I’ve just completed a new plugin, called the Titles to Tags plugin, which I’m sorta proud of. Basically, it checks the title of your post against a list of ignorable words, and then adds tags to your post automatically out of those words that did not appear on the ignore list. The idea is to automatically create a list of relevant keyword tags for your posts. The nice thing is: since I’ve learned to adopt the WordPress API, I’ve found that writing plugins often becomes a much less complex process.

For example, in this plugin, I have to add tags to a post. Obviously, I don’t want to create duplicate tags or create them incorrectly. The new tagging schema is quite complex in the database, and I don’t recommend anyone bother trying to create new tags directly. Instead, I used the wp_add_post_tags() function. This function first checks the current list of tags for the ones I want to add, then if none exist, it creates the tag automatically. This kills both birds with a single stone.

Plus, of course, if the underlying structure of WP should change - and we know it will, eventually - the API will either remain the same or be kept as vestigial, so the plugin doesn’t break because a blog owner did the responsible thing and upgraded to the current version. Another major advantage is that WordPress functions often go through rigorous standards testing and benchmarking, so by using API functions, you’re getting your best shot at creating a highly-compatible and optimized plugin.

I am currently testing a plugin

This is a test to see if my new plugin will work.  Cross yer fingers, y’all.