register_activation_hook not firing after initial activation
-
I’m using register_activation_hook in my plugin and it works fine on the initial activation, but when I de-activate and re-activate the plug-in as I have to do sometimes in development, register_activation_hook stops working. It doesn’t even access the function. Is there a reason for this?
Here is the code:
`functions
if ( !function_exists(‘artdb_install’) ) :function artdb_install () {
global $wpdb;
$wpdb->artists = $wpdb->prefix . “artists”;
$wpdb->art_types = $wpdb->prefix . “art_types”;
$wpdb->art_images = $wpdb->prefix . “art_images”;$table_name = $wpdb->prefix . “artists”;
if($wpdb->get_var(“show tables like ‘$table_name'”) != $table_name) {$sql = “CREATE TABLE ” . $table_name . ” (user_id bigint(20) NOT NULL, photo VARCHAR(35) NULL, bio longtext NULL, phone VARCHAR(10) NULL, inactive VARCHAR(1) NOT NULL, recchange VARCHAR(150) NULL, chgdate DATE NULL, uniqueurl VARCHAR(25) NULL, UNIQUE KEY user_id (user_id))”;
$wpdb->query(“$sql”);
} else {
$columns = $wpdb->get_results(“SHOW COLUMNS FROM ‘$table_name'”);
$hasurl = false;
foreach ($columns as $k => $v) {
echo $v->field;
if ($v->field = ‘photo’) {
$hasurl = true;
}
}
if (!$hasurl) {
$wpdb->query(“ALTER TABLE ‘$table_name’ ADD uniqueurl VARCHAR( 25 ) NULL AFTER ‘chgdate'”);
}}
$table_name = $wpdb->prefix . “art_types”;
if($wpdb->get_var(“show tables like ‘$table_name'”) != $table_name) {$sql = “CREATE TABLE ” . $table_name . ” (user_id bigint(20) NOT NULL, art_type VARCHAR(25) NOT NULL)”;
$wpdb->query(“$sql”);$initialtypes = array(1 => ‘Pictorial’, ‘Sculpture’, ‘Pottery’, ‘Photography’, ‘Watercolor’, ‘Mixed Media’, ‘Oils’, ‘Pastels’);
foreach ($initialtypes as $k => $v) {
$sql = “INSERT INTO $wpdb->art_types (user_id, art_type) VALUES (‘999999’, ‘$v’)”;
$wpdb->query(“$sql”);
}
}
$table_name = $wpdb->prefix . “art_images”;
if($wpdb->get_var(“show tables like ‘$table_name'”) != $table_name) {$sql = “CREATE TABLE ” . $table_name . ” (user_id bigint(20) NOT NULL, image VARCHAR(35) NOT NULL, title VARCHAR(50))”;
$wpdb->query(“$sql”);
}}
endif;register_activation_hook(__FILE__,’artdb_install’);
- The topic ‘register_activation_hook not firing after initial activation’ is closed to new replies.