-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTinyLxp-wp-plugin.php
More file actions
125 lines (110 loc) · 3.89 KB
/
TinyLxp-wp-plugin.php
File metadata and controls
125 lines (110 loc) · 3.89 KB
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<?php
/*
* wordpress-tiny-lxp-platform - Enable WordPress to act as an Tiny LXP Platform.
* Copyright (C) 2022 Waqar Muneer
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Contact: Waqar Muneer <waqarmuneer@gmail.com>
*/
/*
Plugin Name: Tiny Lxp
Plugin URI: https://github.com/i-do-dev/TinyLxp-wp-plugin
Text Domain: TinyLxp-wp-plugin
Description: This plugin allows WordPress to act as a Platform using the IMS Learning Tools Interoperability (Tiny LXP) specification.
Version: 2.0.3
Author: Waqar Muneer
Author URI: https://github.com/i-do-dev/TinyLxp-wp-plugin
License: GPL3
*/
// If this file is called directly, abort.
if (!defined('WPINC')) {
die;
}
/**
* Current plugin name.
*/
define('Tiny_LXP_PLATFORM_NAME', 'lti-platform');
/**
* Current plugin version.
*/
define('Tiny_LXP_PLATFORM_VERSION', '2.0.3');
/**
* The core plugin class that is used to define internationalization,
* admin-specific hooks, and public-facing site hooks.
*/
require plugin_dir_path(__FILE__) . 'includes/class-tiny-lxp-platform.php';
/**
* Begins execution of the plugin.
*
* Since everything within the plugin is registered via hooks,
* then kicking off the plugin from this point in the file does
* not affect the page life cycle.
*
* @since 1.0.0
*/
function run_tiny_lxp_platform()
{
$plugin = new Tiny_LXP_Platform();
if ($plugin->isOK()) {
$plugin->run();
}
}
run_tiny_lxp_platform();
register_activation_hook(__FILE__, 'on_activate');
function on_activate() {
global $wpdb;
$wpdb->query("CREATE TABLE IF NOT EXISTS {$wpdb->prefix}tiny_lms_grades(
id bigint(20) unsigned NOT NULL AUTO_INCREMENT,
lesson_id bigint(20) default NULL,
score FLOAT default NULL,
user_id bigint(20) default NULL,
PRIMARY KEY (id)
)");
// Check if the pages already exist to avoid duplication
$pagesArray = array(
['title' => 'Assignment','content' =>''],
['title' => 'Assignments','content' =>''],
['title' => 'Calendar','content' =>''],
['title' => 'Classes','content' =>''],
['title' => 'Courses','content' =>''],
['title' => 'Dashboard','content' =>''],
['title' => 'Districts','content' =>''],
['title' => 'Grade Assignment','content' =>''],
['title' => 'Grade Summary','content' =>''],
['title' => 'Grades','content' =>''],
['title' => 'Groups','content' =>''],
['title' => 'Lessons','content' =>''],
['title' => 'Login','content' =>''],
['title' => 'Sample Page','content' =>''],
['title' => 'Schools','content' =>''],
['title' => 'Search','content' =>''],
['title' => 'Students','content' =>''],
['title' => 'Teachers','content' =>'']
);
foreach ($pagesArray as $newPage) {
$pageExist = $wpdb->get_row($wpdb->prepare("SELECT * FROM $wpdb->posts WHERE post_title = %s AND post_type = 'page' AND post_status = 'publish' ", $newPage['title']));
if (!$pageExist) {
// Page does not exist, create it
$page = array(
'post_title' => $newPage['title'],
'post_content' => $newPage['content'],
'post_status' => 'publish',
'post_type' => 'page',
);
wp_insert_post($page);
}
}
}