· 6 years ago · Aug 03, 2019, 02:59 PM
1<?php
2// Создание
3function create_custom_table()
4{
5 global $wpdb;
6 require_once ABSPATH . 'wp-admin/includes/upgrade.php';
7 $table_name = $wpdb->prefix . 'test_table';
8 $charset_collate = "DEFAULT CHARACTER SET {$wpdb->charset} COLLATE {$wpdb->collate}";
9 $sql = "CREATE TABLE {$table_name} (
10 id bigint(20) unsigned NOT NULL auto_increment,
11 address varchar(255) NOT NULL default '',
12 alert varchar(20) NOT NULL default '',
13 meta longtext NOT NULL default '',
14 PRIMARY KEY (id),
15 KEY alert (alert)
16 )
17 {$charset_collate}";
18 dbDelta($sql);
19}
20create_custom_table();
21
22// Создание
23function drop_custom_table()
24{
25 global $wpdb;
26 $table_name = $wpdb->prefix . 'test_table';
27 $wpdb->query("DROP TABLE IF EXISTS {$table_name} ");
28}
29drop_custom_table();