将此代码添加到插件文件中以注册激活挂钩
// register activation hook
register_activation_hook( __FILE__, \'my_rating_plugin_activation\' );
现在创建一个函数并将表创建代码添加到
function my_rating_plugin_activation() {
global $wpdb, $rating_table_name;
if($wpdb->get_var("SHOW TABLES LIKE \\"$rating_table_name\\"") != $rating_table_name) {
$wpdb->query("CREATE TABLE IF NOT EXISTS $rating_table_name (
rating_id int(11) NOT NULL AUTO_INCREMENT,
rating_postid int(11) NOT NULL,
rating_posttitle text NOT NULL,
rating_rating int(2) NOT NULL,
rating_timestamp varchar(15) NOT NULL,
rating_ip varchar(40) NOT NULL,
rating_host varchar(200) NOT NULL,
rating_username varchar(50) NOT NULL,
rating_userid int(10) NOT NULL DEFAULT \'0\',
comment_id int(11) NOT NULL,
PRIMARY KEY (rating_id)
) ENGINE=MyISAM");
}
}