PluginProbe
Tutor LMS – eLearning and online course solution / 1.7.0
Tutor LMS – eLearning and online course solution v1.7.0
4.0.7 4.0.6 4.0.5 4.0.4 4.0.3 4.0.2 4.0.1 4.0.0 3.9.15 3.9.14 3.9.13 3.9.12 3.9.11 trunk 1.0.0 1.0.0-alpha 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 All 191 releases
← All changes | classes/Addons.php +138 -354 trunk1.7.0 View file →
@@ -1,354 +1,138 @@
1 -<?php
2 -/**
3 - * Manage Addons
4 - *
5 - * @package Tutor
6 - * @author Themeum <support@themeum.com>
7 - * @link https://themeum.com
8 - * @since 1.0.0
9 - */
10 -
11 -namespace TUTOR;
12 -
13 -defined( 'ABSPATH' ) || exit;
14 -
15 -/**
16 - * Addons Class
17 - *
18 - * @since 1.0.0
19 - */
20 -class Addons {
21 - const OPTION_KEY = 'tutor_addons_config';
22 -
23 - /**
24 - * Constructor
25 - *
26 - * @since 1.0.0
27 - *
28 - * @return void
29 - */
30 - public function __construct() {
31 - add_filter( 'tutor_pro_addons_lists_for_display', array( $this, 'addons_lists_to_show' ) );
32 - add_action( 'wp_ajax_tutor_get_all_addons', array( $this, 'get_all_addons' ) );
33 - add_action( 'wp_ajax_addon_enable_disable', array( $this, 'addon_enable_disable' ) );
34 - }
35 -
36 - /**
37 - * Obtain addons config list.
38 - *
39 - * @since 3.0.0
40 - *
41 - * @return array
42 - */
43 - public static function get_addons_config() {
44 - $list = get_option( self::OPTION_KEY, array() );
45 - return $list;
46 - }
47 -
48 - /**
49 - * Status update of tutor addon.
50 - *
51 - * @since 3.0.0
52 - *
53 - * @param string $basename basename of addon.
54 - * @param bool $status status 0,1.
55 - *
56 - * @return void
57 - */
58 - public static function update_addon_status( $basename, $status ) {
59 - $config = self::get_addons_config();
60 - if ( isset( $config[ $basename ] ) ) {
61 - $config[ $basename ]['is_enable'] = $status;
62 - update_option( self::OPTION_KEY, $config );
63 - }
64 - }
65 -
66 - /**
67 - * Get all addons data.
68 - *
69 - * @since 1.0.0
70 - *
71 - * @return void
72 - */
73 - public function get_all_addons() {
74 -
75 - // Check and verify the request.
76 - tutor_utils()->checking_nonce();
77 -
78 - if ( ! User::can() ) {
79 - wp_send_json_error( tutor_utils()->error_message() );
80 - }
81 -
82 - // All good, let's proceed.
83 - $all_addons = $this->prepare_addons_data();
84 -
85 - wp_send_json_success(
86 - array(
87 - 'addons' => $all_addons,
88 - )
89 - );
90 - }
91 -
92 - /**
93 - * Prepare addons data.
94 - *
95 - * @since 1.0.0
96 - * @return array
97 - */
98 - public function prepare_addons_data() {
99 - $addons = apply_filters( 'tutor_addons_lists_config', array() );
100 - $plugins_data = $addons;
101 -
102 - if ( is_array( $addons ) && count( $addons ) ) {
103 - foreach ( $addons as $base_name => $addon ) {
104 - $addon_config = tutor_utils()->get_addon_config( $base_name );
105 - $is_enabled = (bool) tutor_utils()->avalue_dot( 'is_enable', $addon_config );
106 -
107 - $plugins_data[ $base_name ]['is_enabled'] = $is_enabled;
108 -
109 - $thumbnail_url = tutor()->url . 'assets/images/tutor-plugin.png';
110 - if ( file_exists( $addon['path'] . 'assets/images/thumbnail.png' ) ) {
111 - $thumbnail_url = $addon['url'] . 'assets/images/thumbnail.png';
112 - } elseif ( file_exists( $addon['path'] . 'assets/images/thumbnail.jpg' ) ) {
113 - $thumbnail_url = $addon['url'] . 'assets/images/thumbnail.jpg';
114 - } elseif ( file_exists( $addon['path'] . 'assets/images/thumbnail.svg' ) ) {
115 - $thumbnail_url = $addon['url'] . 'assets/images/thumbnail.svg';
116 - }
117 -
118 - $plugins_data[ $base_name ]['thumb_url'] = $thumbnail_url;
119 -
120 - /**
121 - * Checking if there any dependant plugin exists
122 - */
123 - $depends = tutor_utils()->array_get( 'depend_plugins', $addon );
124 - $plugins_required = array();
125 - if ( tutor_utils()->count( $depends ) ) {
126 - foreach ( $depends as $plugin_base => $plugin_name ) {
127 - if ( ! is_plugin_active( $plugin_base ) ) {
128 - $plugins_required[ $plugin_base ] = $plugin_name;
129 - }
130 - }
131 - }
132 -
133 - $depended_plugins = array();
134 - foreach ( $plugins_required as $required_plugin ) {
135 - array_push( $depended_plugins, $required_plugin );
136 - }
137 -
138 - $plugins_data[ $base_name ]['plugins_required'] = $depended_plugins;
139 -
140 - // Check if it's notifications.
141 - if ( function_exists( 'tutor_notifications' ) && tutor_notifications()->basename === $base_name ) {
142 -
143 - $required = array();
144 - version_compare( PHP_VERSION, '7.2.5', '>=' ) ? 0 : $required[] = __( 'PHP 7.2.5 or greater is required', 'tutor' );
145 - ! is_ssl() ? $required[] = __( 'SSL certificate', 'tutor' ) : 0;
146 -
147 - foreach ( array( 'curl', 'gmp', 'mbstring', 'openssl' ) as $ext ) {
148 - ! extension_loaded( $ext ) ? $required[] = 'PHP extension <strong>' . $ext . '</strong>' : 0;
149 - }
150 -
151 - $plugins_data[ $base_name ]['ext_required'] = $required;
152 - }
153 - }
154 - }
155 -
156 - /**
157 - * Keep same sorting order.
158 - *
159 - * @since 2.2.4
160 - */
161 - $free_addon_list = apply_filters( 'tutor_pro_addons_lists_for_display', array() );
162 - $prepared_addons = array();
163 -
164 - foreach ( $free_addon_list as $addon_name => $addon ) {
165 - $key = "tutor-pro/addons/{$addon_name}/{$addon_name}.php";
166 - if ( isset( $plugins_data[ $key ] ) ) {
167 - $prepared_addons[] = $plugins_data[ $key ];
168 - }
169 - }
170 -
171 - return $prepared_addons;
172 - }
173 -
174 - /**
175 - * Method for enable / disable addons
176 - *
177 - * @since 1.0.0
178 - * @return void
179 - */
180 - public function addon_enable_disable() {
181 -
182 - tutor_utils()->checking_nonce();
183 -
184 - if ( ! User::can() ) {
185 - wp_send_json_error( tutor_utils()->error_message() );
186 - }
187 -
188 - $form_data = json_decode( Input::post( 'addonFieldNames' ) );
189 - $before_config = self::get_addons_config();
190 - $addons_config = array();
191 -
192 - foreach ( $form_data as $addon_field_name => $is_enable ) {
193 -
194 - $before_status = ! isset( $before_config[ $addon_field_name ] ) ? 0 : $before_config[ $addon_field_name ]['is_enable'];
195 - $after_status = $is_enable ? 1 : 0;
196 -
197 - if ( $before_status !== $after_status ) {
198 - do_action( 'tutor_addon_before_enable_disable' );
199 - if ( $is_enable ) {
200 - do_action( "tutor_addon_before_enable_{$addon_field_name}" );
201 - do_action( 'tutor_addon_before_enable', $addon_field_name );
202 -
203 - $addons_config[ $addon_field_name ]['is_enable'] = 1;
204 - update_option( self::OPTION_KEY, $addons_config );
205 -
206 - do_action( 'tutor_addon_after_enable', $addon_field_name );
207 - do_action( "tutor_addon_after_enable_{$addon_field_name}" );
208 - } else {
209 - do_action( "tutor_addon_before_disable_{$addon_field_name}" );
210 - do_action( 'tutor_addon_before_disable', $addon_field_name );
211 -
212 - $addons_config[ $addon_field_name ]['is_enable'] = 0;
213 - update_option( self::OPTION_KEY, $addons_config );
214 -
215 - do_action( 'tutor_addon_after_disable', $addon_field_name );
216 - do_action( "tutor_addon_after_disable_{$addon_field_name}" );
217 - }
218 - do_action( 'tutor_addon_after_enable_disable' );
219 - } else {
220 - $addons_config[ $addon_field_name ]['is_enable'] = $after_status;
221 - update_option( self::OPTION_KEY, $addons_config );
222 - }
223 - }
224 -
225 - wp_send_json_success();
226 - }
227 -
228 - /**
229 - * Get tutor addons list
230 - *
231 - * @since 1.0.0
232 - *
233 - * @return array
234 - */
235 - public function addons_lists_to_show() {
236 - $addons = array(
237 - 'course-bundle' => array(
238 - 'name' => __( 'Course Bundle', 'tutor' ),
239 - 'description' => __( 'Group multiple courses to sell together.', 'tutor' ),
240 - ),
241 - 'subscription' => array(
242 - 'name' => __( 'Subscription', 'tutor' ),
243 - 'description' => __( 'Manage subscription', 'tutor' ),
244 - ),
245 - 'content-bank' => array(
246 - 'name' => __( 'Content Bank', 'tutor' ),
247 - 'description' => __( 'Create content once and use it across multiple courses.', 'tutor' ),
248 - 'is_new' => true,
249 - ),
250 - 'social-login' => array(
251 - 'name' => __( 'Social Login', 'tutor' ),
252 - 'description' => __( 'Let users register & login through social networks.', 'tutor' ),
253 - ),
254 - 'content-drip' => array(
255 - 'name' => __( 'Content Drip', 'tutor' ),
256 - 'description' => __( 'Unlock lessons by schedule or when students meet a specific condition.', 'tutor' ),
257 - ),
258 - 'tutor-multi-instructors' => array(
259 - 'name' => __( 'Tutor Multi Instructors', 'tutor' ),
260 - 'description' => __( 'Collaborate and add multiple instructors to a course.', 'tutor' ),
261 - ),
262 - 'tutor-assignments' => array(
263 - 'name' => __( 'Tutor Assignments', 'tutor' ),
264 - 'description' => __( 'Assess student learning with assignments.', 'tutor' ),
265 - ),
266 - 'tutor-course-preview' => array(
267 - 'name' => __( 'Tutor Course Preview', 'tutor' ),
268 - 'description' => __( 'Offer free previews of specific lessons before enrollment.', 'tutor' ),
269 - ),
270 - 'tutor-course-attachments' => array(
271 - 'name' => __( 'Tutor Course Attachments', 'tutor' ),
272 - 'description' => __( 'Add unlimited attachments/ private files to any Tutor course', 'tutor' ),
273 - ),
274 - 'google-meet' => array(
275 - 'name' => __( 'Tutor Google Meet Integration', 'tutor' ),
276 - 'description' => __( 'Host live classes with Google Meet, directly from your lesson page.', 'tutor' ),
277 - ),
278 - 'tutor-report' => array(
279 - 'name' => __( 'Tutor Report', 'tutor' ),
280 - 'description' => __( 'Check your course performance through Tutor Report stats.', 'tutor' ),
281 - ),
282 - 'tutor-email' => array(
283 - 'name' => __( 'Email', 'tutor' ),
284 - 'description' => __( 'Send automated and customized emails for various Tutor events.', 'tutor' ),
285 - ),
286 - 'calendar' => array(
287 - 'name' => __( 'Calendar', 'tutor' ),
288 - 'description' => __( 'Enable to let students view all your course events in one place.', 'tutor' ),
289 - ),
290 - 'tutor-notifications' => array(
291 - 'name' => __( 'Notifications', 'tutor' ),
292 - 'description' => __( 'Keep students and instructors notified of course events on their dashboard.', 'tutor' ),
293 - ),
294 - 'google-classroom' => array(
295 - 'name' => __( 'Google Classroom Integration', 'tutor' ),
296 - 'description' => __( 'Enable to integrate Tutor LMS with Google Classroom.', 'tutor' ),
297 - ),
298 - 'tutor-zoom' => array(
299 - 'name' => __( 'Tutor Zoom Integration', 'tutor' ),
300 - 'description' => __( 'Connect Tutor LMS with Zoom to host live online classes.', 'tutor' ),
301 - ),
302 - 'quiz-import-export' => array(
303 - 'name' => __( 'Quiz Export/Import', 'tutor' ),
304 - 'description' => __( 'Save time by exporting/importing quiz data with easy options.', 'tutor' ),
305 - ),
306 - 'enrollments' => array(
307 - 'name' => __( 'Enrollment', 'tutor' ),
308 - 'description' => __( 'Enable to manually enroll students in your courses.', 'tutor' ),
309 - ),
310 - 'tutor-certificate' => array(
311 - 'name' => __( 'Tutor Certificate', 'tutor' ),
312 - 'description' => __( 'Enable to award certificates upon course completion.', 'tutor' ),
313 - ),
314 - 'gradebook' => array(
315 - 'name' => __( 'Gradebook', 'tutor' ),
316 - 'description' => __( 'Track student progress with a centralized gradebook.', 'tutor' ),
317 - ),
318 - 'tutor-prerequisites' => array(
319 - 'name' => __( 'Tutor Prerequisites', 'tutor' ),
320 - 'description' => __( 'Set course prerequisites to guide learning paths effectively.', 'tutor' ),
321 - ),
322 - 'buddypress' => array(
323 - 'name' => __( 'BuddyPress', 'tutor' ),
324 - 'description' => __( 'Boost engagement with social features through BuddyPress for Tutor LMS.', 'tutor' ),
325 - ),
326 - 'wc-subscriptions' => array(
327 - 'name' => __( 'WooCommerce Subscriptions', 'tutor' ),
328 - 'description' => __( 'Capture Residual Revenue with Recurring Payments.', 'tutor' ),
329 - ),
330 - 'pmpro' => array(
331 - 'name' => __( 'Paid Memberships Pro', 'tutor' ),
332 - 'description' => __( 'Boost revenue by selling course memberships.', 'tutor' ),
333 - ),
334 - 'restrict-content-pro' => array(
335 - 'name' => __( 'Restrict Content Pro', 'tutor' ),
336 - 'description' => __( 'Enable to manage content access through Restrict Content Pro. ', 'tutor' ),
337 - ),
338 - 'tutor-weglot' => array(
339 - 'name' => __( 'Weglot', 'tutor' ),
340 - 'description' => __( 'Translate & manage multilingual courses for global reach.', 'tutor' ),
341 - ),
342 - 'tutor-wpml' => array(
343 - 'name' => __( 'WPML', 'tutor' ),
344 - 'description' => __( 'Create multilingual courses, lessons, dashboard and more.', 'tutor' ),
345 - ),
346 - 'h5p' => array(
347 - 'name' => __( 'H5P', 'tutor' ),
348 - 'description' => __( 'Integrate H5P to add interactivity and engagement to your courses.', 'tutor' ),
349 - ),
350 - );
351 -
352 - return $addons;
353 - }
354 -}
1 +<?php
2 +/**
3 + * Addons class
4 + *
5 + * @author: themeum
6 + * @author_uri: https://themeum.com
7 + * @package Tutor
8 + * @since v.1.0.0
9 + */
10 +
11 +
12 +namespace TUTOR;
13 +
14 +if ( ! defined( 'ABSPATH' ) )
15 + exit;
16 +
17 +class Addons {
18 +
19 + public function __construct() {
20 + add_filter('tutor_pro_addons_lists_for_display', array($this, 'tutor_addons_lists_to_show'));
21 + }
22 +
23 + public function tutor_addons_lists_to_show(){
24 + $addons = array(
25 + 'buddypress' => array(
26 + 'name' => __('BuddyPress', 'tutor'),
27 + 'description' => 'Discuss about course and share your knowledge with your friends through BuddyPress',
28 + ),
29 + 'gradebook' => array(
30 + 'name' => __('Gradebook', 'tutor'),
31 + 'description' => 'Shows student progress from assignment and quiz',
32 + ),
33 + 'content-drip' => array(
34 + 'name' => __('Content Drip', 'tutor'),
35 + 'description' => 'Unlock lessons by schedule or when the student meets specific condition.',
36 + ),
37 + 'enrollments' => array(
38 + 'name' => __('Enrollments', 'tutor'),
39 + 'description' => 'Take advanced control on enrollments. Enroll the student manually.',
40 + ),
41 + 'wc-subscriptions' => array(
42 + 'name' => __('WooCommerce Subscriptions', 'tutor'),
43 + 'description' => 'Capture Residual Revenue with Recurring Payments.',
44 + ),
45 + 'pmpro' => array(
46 + 'name' => __('Paid Memberships Pro', 'tutor'),
47 + 'description' => 'Maximize revenue by selling membership access to all of your courses.',
48 + ),
49 + 'restrict-content-pro' => array(
50 + 'name' => __('Restrict Content Pro', 'tutor'),
51 + 'description' => 'Unlock Course depending on Restrict Content Pro Plugin Permission.',
52 + ),
53 + 'tutor-assignments' => array(
54 + 'name' => __('Tutor Assignments', 'tutor'),
55 + 'description' => 'Tutor assignments is a great way to assign tasks to students.',
56 + ),
57 + 'tutor-certificate' => array(
58 + 'name' => __('Tutor Certificate', 'tutor'),
59 + 'description' => 'Students will be able to download a certificate after course completion.',
60 + ),
61 + 'tutor-course-attachments' => array(
62 + 'name' => __('Tutor Course Attachments', 'tutor'),
63 + 'description' => 'Add unlimited attachments/ private files to any Tutor course',
64 + ),
65 + 'tutor-course-preview' => array(
66 + 'name' => __('Tutor Course Preview', 'tutor'),
67 + 'description' => 'Unlock some lessons for students before enrollment.',
68 + ),
69 + 'tutor-email' => array(
70 + 'name' => __('Tutor E-Mail', 'tutor'),
71 + 'description' => 'Send email on various tutor events',
72 + ),
73 + 'tutor-multi-instructors' => array(
74 + 'name' => __('Tutor Multi Instructors', 'tutor'),
75 + 'description' => 'Start a course with multiple instructors by Tutor Multi Instructors',
76 + ),
77 + 'tutor-prerequisites' => array(
78 + 'name' => __('Tutor Prerequisites', 'tutor'),
79 + 'description' => 'Specific course you must complete before you can enroll new course by Tutor Prerequisites',
80 + ),
81 + 'tutor-report' => array(
82 + 'name' => __('Tutor Report', 'tutor'),
83 + 'description' => 'Check your course performance through Tutor Report stats.',
84 + ),
85 + 'quiz-import-export' => array(
86 + 'name' => __('Quiz Export/Import', 'tutor'),
87 + 'description' => __('Save time by exporting/importing quiz data with easy options.', 'tutor'),
88 + ),
89 + );
90 +
91 + return $addons;
92 + }
93 +
94 +
95 + /**
96 + * @deprecated from alpha version
97 + */
98 +
99 + public function addons_page(){
100 +
101 + if ( false === ( $addons_themes_data = get_transient( 'tutor_addons_themes_data' ) ) ) {
102 + //Request New
103 + $api_endpoint = 'https://www.themeum.com/wp-json/addon-serve/v2/get-products';
104 + $response = wp_remote_post( $api_endpoint, array(
105 + 'method' => 'POST',
106 + 'timeout' => 45,
107 + 'user-agent' => 'Tutor/'.TUTOR_VERSION.'; '.home_url( '/' ),
108 + 'headers' => array(
109 + 'wp_blog' => home_url( '/' )
110 + ),
111 + 'body' => array('plugin_slug' => 'tutor', 'wp_blog' => home_url( '/' )),
112 + )
113 + );
114 +
115 + if ( is_wp_error( $response ) ) {
116 + $error_message = $response->get_error_message();
117 + echo "Something went wrong: $error_message";
118 + } else {
119 + if (tutor_utils()->avalue_dot('body', $response) && tutor_utils()->avalue_dot('response.code', $response) == 200 ){
120 + $api_data = tutor_utils()->avalue_dot('body', $response);
121 +
122 + $addons_themes_data = array(
123 + 'last_checked_time' => tutor_time(),
124 + 'data' => $api_data,
125 + );
126 + }
127 + }
128 +
129 + //Save the Final api call result on the database
130 + set_transient( 'tutor_addons_themes_data', $addons_themes_data, 6 * HOUR_IN_SECONDS );
131 + }
132 +
133 +
134 + //Finally Show the View Page
135 + include tutor()->path.'views/pages/addons.php';
136 + }
137 +
138 +}