Introducing WP-Table Reloaded Extensions

December 28th, 2009 by Tobias Leave a reply »

One of the main additions to version 1.5 of WP-Table Reloaded were so-called “Plugin Actions” and “Plugin Filters”. Both are part of the “Plugin Hooks”, a widely used concept within WordPress. This explanation from the WordPress Codex sums it up.

The way Plugin hooks work is that at various times while WordPress is running, WordPress checks to see if any Plugins have registered functions to run at that time, and if so, the functions are run. These functions modify the default behavior of WordPress.

Well known hooks are for example “wp_head” and “wp_footer”, which allow adding functions to the head and footer of a page that was generated by WordPress.

Actions and Filters can not only be used by the WordPress Core, but also by plugins and it is possible to add new ones. And this is what I did in WP-Table Reloaded 1.5. Many of these hooks were added to the plugin which now allow other plugins to add or change functions in WP-Table Reloaded.

These new functions may be as short as one line or as long as a complete new plugin. For WP-Table Reloaded, I will – over the course of the next weeks and months, but with no fixed time frame or frequency – present such pieces of code on this website, as a series of blog posts. As these code snippets are not complete WordPress plugins, I will call them WP-Table Reloaded Extensions, as that describes what they are a little bit better.

Before adding any Extensions, we need to establish a foundation for them. There are two possible ways: As they (mostly) are pretty short (only one or two PHP functions and only few lines of code), they can simply be added to the file “functions.php” of the currently used theme. While that is possible, I don’t really recommend it, because it mixes theme and plugin code. And it requires special attention, if e.g. the theme is switched.
The other (and recommended) way is to create a new plugin file that will hold all of the extensions. That file (which should be called “wp-table-reloaded-extensions.php”) simply needs to be put into the WordPress “plugins” folder (a sub-directory of “wp-content”). It *MUST NOT* be placed in the WP-Table Reloaded plugin directory (“wp-table-reloaded”), because it will be deleted from there by WordPress, once WP-Table Reloaded is updated.

This file is nothing else than a regular WordPress Plugin, with all the advantages, like separation of theme and plugin code, i.e. no problems when switching the theme. It must be activated like any other plugin, which obviously creates the advantage it can be deactivated any time, if its functionality is no longer needed.

The contents of that file (“wp-table-reloaded-extensions.php” in the folder “plugins”) are (for now):

<?php
/*
Plugin Name: WP-Table Reloaded Extensions
Plugin URI: http://tobias.baethge.com/wordpress-plugins/wp-table-reloaded-english/extensions/
Description: Custom Extensions for WP-Table Reloaded 
Version: 1.0
Author: YOU, Tobias Baethge
*/
 
// this is where the actual code goes

As you will certainly see, the file does not yet contain any real PHP code, but just comments. These comments are the so-called “Plugin Header”, that every WordPress Plugin must contain to be recognized as such.

All new code now has to be added to this file (after these comments and *before* the closing PHP bracket (?>).

So, a quick summary to get started with WP-Table Reloaded Extensions:

  • Copy the code from above into a new text file.
  • Save that file as “wp-table-reloaded-extensions.php”.
  • Move it to the directory “/wp-contents/plugins/” of your WordPress installation on your server (but NOT into the “wp-table-reloaded” folder!)
  • Activate the newly available plugin “WP-Table Reloaded Extensions” from the WordPress Plugins screen.
  • Any code for an Extension (that will be presented throughout the announced series of sporadic blog posts) has to be added to that file (below the existing code and above the ?> in the last line of code).
  • Of course you can add more than one Extension to that file (I recommend to separate them by a comment line that describes what each part does.)

To start off the series in the next days, I will show you a way to automatically convert URLs in a table into complete HTML links – without the need of having to use the Link Wizard on the “Edit table” screen.

If you have any questions or feedback, just let me know. I’m also open to ideas or solutions that involve Actions and Filters. So, if you have any input on this, just contact me or leave a comment!

I hope that we’ll have a lot of fun with WP-Table Reloaded Extensions and that they provide valuable functions and maybe even a plugin develepment learning experience to you.

2 comments

  1. This is very good news. I activated your code and wait for the exciting stuff to come. (And I made a small donation, for your enthousiastic work on this very fine plugin.)

  2. Many thanks for the formidable set of plugins. Everything needed in a sortable table!