插件激活后创建表单
wptutor
2024-08-31
17 Views
register_activation_hook(__FILE__, 'cdu_activae_plugin');
function cdu_activae_plugin(){
global $wpdb;
$table_name = $wpdb->prefix . 'students_data';
$sql = "CREATE TABLE {$table_name} (
`id` INT(10) NOT NULL AUTO_INCREMENT,
`name` VARCHAR(50) NULL DEFAULT NULL COLLATE 'utf8mb4_unicode_520_ci',
`email` VARCHAR(50) NULL DEFAULT NULL COLLATE 'utf8mb4_unicode_520_ci',
`age` INT(10) NULL DEFAULT NULL,
`phone` VARCHAR(50) NULL DEFAULT NULL COLLATE 'utf8mb4_unicode_520_ci',
`photo` VARCHAR(120) NULL DEFAULT NULL COLLATE 'utf8mb4_unicode_520_ci',
PRIMARY KEY (`id`)
)
COLLATE='utf8mb4_unicode_520_ci'
ENGINE=InnoDB
";
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
dbDelta($sql);
}