Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<?php
$SPACES_TABLE = get_table_name("spaces");
$NODES_TABLE = get_table_name("nodes");
$NODETYPES_TABLE = get_table_name("nodetypes");
$LINKS_TABLE = get_table_name("links");
$REFERENCES_TABLE = get_table_name("references");
global $ks_db_version;
$ks_db_version = '1.0';
function get_table_name($table)
{
global $wpdb;
return $wpdb->prefix . "ks_" . $table;
}
register_activation_hook(__FILE__, 'ks_install');
function ks_install()
{
global $wpdb;
global $ks_db_version;
$installed_ver = get_option("ks_db_version");
if ($installed_ver == $ks_db_version) {
return;
}
$charset_collate = $wpdb->get_charset_collate();
require_once(__DIR__ . '/../../../wp-admin/includes/upgrade.php');
global $SPACES_TABLE;
$sql = "CREATE TABLE $SPACES_TABLE (
space_id int(11) NOT NULL AUTO_INCREMENT,
name text NOT NULL,
description text NOT NULL,
PRIMARY KEY (space_id)
) $charset_collate;";
dbDelta($sql); //! Has some weird restrictions for the SQL Query: https://codex.wordpress.org/Creating_Tables_with_Plugins
global $NODETYPES_TABLE;
$sql = "CREATE TABLE $NODETYPES_TABLE (
nodetype_id int(11) NOT NULL AUTO_INCREMENT,
name text NOT NULL,
color bit(24) NOT NULL,
PRIMARY KEY (nodetype_id)
) $charset_collate;";
dbDelta($sql); //! Has some weird restrictions for the SQL Query: https://codex.wordpress.org/Creating_Tables_with_Plugins
global $NODES_TABLE;
$sql = "CREATE TABLE $NODES_TABLE (
node_id int(11) NOT NULL AUTO_INCREMENT,
title text NOT NULL,
description text NOT NULL,
icon_url text,
header_url text,
video_url text,
nodetype_id int(11) NOT NULL,
space_id int(11) NOT NULL,
PRIMARY KEY (node_id)
) $charset_collate;";
dbDelta($sql); //! Has some weird restrictions for the SQL Query: https://codex.wordpress.org/Creating_Tables_with_Plugins
global $LINKS_TABLE;
$sql = "CREATE TABLE $LINKS_TABLE (
link_id int(11) NOT NULL AUTO_INCREMENT,
source_node_id int(11) NOT NULL,
target_node_id int(11) NOT NULL,
PRIMARY KEY (link_id)
) $charset_collate;";
dbDelta($sql); //! Has some weird restrictions for the SQL Query: https://codex.wordpress.org/Creating_Tables_with_Plugins
global $REFERENCES_TABLE;
$sql = "CREATE TABLE $REFERENCES_TABLE (
reference_id int(11) NOT NULL AUTO_INCREMENT,
url text NOT NULL,
node_id int(11) NOT NULL,
PRIMARY KEY (reference_id)
) $charset_collate;";
dbDelta($sql); //! Has some weird restrictions for the SQL Query: https://codex.wordpress.org/Creating_Tables_with_Plugins
add_option('ks_db_version', $ks_db_version);
}
// Handling upgrade
function ks_update_db_check()
{
global $ks_db_version;
if (get_site_option('ks_db_version') != $ks_db_version) {
ks_install();
}
}
add_action('plugins_loaded', 'ks_update_db_check');