• Hi all! I write a simple plugin to manage mailing lists and newsletter in WP. My question is: How to change the table structure during the installation if the table already exixts? Many people download my first version, and i just want to add some column in my second version.
    This is the code

    if ($wpdb->get_var("show tables like '$table_name_email'") != $table_name_email)
    {
    add_option("nl_db_version", "1.2");

    $sql = "CREATE TABLE " . $table_name_email . " (
    id_email int(11) NOT NULL AUTO_INCREMENT,
    id_lista int(11) default '1',
    contactname varchar(250) default NULL,
    email varchar(250) default NULL,
    magic_string varchar(250) default NULL,
    accepted varchar(1) default ‘n’,
    post_id mediumint(9) NULL,
    ipaddress VARCHAR(255) NULL,

    PRIMARY KEY (id_email),
    KEY id_lista (id_lista)

    );”;

    require_once(ABSPATH . ‘wp-admin/upgrade-functions.php’);
    dbDelta($sql);
    } else {

    //la tabella esiste verifico la versione e aggiorno i campi aggiungendo post_id e ip
    $sql=”ALTER TABLE ” . $table_name_email . “
    ADD COLUMN post_id INT(9) default NULL,
    ADD COLUMN ip_address VARCHAR(55) default NULL ;”;

    require_once(ABSPATH . ‘wp-admin/upgrade-functions.php’);
    dbDelta($sql);

    }

    Activating this plugin nothing happens! and i would like just to add 2 columns

  • The topic ‘Upgrading my own plugin problem’ is closed to new replies.