Support » Plugins » register_activation_hook not working

  • Hi,

    My code is as below.But it is not working.
    <?
    if (!defined(‘PLUGINDIR’)) {
    define(‘PLUGINDIR’,’wp-content/plugins’);
    }

    if (is_file(trailingslashit(ABSPATH.PLUGINDIR).’myplugin6.php’)) {
    define(‘AKTT_FILE’, trailingslashit(ABSPATH.PLUGINDIR).’/myplugin6.php’);
    }
    else if (is_file(trailingslashit(ABSPATH.PLUGINDIR).’/myplugin6/myplugin6.php’)) {
    define(‘AKTT_FILE’, trailingslashit(ABSPATH.PLUGINDIR).’/myplugin6/myplugin6.php’);
    }
    global $wpdb;

    function myplugin_activate()
    {
    global $wpdb;
    $table = $wpdb->prefix.”sh_gloss”;

    require_once(ABSPATH . ‘wp-admin/includes/upgrade.php’);

    $structure = “CREATE TABLE $table (
    id INT(9) NOT NULL AUTO_INCREMENT,
    phrase VARCHAR(80) NOT NULL,
    desc VARCHAR(255) NOT NULL,
    UNIQUE KEY id (id));”;

    dbDelta($structure);

    // Populate table
    $wpdb->query(“INSERT INTO $table(phrase, desc)
    VALUES(‘Scott Herbert’, ‘Rockstar Programmer’)”);

    }

    register_activation_hook( AKTT_FILE, ‘myplugin_activate’ );
    ?>
    What could be the reason?

    Thanks
    Pradeep

Viewing 2 replies - 1 through 2 (of 2 total)
  • Have you tried the wp-hackers mailing list?

    Thread Starter sturdyindian

    (@sturdyindian)

    Hi,
    It is working now.
    Updated Code below.

    <?
    /*
    Plugin Name: My Plugin 8
    Plugin URI: http://www.example.com/myplugin
    Description: This is a really great plugin that extends WordPress.
    Version: 1.0.0
    Author: Pradeep
    */
    function fun_install_tables () {
    global $wpdb;
    $charset_collate = ”;
    if ( version_compare(mysql_get_server_info(), ‘4.1.0’, ‘>=’) ) {
    if (!empty($wpdb->charset)) {
    $charset_collate .= ” DEFAULT CHARACTER SET $wpdb->charset”;
    }
    if (!empty($wpdb->collate)) {
    $charset_collate .= ” COLLATE $wpdb->collate”;
    }
    }
    $table=$wpdb->prefix.”test”;
    $sql=”CREATE TABLE IF NOT EXISTS $table (
    id int(11) NOT NULL auto_increment,
    name varchar(50) collate utf8_unicode_ci NOT NULL,
    PRIMARY KEY (id)
    )$charset_collate;”;
    require_once(ABSPATH . ‘wp-admin/includes/upgrade.php’);
    dbDelta($sql);
    $sql = “insert into $table (name)values(‘apj kalam’)”;
    $wpdb->query($sql);

    }
    register_activation_hook(__FILE__,’fun_install_tables’);
    ?>

    Thanks…

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘register_activation_hook not working’ is closed to new replies.