-
Notifications
You must be signed in to change notification settings - Fork 34
/
bp-courseware.php
166 lines (145 loc) · 5.24 KB
/
bp-courseware.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
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
<?php
/*
Plugin Name: BuddyPress Courseware
Plugin URI: http://buddypress.coursewa.re/
Description: A LMS for BuddyPress.
Author: Stas Sușcov
Version: 0.9.8
License: GNU/GPL 2
Requires at least: WordPress 3.2, BuddyPress 1.5
Tested up to: WordPress 3.5 / BuddyPress 1.6
Author URI: https://github.com/Courseware/buddypress-courseware/contributors
Additional contributions:
Ian Dunn, Mădălin Ignișca, Stéphane Boisvert, Christian Wach
*/
// Exit if accessed directly
if ( !defined( 'ABSPATH' ) ) exit;
/*
* Avoid loading the plugin when BuddyPress is being activated, because there's no way to avoid fatal errors.
* Either BPSP will call a function that's undefined (because the mock isn't setup), or BuddyPress will try to redeclare a mocked function.
*/
if ( ! bpsp_activating_buddypress() ) {
// define constants
define( 'BPSP_VERSION', '0.9.8' );
define( 'BPSP_DEBUG', (bool) WP_DEBUG ); // This will allow you to see post types in wp-admin
define( 'BPSP_PLUGIN_DIR', dirname( __FILE__ ) );
define( 'BPSP_WEB_URI', WP_PLUGIN_URL . '/' . basename( BPSP_PLUGIN_DIR ) );
define( 'BPSP_PLUGIN_FILE', basename( BPSP_PLUGIN_DIR ) . '/' . basename( __FILE__ ) );
/* Load the components */
require_once ABSPATH . '/wp-admin/includes/plugin.php'; // To get is_plugin_active() for BuddyPress detection
require_once BPSP_PLUGIN_DIR . '/wordpress/wordpress.class.php';
require_once BPSP_PLUGIN_DIR . '/mock-buddypress/mock-buddypress.php';
require_once BPSP_PLUGIN_DIR . '/roles/roles.class.php';
require_once BPSP_PLUGIN_DIR . '/courses/courses.class.php';
require_once BPSP_PLUGIN_DIR . '/lectures/lectures.class.php';
require_once BPSP_PLUGIN_DIR . '/assignments/assignments.class.php';
require_once BPSP_PLUGIN_DIR . '/responses/responses.class.php';
require_once BPSP_PLUGIN_DIR . '/gradebook/gradebook.class.php';
require_once BPSP_PLUGIN_DIR . '/bibliography/bibliography.class.php';
require_once BPSP_PLUGIN_DIR . '/bibliography/webapis.class.php';
require_once BPSP_PLUGIN_DIR . '/schedules/schedules.class.php';
require_once BPSP_PLUGIN_DIR . '/groups/groups.class.php';
require_once BPSP_PLUGIN_DIR . '/dashboards/dashboards.class.php';
require_once BPSP_PLUGIN_DIR . '/static/static.class.php';
require_once BPSP_PLUGIN_DIR . '/activity/activity.class.php';
require_once BPSP_PLUGIN_DIR . '/notifications/notifications.class.php';
// decide how to init plugin in loader file
require_once( BPSP_PLUGIN_DIR . '/bp-courseware-loader.php' );
/**
* i18n
*/
function bpsp_textdomain() {
load_plugin_textdomain( 'bpsp', false, basename( BPSP_PLUGIN_DIR ) . '/languages' );
}
add_action( 'init', 'bpsp_textdomain' );
/**
* bpsp_check()
* Will check for Courseware dependencies and active components
*
* @return True on errors
* @uses `admin_notices`
*/
function bpsp_check() {
$messages = array();
if ( apply_filters( 'bpsp_require_buddypress', true ) ) {
if ( function_exists( 'bp_get_version' ) ) {
// @todo make sure that bbpress is enabled? or ignore?
//foreach( array( 'groups', 'activity', 'xprofile', 'forums', 'messages' ) as $c )
foreach( array( 'groups', 'activity', 'xprofile', 'messages' ) as $c ) {
if( !bp_is_active( $c ) ) {
$messages[] = sprintf(
__( 'BuddyPress Courseware dependency error: <a href="%1$s">%2$s has to be activated</a>!', 'bpsp' ),
admin_url( 'admin.php?page=bp-general-settings' ),
$c
);
}
}
} else {
$messages[] = sprintf(
__( 'BuddyPress Courseware dependency error: Please <a href="%1$s">install BuddyPress</a>!', 'bpsp' ),
admin_url( 'plugins.php' )
);
}
}
if( !empty( $messages ) ) {
echo '<div id="message" class="error fade">';
foreach ( $messages as $m ) {
echo "<p>{$m}</p>";
}
echo '</div>';
return false;
}
return true;
}
// Init the componenents
function bpsp_init() {
new BPSP_WordPress();
new BPSP_Roles();
new BPSP_Groups();
new BPSP_Courses();
new BPSP_Lectures();
new BPSP_Assignments();
new BPSP_Responses();
new BPSP_Gradebook();
new BPSP_Bibliography();
new BPSP_Schedules();
new BPSP_Dashboards();
new BPSP_Static();
new BPSP_Activity();
new BPSP_Notifications();
}
/**
* Register post types and taxonomies
*/
function bpsp_registration() {
BPSP_Courses::register_post_types();
BPSP_Lectures::register_post_types();
BPSP_Assignments::register_post_types();
BPSP_Responses::register_post_types();
BPSP_Gradebook::register_post_types();
BPSP_Bibliography::register_post_types();
BPSP_Schedules::register_post_types();
}
/* Activate the components */
function bpsp_activation() {
if( !bpsp_check() )
exit(1);
BPSP_Roles::register_profile_fields();
bpsp_registration();
flush_rewrite_rules();
}
register_activation_hook( BPSP_PLUGIN_FILE, 'bpsp_activation' );
/* Deactivate the components */
function bpsp_deactivation() {
flush_rewrite_rules();
}
register_deactivation_hook( BPSP_PLUGIN_FILE, 'bpsp_deactivation' );
}
function bpsp_activating_buddypress() {
global $pagenow;
$activating_buddypress = false;
if ( 'plugins.php' == $pagenow && isset( $_GET['action'], $_GET['plugin'] ) && 'activate' == $_GET['action'] && 'buddypress/bp-loader.php' == $_GET['plugin'] ) {
$activating_buddypress = true;
}
return $activating_buddypress;
}