WordPress.org

Ready to get started?Download WordPress

Forums

Registering an activation hook doesn't seem to work (2 posts)

  1. vtblogmu
    Member
    Posted 2 years ago #

    I have the following declared at the top of a php file called myplugin.php:

    register_activation_hook('myplugin.php', 'setup');

    Setup creates some new tables in the database:

    function setup() {

    global $wpdb;

    $table = $wpdb->prefix."post_votes";
    $wpdb->query("DROP TABLE IF EXISTS ".$table);

    $wpdb->query("CREATE TABLE IF NOT EXISTS wp_post_votes (
    post_id int(11) DEFAULT NULL,
    blog_id int(11) DEFAULT NULL,
    vote_count int(11) DEFAULT NULL
    ) ENGINE=MyISAM DEFAULT CHARSET=latin1;");

    $table = $wpdb->prefix."user_votes";
    $wpdb->query("DROP TABLE IF EXISTS ".$table);

    $wpdb->query("CREATE TABLE IF NOT EXISTS wp_user_votes (
    user_id int(11) DEFAULT NULL,
    post_id int(11) DEFAULT NULL,
    blog_id int(11) DEFAULT NULL
    ) ENGINE=MyISAM DEFAULT CHARSET=latin1;");
    }

    The tables are never created so it has led me to believe that the setup function is not being called. Any ideas on how to fix?

    I'm network activating if that makes a difference...

  2. timDesain
    Member
    Posted 2 years ago #

    myplugin.php is inside subfolder of wp plugins.

    replace
    register_activation_hook('myplugin.php', 'setup');
    with
    register_activation_hook( __FILE__ , 'setup');

    and
    replace wp_post_votes with ".$table."
    replace wp_user_votes with ".$table."

Topic Closed

This topic has been closed to new replies.

About this Topic