Originally posted on the WordPress forums but no-one answered... so I'll try my luck here...
Hi all,
I'm trying to learn to write a WordPress plugin by setting myself a goal of witting a user generated glossary plugin after I asked people on Twitter what would be useful (well I may as well use my learning experience to be useful for more than just me).
Anyway, on installation the plugin sets up a database table, and adds some test data to it. Then when the content is displayed a foreach loop changes each phrase and replaces it with a DHTML floaty box.
The problem is, however, I can't work out what's going on with the register_activation_hook
; it may be being called and the SQL is failing or it may not be being called (either way I don't have an extra table in the database after I activate the plugin).
The hook looks like this:
register_activation_hook(__FILE__, "bot_install");
And the bot_install code like this
function bot_install()
{
global $wpdb;
$table = $wpdb->prefix."sh_gloss";
$structure = "CREATE TABLE $table (
id INT(9) NOT NULL AUTO_INCREMENT,
phrase VARCHAR(80) NOT NULL,
desc VARCHAR(255) NOT NULL,
UNIQUE KEY id (id)
);";
$wpdb->query($structure);
// Populate table
$wpdb->query("INSERT INTO $table(phrase, desc)
VALUES('Scott Herbert', 'Rockstar Programmer')");
}
OK so firstly please forgive the ego database entry, it's just for testing...
Secondly is there something I should have seen that I've missed? And thirdly (and most importantly) how can I debug "bot_install"? Can I just add statements like:
echo "in xxxx";
or will that mess up the headers (since I guess all this code is ran before the main output).
Thanks in advance Scott