A bunch of stuff I would have emailed you about.

Menu

More bsuite Hacking

Some conversations with Chow Kah Soon, who’s site is full of diversions from work , finally convinced encouraged me to solve some small problems that were giving him big trouble. Chow Kah Soon is in the lucky, but rare, position of having over 20,000 unique daily visitors to his site, so he’s sort of my designated stress-tester.

After looking at the logs he shared with me, the table structure, and the queries in bsuite, it was pretty clear that I needed to make some changes to the indexes.

Optimizing the indexes was easy, but how can I make bsuite update those indexes on existing installs? That’s where these docs explaining WordPress’ rather unique dbDelta function come in:

Instead of using a normal $wpdb query to make our table, there is a special function in WordPress that we’ll use that can create a table if it isn’t there, or change the structure if it doesn’t match the current table. This will come in very handy if we ever need to make changes to the MySQL structure in the future.

The function’s a little finicky, and it took me a couple minutes to realize that it was tripping up on the backtick quotes (`) I had wrapped around my table and field names. But with that out of the way, it solves the big problem of how to easily add indexes to existing tables. What it doesn’t solve, sadly, is how to delete existing indexes that aren’t in the new table definition.

With the dbDelta function implemented, I also finally got around to implementing an auto-install hook that creates or re-configs the tables upon plugin activation. Here’s the example from the docs:

…you simply have to use the path of your plugin relative to /wp-content/plugins. Eg: you have a plugin in /wp-content/plugins/wp-spamfilter/wp-spamfilter.php then you have to call add_action as following:

Post navigation

4 thoughts on “More bsuite Hacking”

I’ve tried twice recently to deactivate this plugin so it is only active when I want to view it (thinking it would be less of a load, just like my wp-slimstat suggest doing for their’s) but each time I tried with bsuite, my blog site goes completely void of data; the only thing displayed is my theme lol. Needless to say, I leave it active all the time now, have you run across this before? TIA.

I’ve noticed a small error in bsuite.php on l. 753: instead of using the variable get_settings(‘home’) you should use the variable get_settings(‘siteurl’), otherwise you won’t get the right path to spacer.gif in case wordpress is not in the same directory as index.php.