WordPress.org

Ready to get started?Download WordPress

Forums

register_activation_hook JUST WON'T WORK (7 posts)

  1. lucasrcosta
    Member
    Posted 4 years ago #

    All of these do NOT WORK. What I'm I missing?

    register_activation_hook(__FILE__,'teste');
    register_deactivation_hook(__FILE__, 'teste');
    register_activation_hook(__FILE__,array(&$this,'teste'));
    register_deactivation_hook(__FILE__,array(&$this,'teste'));

    function teste() {
    echo "A Simple echo function to see if it works";
    }

  2. god0fgod
    Member
    Posted 4 years ago #

    It's the same with me. What the heck is wrong with it. I tried looking for any output in the source but it isn't there:

    Nothing from "echo "DBINFO:" . dbDelta($sql);" here. Only the relevant parts were copied.
    <?
    function create_links_table(){
    //Create link table
    global $wpdb;
    $table_name = $wpdb->prefix . "fim_links";
    if($wpdb->get_var("SHOW TABLES LIKE '$table_name'") != $table_name) {
    $sql = "CREATE TABLE " . $table_name . " (
    order mediumint(9) NOT NULL AUTO_INCREMENT,
    href text DEFAULT '#' NOT NULL,
    id text DEFAULT '0' NOT NULL,
    block mediumint(9) DEFAULT '1' NOT NULL,
    PRIMARY KEY order (order)
    );";
    require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
    echo "DBINFO:" . dbDelta($sql);
    $sql = "INSERT INTO " . $table_name .
    " (href, id) " .
    "VALUES ('http://crytekuk.info','link_example')";
    $wpdb->query($sql);
    }
    }
    function setup_fim(){
    setup_themes();
    add_option("fim_version",FIM_VERSION);
    add_option("fim_widgets","links,ajax_login");
    create_links_table();
    }
    register_activation_hook(__FILE__, "setup_fim");
    ?>

  3. god0fgod
    Member
    Posted 4 years ago #

    Oh, and the table isn't created.

  4. lexayo
    Member
    Posted 4 years ago #

    me too
    so i do this :

    function silex_activation_hook(){
    .................
    }

    // does not work => call it directly register_activation_hook( __FILE__, 'silex_activation_hook');
    if ($_GET['activate'] == true)
    {
    silex_activation_hook();
    }

  5. mgtonelli
    Member
    Posted 4 years ago #

    got the same issue, did any of you guys found a solution or had implemented a work around to make it work???

    need to create tables on the DB, not able to do that since 'register_activation_hook' just doesn't work..

    regards..

  6. gesman
    Member
    Posted 4 years ago #

    See my post with sample of working code here:
    http://wordpress.org/support/topic/312342?replies=2#post-1226615

    Gleb

  7. s_ha_dum
    Member
    Posted 4 years ago #

    From inside a PHP class in a plugin, this works for me:

    register_activation_hook(ABSPATH.PLUGINDIR.'/<pluginfoldername>/<pluginname>.php',array(&$this,'<functiontorun>'));

    gesman's code looks to me to be essentially the but is not inside a class.

    You should also think about whether it is register_activation_hook that is failing or the function being called that is failing. This bit from gesman's link is a very good way to start sorting that out:

    // If you want to quickly test if your activation hook works - put exit() into it. At least you'll see error during activation.

Topic Closed

This topic has been closed to new replies.

About this Topic