Support » Plugins » 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:
    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))”;

    } 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)”;

    $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’)”;
    $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))”;




Viewing 6 replies - 1 through 6 (of 6 total)
  • Same problem here. Very frustrating in plugin development. It’s been two weeks since this was posted, does anyone have any suggestions..

    Dear WordPress master,
    i’m also using “register_activation_hook” function, i’m try to create table but, it is not working.

    This is my code:
    function contact_install()
    global $wpdb;
    $contacts = $wpdb->prefix .”contacts”;
    $sql = “CREATE TABLE “. $contacts .” (
    user_id INT(9) NOT NULL
    UNIQUE KEY id (id)
    register_activation_hook(__FILE__, ‘contact_install’);

    please help me!

    Sorry, the error is my mistake, please ignore my post!

    southdreamz – what was the mistake?

    I just encountered a similar problem. My registration hook wasn’t firing.

    Eventually I tracked the problem down to a symbolic link. I’m in the habit of keeping plug-in code outside my wordpress tree, and just creating symlinks from in into the various wp-content/plugins directories where I want to test it.

    register_activation_hook() doesn’t like that, because it looks for the “wp-content/plugins” directory in the plug-in file’s canonical pathname. As soon as I physically copied my plug-in files into each WordPress tree, the activation hook started firing.

    alex_tingle –

    I got all my plugins under wp-content/plugins but it doesn’t work either

    could you help me?

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘register_activation_hook not firing after initial activation’ is closed to new replies.