-
Notifications
You must be signed in to change notification settings - Fork 88
Expand file tree
/
Copy pathAddons.php
More file actions
354 lines (314 loc) · 11.8 KB
/
Copy pathAddons.php
File metadata and controls
354 lines (314 loc) · 11.8 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
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
<?php
/**
* Manage Addons
*
* @package Tutor
* @author Themeum <support@themeum.com>
* @link https://themeum.com
* @since 1.0.0
*/
namespace TUTOR;
defined( 'ABSPATH' ) || exit;
/**
* Addons Class
*
* @since 1.0.0
*/
class Addons {
const OPTION_KEY = 'tutor_addons_config';
/**
* Constructor
*
* @since 1.0.0
*
* @return void
*/
public function __construct() {
add_filter( 'tutor_pro_addons_lists_for_display', array( $this, 'addons_lists_to_show' ) );
add_action( 'wp_ajax_tutor_get_all_addons', array( $this, 'get_all_addons' ) );
add_action( 'wp_ajax_addon_enable_disable', array( $this, 'addon_enable_disable' ) );
}
/**
* Obtain addons config list.
*
* @since 3.0.0
*
* @return array
*/
public static function get_addons_config() {
$list = get_option( self::OPTION_KEY, array() );
return $list;
}
/**
* Status update of tutor addon.
*
* @since 3.0.0
*
* @param string $basename basename of addon.
* @param bool $status status 0,1.
*
* @return void
*/
public static function update_addon_status( $basename, $status ) {
$config = self::get_addons_config();
if ( isset( $config[ $basename ] ) ) {
$config[ $basename ]['is_enable'] = $status;
update_option( self::OPTION_KEY, $config );
}
}
/**
* Get all addons data.
*
* @since 1.0.0
*
* @return void
*/
public function get_all_addons() {
// Check and verify the request.
tutor_utils()->checking_nonce();
if ( ! User::is_admin() ) {
wp_send_json_error( tutor_utils()->error_message() );
}
// All good, let's proceed.
$all_addons = $this->prepare_addons_data();
wp_send_json_success(
array(
'addons' => $all_addons,
)
);
}
/**
* Prepare addons data.
*
* @since 1.0.0
* @return array
*/
public function prepare_addons_data() {
$addons = apply_filters( 'tutor_addons_lists_config', array() );
$plugins_data = $addons;
if ( is_array( $addons ) && count( $addons ) ) {
foreach ( $addons as $base_name => $addon ) {
$addon_config = tutor_utils()->get_addon_config( $base_name );
$is_enabled = (bool) tutor_utils()->avalue_dot( 'is_enable', $addon_config );
$plugins_data[ $base_name ]['is_enabled'] = $is_enabled;
$thumbnail_url = tutor()->url . 'assets/images/tutor-plugin.png';
if ( file_exists( $addon['path'] . 'assets/images/thumbnail.png' ) ) {
$thumbnail_url = $addon['url'] . 'assets/images/thumbnail.png';
} elseif ( file_exists( $addon['path'] . 'assets/images/thumbnail.jpg' ) ) {
$thumbnail_url = $addon['url'] . 'assets/images/thumbnail.jpg';
} elseif ( file_exists( $addon['path'] . 'assets/images/thumbnail.svg' ) ) {
$thumbnail_url = $addon['url'] . 'assets/images/thumbnail.svg';
}
$plugins_data[ $base_name ]['thumb_url'] = $thumbnail_url;
/**
* Checking if there any dependant plugin exists
*/
$depends = tutor_utils()->array_get( 'depend_plugins', $addon );
$plugins_required = array();
if ( tutor_utils()->count( $depends ) ) {
foreach ( $depends as $plugin_base => $plugin_name ) {
if ( ! is_plugin_active( $plugin_base ) ) {
$plugins_required[ $plugin_base ] = $plugin_name;
}
}
}
$depended_plugins = array();
foreach ( $plugins_required as $required_plugin ) {
array_push( $depended_plugins, $required_plugin );
}
$plugins_data[ $base_name ]['plugins_required'] = $depended_plugins;
// Check if it's notifications.
if ( function_exists( 'tutor_notifications' ) && tutor_notifications()->basename === $base_name ) {
$required = array();
version_compare( PHP_VERSION, '7.2.5', '>=' ) ? 0 : $required[] = __( 'PHP 7.2.5 or greater is required', 'tutor' );
! is_ssl() ? $required[] = __( 'SSL certificate', 'tutor' ) : 0;
foreach ( array( 'curl', 'gmp', 'mbstring', 'openssl' ) as $ext ) {
! extension_loaded( $ext ) ? $required[] = 'PHP extension <strong>' . $ext . '</strong>' : 0;
}
$plugins_data[ $base_name ]['ext_required'] = $required;
}
}
}
/**
* Keep same sorting order.
*
* @since 2.2.4
*/
$free_addon_list = apply_filters( 'tutor_pro_addons_lists_for_display', array() );
$prepared_addons = array();
foreach ( $free_addon_list as $addon_name => $addon ) {
$key = "tutor-pro/addons/{$addon_name}/{$addon_name}.php";
if ( isset( $plugins_data[ $key ] ) ) {
$prepared_addons[] = $plugins_data[ $key ];
}
}
return $prepared_addons;
}
/**
* Method for enable / disable addons
*
* @since 1.0.0
* @return void
*/
public function addon_enable_disable() {
tutor_utils()->checking_nonce();
if ( ! User::is_admin() ) {
wp_send_json_error( tutor_utils()->error_message() );
}
$form_data = json_decode( Input::post( 'addonFieldNames' ) );
$before_config = self::get_addons_config();
$addons_config = array();
foreach ( $form_data as $addon_field_name => $is_enable ) {
$before_status = ! isset( $before_config[ $addon_field_name ] ) ? 0 : $before_config[ $addon_field_name ]['is_enable'];
$after_status = $is_enable ? 1 : 0;
if ( $before_status !== $after_status ) {
do_action( 'tutor_addon_before_enable_disable' );
if ( $is_enable ) {
do_action( "tutor_addon_before_enable_{$addon_field_name}" );
do_action( 'tutor_addon_before_enable', $addon_field_name );
$addons_config[ $addon_field_name ]['is_enable'] = 1;
update_option( self::OPTION_KEY, $addons_config );
do_action( 'tutor_addon_after_enable', $addon_field_name );
do_action( "tutor_addon_after_enable_{$addon_field_name}" );
} else {
do_action( "tutor_addon_before_disable_{$addon_field_name}" );
do_action( 'tutor_addon_before_disable', $addon_field_name );
$addons_config[ $addon_field_name ]['is_enable'] = 0;
update_option( self::OPTION_KEY, $addons_config );
do_action( 'tutor_addon_after_disable', $addon_field_name );
do_action( "tutor_addon_after_disable_{$addon_field_name}" );
}
do_action( 'tutor_addon_after_enable_disable' );
} else {
$addons_config[ $addon_field_name ]['is_enable'] = $after_status;
update_option( self::OPTION_KEY, $addons_config );
}
}
wp_send_json_success();
}
/**
* Get tutor addons list
*
* @since 1.0.0
*
* @return array
*/
public function addons_lists_to_show() {
$addons = array(
'course-bundle' => array(
'name' => __( 'Course Bundle', 'tutor' ),
'description' => __( 'Group multiple courses to sell together.', 'tutor' ),
),
'subscription' => array(
'name' => __( 'Subscription', 'tutor' ),
'description' => __( 'Manage subscription', 'tutor' ),
),
'content-bank' => array(
'name' => __( 'Content Bank', 'tutor' ),
'description' => __( 'Create content once and use it across multiple courses.', 'tutor' ),
'is_new' => true,
),
'social-login' => array(
'name' => __( 'Social Login', 'tutor' ),
'description' => __( 'Let users register & login through social networks.', 'tutor' ),
),
'content-drip' => array(
'name' => __( 'Content Drip', 'tutor' ),
'description' => __( 'Unlock lessons by schedule or when students meet a specific condition.', 'tutor' ),
),
'tutor-multi-instructors' => array(
'name' => __( 'Tutor Multi Instructors', 'tutor' ),
'description' => __( 'Collaborate and add multiple instructors to a course.', 'tutor' ),
),
'tutor-assignments' => array(
'name' => __( 'Tutor Assignments', 'tutor' ),
'description' => __( 'Assess student learning with assignments.', 'tutor' ),
),
'tutor-course-preview' => array(
'name' => __( 'Tutor Course Preview', 'tutor' ),
'description' => __( 'Offer free previews of specific lessons before enrollment.', 'tutor' ),
),
'tutor-course-attachments' => array(
'name' => __( 'Tutor Course Attachments', 'tutor' ),
'description' => __( 'Add unlimited attachments/ private files to any Tutor course', 'tutor' ),
),
'google-meet' => array(
'name' => __( 'Tutor Google Meet Integration', 'tutor' ),
'description' => __( 'Host live classes with Google Meet, directly from your lesson page.', 'tutor' ),
),
'tutor-report' => array(
'name' => __( 'Tutor Report', 'tutor' ),
'description' => __( 'Check your course performance through Tutor Report stats.', 'tutor' ),
),
'tutor-email' => array(
'name' => __( 'Email', 'tutor' ),
'description' => __( 'Send automated and customized emails for various Tutor events.', 'tutor' ),
),
'calendar' => array(
'name' => __( 'Calendar', 'tutor' ),
'description' => __( 'Enable to let students view all your course events in one place.', 'tutor' ),
),
'tutor-notifications' => array(
'name' => __( 'Notifications', 'tutor' ),
'description' => __( 'Keep students and instructors notified of course events on their dashboard.', 'tutor' ),
),
'google-classroom' => array(
'name' => __( 'Google Classroom Integration', 'tutor' ),
'description' => __( 'Enable to integrate Tutor LMS with Google Classroom.', 'tutor' ),
),
'tutor-zoom' => array(
'name' => __( 'Tutor Zoom Integration', 'tutor' ),
'description' => __( 'Connect Tutor LMS with Zoom to host live online classes.', 'tutor' ),
),
'quiz-import-export' => array(
'name' => __( 'Quiz Export/Import', 'tutor' ),
'description' => __( 'Save time by exporting/importing quiz data with easy options.', 'tutor' ),
),
'enrollments' => array(
'name' => __( 'Enrollment', 'tutor' ),
'description' => __( 'Enable to manually enroll students in your courses.', 'tutor' ),
),
'tutor-certificate' => array(
'name' => __( 'Tutor Certificate', 'tutor' ),
'description' => __( 'Enable to award certificates upon course completion.', 'tutor' ),
),
'gradebook' => array(
'name' => __( 'Gradebook', 'tutor' ),
'description' => __( 'Track student progress with a centralized gradebook.', 'tutor' ),
),
'tutor-prerequisites' => array(
'name' => __( 'Tutor Prerequisites', 'tutor' ),
'description' => __( 'Set course prerequisites to guide learning paths effectively.', 'tutor' ),
),
'buddypress' => array(
'name' => __( 'BuddyPress', 'tutor' ),
'description' => __( 'Boost engagement with social features through BuddyPress for Tutor LMS.', 'tutor' ),
),
'wc-subscriptions' => array(
'name' => __( 'WooCommerce Subscriptions', 'tutor' ),
'description' => __( 'Capture Residual Revenue with Recurring Payments.', 'tutor' ),
),
'pmpro' => array(
'name' => __( 'Paid Memberships Pro', 'tutor' ),
'description' => __( 'Boost revenue by selling course memberships.', 'tutor' ),
),
'restrict-content-pro' => array(
'name' => __( 'Restrict Content Pro', 'tutor' ),
'description' => __( 'Enable to manage content access through Restrict Content Pro. ', 'tutor' ),
),
'tutor-weglot' => array(
'name' => __( 'Weglot', 'tutor' ),
'description' => __( 'Translate & manage multilingual courses for global reach.', 'tutor' ),
),
'tutor-wpml' => array(
'name' => __( 'WPML', 'tutor' ),
'description' => __( 'Create multilingual courses, lessons, dashboard and more.', 'tutor' ),
),
'h5p' => array(
'name' => __( 'H5P', 'tutor' ),
'description' => __( 'Integrate H5P to add interactivity and engagement to your courses.', 'tutor' ),
),
);
return $addons;
}
}