create a plagin code

Enough talking it is time to write some code, let’s start with function, which will be responsible for creating additional table in our database and populating it with two records. In this table we will keep information about different bots and their visits number.

function bot_install()
global $wpdb;
$table = $wpdb->prefix.”bot_counter”;
$structure = “CREATE TABLE $table (
bot_name VARCHAR(80) NOT NULL,
bot_mark VARCHAR(20) NOT NULL,
bot_visits INT(9) DEFAULT 0,
UNIQUE KEY id (id)

// Populate table
$wpdb->query(“INSERT INTO $table(bot_name, bot_mark)
VALUES(‘Google Bot’, ‘googlebot’)”);
$wpdb->query(“INSERT INTO $table(bot_name, bot_mark)
VALUES(‘Yahoo Slurp’, ‘yahoo’)”);

so our best shot will be “activate” Plugin Hook, but be careful these one is a bit tricky.

All of WordPress actions are predefined, all except these one. Look at the code:

add_action(‘activate_bot/bots.php’, ‘bot_install’);


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s