Skip to content

Instantly share code, notes, and snippets.

@yaleksandr89
Created July 22, 2019 20:15
Show Gist options
  • Select an option

  • Save yaleksandr89/40f6a3e3bd761084cae0f50790bb8435 to your computer and use it in GitHub Desktop.

Select an option

Save yaleksandr89/40f6a3e3bd761084cae0f50790bb8435 to your computer and use it in GitHub Desktop.
<?php
// Создание
function create_custom_table()
{
global $wpdb;
require_once ABSPATH . 'wp-admin/includes/upgrade.php';
$table_name = $wpdb->prefix . 'test_table';
$charset_collate = "DEFAULT CHARACTER SET {$wpdb->charset} COLLATE {$wpdb->collate}";
$sql = "CREATE TABLE {$table_name} (
id bigint(20) unsigned NOT NULL auto_increment,
address varchar(255) NOT NULL default '',
alert varchar(20) NOT NULL default '',
meta longtext NOT NULL default '',
PRIMARY KEY (id),
KEY alert (alert)
)
{$charset_collate}";
dbDelta($sql);
}
create_custom_table();
// Создание
function drop_custom_table()
{
global $wpdb;
$table_name = $wpdb->prefix . 'test_table';
$wpdb->query("DROP TABLE IF EXISTS {$table_name} ");
}
drop_custom_table();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment