-
Notifications
You must be signed in to change notification settings - Fork 0
/
db.php
74 lines (65 loc) · 2.87 KB
/
db.php
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
<?php
function bbconnect_personalisation_updates() {
// Get current version
$dbv = get_option('_bbconnect_personalisation_version', 0);
// If it's not the latest, run our updates
if (version_compare($dbv, BBCONNECT_PERSONALISATION_VERSION, '<')) {
// List of versions that involved a DB update - each one must have a corresponding function below
$db_versions = array(
'0.1',
'0.1.1',
);
foreach ($db_versions as $version) {
if (version_compare($version, $dbv, '>')) {
update_option('_bbconnect_personalisation_version', $version);
call_user_func('bbconnect_personalisation_db_update_'.str_replace('.', '_', $version));
}
}
update_option('_bbconnect_personalisation_version', BBCONNECT_PERSONALISATION_VERSION);
}
}
function bbconnect_personalisation_db_update_0_1() {
// Add new unique key field
$field = array(
array('source' => 'bbconnect', 'meta_key' => 'personalisation_key', 'tag' => '', 'name' => __('Unique Key', 'bbconnect'), 'options' => array('admin' => true, 'user' => true, 'signup' => false, 'reports' => true, 'public' => false, 'req' => false, 'field_type' => 'text', 'choices' => array()), 'help' => ''),
);
$field_keys = array();
foreach ($field as $key => $value) {
if (false != get_option('bbconnect_'.$value['meta_key'])) {
continue;
}
$field_keys[] = $value['meta_key'];
add_option('bbconnect_'.$value['meta_key'], $value);
}
$umo = get_option('_bbconnect_user_meta');
if (!empty($field_keys)) {
foreach ($umo as $uk => $uv) {
// Add to the account info section
foreach ($uv as $suk => $suv) {
if ('bbconnect_account_information' == $suv) {
$acct = get_option($suv);
foreach ($field_keys as $fk => $fv) {
$acct['options']['choices'][] = $fv;
}
update_option($suv, $acct);
$aok = true;
}
}
}
// If we couldn't find the account info section just add to column 3
if (!isset($aok)) {
foreach ($field_keys as $fk => $fv) {
$umo['column_3'][] = 'bbconnect_' . $fv;
}
update_option('_bbconnect_user_meta', $umo);
}
}
}
function bbconnect_personalisation_db_update_0_1_1() {
// Generate a unique key for all existing users
wp_schedule_single_event(time()-24*HOUR_IN_SECONDS, 'bbconnect_personalisation_generate_keys_for_all_users');
}
function bbconnect_personalisation_db_update_0_1_3() {
// Schedule hourly check for any users who may have somehow missed out on a key
wp_schedule_event(time(), 'hourly', 'bbconnect_personalisation_generate_keys_for_all_users');
}