jeudi 8 octobre 2015

Wordpress plugin is not creating table when activating

I am working to develop a plugin that needs to create a table in database here is my code please help the code is not showing any errors and not creating the table

public function create_phone_order_db() {

    global $wpdb;


$charset_collate = $wpdb->get_charset_collate();
$table_name = $wpdb->prefix . 'phone_orders';
    require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
    $sql = "CREATE TABLE IF NOT EXISTS " . $table_name . " ( 
        id INT NOT NULL AUTO_INCREMENT, 
        billing_country VARCHAR(100) NOT NULL, 
        billing_first_name VARCHAR(50) NOT NULL, 
        billing_last_name VARCHAR(50) NOT NULL, 
        billing_company VARCHAR(50) NOT NULL, 
        billing_address_1 VARCHAR(120) NOT NULL, 
        billing_address_2 VARCHAR(120) NOT NULL, 
        billing_city VARCHAR(50) NOT NULL, 
        billing_state VARCHAR(40) NOT NULL, 
        billing_postcode VARCHAR(8) NOT NULL, 
        billing_email VARCHAR(25) NOT NULL, 
        billing_phone VARCHAR(20) NOT NULL, 
        ship_to_different_address VARCHAR(10) NOT NULL, 
        shipping_country VARCHAR(50) NOT NULL, 
        shipping_first_name VARCHAR(40) NOT NULL, 
        shipping_last_name VARCHAR(40) NOT NULL, 
        shipping_company VARCHAR(50) NOT NULL, 
        shipping_address_1 VARCHAR(120) NOT NULL, 
        shipping_address_2 VARCHAR(120) NOT NULL, 
        shipping_city VARCHAR(50) NOT NULL, 
        shipping_state VARCHAR(50) NOT NULL, 
        shipping_postcode VARCHAR(8) NOT NULL, 
        admin_email_switched VARCHAR(25) NOT NULL, 
        admin_switched_id INT NOT NULL, 
        admin_user_name_switched VARCHAR(30) NOT NULL, 
        admin_role_switched VARCHAR(15) NOT NULL, 
        order_comments VARCHAR NOT NULL, 
        shipping_method VARCHAR NOT NULL, 
        payment_method VARCHAR NOT NULL, 
        _wpnonce VARCHAR NOT NULL, 
        _wp_http_referer VARCHAR NOT NULL, 
        PRIMARY KEY  (id)
        ) " . $charset_collate . ";";
    dbDelta($sql);
}

register_activation_hook( FILE, array($this, 'create_phone_order_db'));



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire