WordPress.org

Ready to get started?Download WordPress

Forums

register_activation_hook not working (3 posts)

  1. sturdyindian
    Member
    Posted 4 years ago #

    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

  2. trigmed
    Member
    Posted 4 years ago #

    Have you tried the wp-hackers mailing list?

  3. sturdyindian
    Member
    Posted 4 years ago #

    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...

Topic Closed

This topic has been closed to new replies.

About this Topic