I am trying to create some custom database table on wordpress plugin activation with php oop concept. But no database is created after plugin activation. Here is my code
class wpe_Main {
public function __construct() {
register_activation_hook( __FILE__, array($this,'create_wpe_enquiry_table'));
}
public function create_wpe_enquiry_table(){
global $wpdb;
$sql_enquiry = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}wpe_enquiry (
`id` int(11) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
`userid` int(11) NOT NULL,
`enquiry_type_id` varchar(3) NOT NULL,
`contact_email` varchar(200) NOT NULL,
`contact_number` varchar(50) NOT NULL,
`contact_messenger` varchar(200) NOT NULL,
`query_title` varchar(200) NOT NULL,
`query_content` text NOT NULL,
`attachment1` varchar(200) NOT NULL,
`attachment2` varchar(200) NOT NULL,
`attachment3` varchar(200) NOT NULL,
`user_ip` varchar(50) NOT NULL,
`query_cdate` DATETIME DEFAULT CURRENT_TIMESTAMP,
`query_udate` DATETIME ON UPDATE CURRENT_TIMESTAMP,
`status` varchar(2) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8";
$sql_enquiry_reply = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}wpe_query_reply (
`id` int(11) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
`quiry_id` int(11) NOT NULL,
`reply_content` text NOT NULL,
`user_ip` varchar(50) NOT NULL,
`reply_cdate` DATETIME DEFAULT CURRENT_TIMESTAMP,
`reply_udate` DATETIME ON UPDATE CURRENT_TIMESTAMP,
`status` varchar(2) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8";
$sql_enquiry_type = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}wpe_query_part (
`id` int(11) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
`part_value` int(11) NOT NULL,
`part_name` varchar(200) NOT NULL,
`user_ip` varchar(50) NOT NULL,
`reply_cdate` DATETIME DEFAULT CURRENT_TIMESTAMP
) ENGINE=MyISAM DEFAULT CHARSET=utf8";
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
dbDelta( $sql_enquiry );
dbDelta( $sql_enquiry_reply );
dbDelta( $sql_enquiry_type );
}
} $wpuf = new wpe_Main();
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire