/
register.php
95 lines (81 loc) · 2.62 KB
/
register.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<?php
function load_course_roles()
{
global $wp_roles;
if (!$wp_roles->is_role('course_manager')) {
_c('Course Manager|User role');
$author = get_role('author');
add_role('course_manager', 'Course Manager|User role', $author->capabilities);
$role = get_role('course_manager');
$role->add_cap('manage_courses');
$role = get_role('administrator');
$role->add_cap('manage_courses');
}
}
function unload_course_roles()
{
global $wp_roles;
if ($wp_roles->is_role('course_manager')) {
$role = get_role('administrator');
$role->remove_cap('manage_courses');
$wp_roles->remove_role('course_manager');
}
}
function load_course_options()
{
add_option('lms_signup_period', 18);
add_option('lms_courses_page_id');
add_option('lms_currency', '€');
add_option('lms_contact', '');
add_option('lms_template_signup_subject', __( 'Your training info', 'warp_lms' ));
add_option('lms_template_signup', '');
add_option('lms_signup_notification', true);
}
function unload_course_options()
{
// delete_option('lms_signup_period');
// delete_option('lms_courses_page_id');
}
function create_lms_tables()
{
global $wpdb;
$table_name = $wpdb->prefix . "lms_instances";
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
if ($wpdb->get_var("SHOW TABLES LIKE '$table_name'") != $table_name) {
$sql = "CREATE TABLE $table_name (
id mediumint(9) UNSIGNED NOT NULL AUTO_INCREMENT,
start_date date NOT NULL,
end_date date NOT NULL,
course_id bigint(20) UNSIGNED NOT NULL,
PRIMARY KEY(id),
FOREIGN KEY (course_id) REFERENCES " . $wpdb->prefix . "posts (ID)
)";
dbDelta($sql);
}
$table_name = $wpdb->prefix . "lms_students";
if ($wpdb->get_var("SHOW TABLES LIKE '$table_name'") != $table_name) {
$sql = "CREATE TABLE $table_name (
id mediumint(9) UNSIGNED NOT NULL AUTO_INCREMENT,
first_name varchar(50) NOT NULL,
last_name varchar(100) NOT NULL,
company varchar(100) NOT NULL,
email varchar(255) NOT NULL,
phone varchar(35) NOT NULL,
PRIMARY KEY (id)
)";
dbDelta($sql);
}
$table_name = $wpdb->prefix . "lms_registrations";
if ($wpdb->get_var("SHOW TABLES LIKE '$table_name'") != $table_name) {
$sql = "CREATE TABLE $table_name (
course_id mediumint(9) UNSIGNED NOT NULL,
student_id mediumint(9) UNSIGNED NOT NULL,
PRIMARY KEY (course_id, student_id),
FOREIGN KEY (course_id) REFERENCES " . $wpdb->prefix . "lms_instances (id),
FOREIGN KEY (student_id) REFERENCES " . $wpdb->prefix . "lms_students (id)
)";
dbDelta($sql);
}
add_option('warp_lms_version', warp_lms_version);
update_option('warp_lms_version', warp_lms_version);
}