Addons.php
1 year ago
Admin.php
1 year ago
Ajax.php
1 year ago
Announcements.php
1 year ago
Assets.php
1 year ago
Backend_Page_Trait.php
1 year ago
BaseController.php
1 year ago
Course.php
1 year ago
Course_Embed.php
3 years ago
Course_Filter.php
1 year ago
Course_List.php
1 year ago
Course_Settings_Tabs.php
1 year ago
Course_Widget.php
3 years ago
Custom_Validation.php
3 years ago
Dashboard.php
1 year ago
Earnings.php
1 year ago
FormHandler.php
2 years ago
Frontend.php
1 year ago
Gutenberg.php
1 year ago
Input.php
1 year ago
Instructor.php
1 year ago
Instructors_List.php
1 year ago
Lesson.php
1 year ago
Options_V2.php
1 year ago
Permalink.php
2 years ago
Post_types.php
2 years ago
Private_Course_Access.php
1 year ago
Q_And_A.php
1 year ago
Question_Answers_List.php
3 years ago
Quiz.php
1 year ago
QuizBuilder.php
1 year ago
Quiz_Attempts_List.php
1 year ago
RestAPI.php
2 years ago
Reviews.php
3 years ago
Rewrite_Rules.php
2 years ago
Shortcode.php
1 year ago
Singleton.php
1 year ago
Student.php
1 year ago
Students_List.php
3 years ago
Taxonomies.php
3 years ago
Template.php
1 year ago
Theme_Compatibility.php
3 years ago
Tools.php
3 years ago
Tools_V2.php
1 year ago
Tutor.php
1 year ago
TutorEDD.php
1 year ago
Tutor_Base.php
2 years ago
Tutor_Setup.php
1 year ago
Upgrader.php
1 year ago
User.php
1 year ago
Utils.php
1 year ago
Video_Stream.php
3 years ago
WhatsNew.php
2 years ago
Withdraw.php
1 year ago
Withdraw_Requests_List.php
3 years ago
WooCommerce.php
1 year ago
Addons.php
347 lines
| 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 | if ( ! defined( 'ABSPATH' ) ) { |
| 14 | exit; |
| 15 | } |
| 16 | /** |
| 17 | * Addons Class |
| 18 | * |
| 19 | * @since 1.0.0 |
| 20 | */ |
| 21 | class Addons { |
| 22 | const OPTION_KEY = 'tutor_addons_config'; |
| 23 | |
| 24 | /** |
| 25 | * Constructor |
| 26 | * |
| 27 | * @since 1.0.0 |
| 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 | * @return void |
| 56 | */ |
| 57 | public static function update_addon_status( $basename, $status ) { |
| 58 | $config = self::get_addons_config(); |
| 59 | if ( isset( $config[ $basename ] ) ) { |
| 60 | $config[ $basename ]['is_enable'] = $status; |
| 61 | update_option( self::OPTION_KEY, $config ); |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | /** |
| 66 | * Get all addons data. |
| 67 | * |
| 68 | * @since 1.0.0 |
| 69 | * @return void |
| 70 | */ |
| 71 | public function get_all_addons() { |
| 72 | |
| 73 | // Check and verify the request. |
| 74 | tutor_utils()->checking_nonce(); |
| 75 | |
| 76 | if ( ! User::is_admin() ) { |
| 77 | wp_send_json_error( tutor_utils()->error_message() ); |
| 78 | } |
| 79 | |
| 80 | // All good, let's proceed. |
| 81 | $all_addons = $this->prepare_addons_data(); |
| 82 | |
| 83 | wp_send_json_success( |
| 84 | array( |
| 85 | 'addons' => $all_addons, |
| 86 | ) |
| 87 | ); |
| 88 | } |
| 89 | |
| 90 | /** |
| 91 | * Prepare addons data. |
| 92 | * |
| 93 | * @since 1.0.0 |
| 94 | * @return array |
| 95 | */ |
| 96 | public function prepare_addons_data() { |
| 97 | $addons = apply_filters( 'tutor_addons_lists_config', array() ); |
| 98 | $plugins_data = $addons; |
| 99 | |
| 100 | if ( is_array( $addons ) && count( $addons ) ) { |
| 101 | foreach ( $addons as $base_name => $addon ) { |
| 102 | $addon_config = tutor_utils()->get_addon_config( $base_name ); |
| 103 | $is_enabled = (bool) tutor_utils()->avalue_dot( 'is_enable', $addon_config ); |
| 104 | |
| 105 | $plugins_data[ $base_name ]['is_enabled'] = $is_enabled; |
| 106 | |
| 107 | $thumbnail_url = tutor()->url . 'assets/images/tutor-plugin.png'; |
| 108 | if ( file_exists( $addon['path'] . 'assets/images/thumbnail.png' ) ) { |
| 109 | $thumbnail_url = $addon['url'] . 'assets/images/thumbnail.png'; |
| 110 | } elseif ( file_exists( $addon['path'] . 'assets/images/thumbnail.jpg' ) ) { |
| 111 | $thumbnail_url = $addon['url'] . 'assets/images/thumbnail.jpg'; |
| 112 | } elseif ( file_exists( $addon['path'] . 'assets/images/thumbnail.svg' ) ) { |
| 113 | $thumbnail_url = $addon['url'] . 'assets/images/thumbnail.svg'; |
| 114 | } |
| 115 | |
| 116 | $plugins_data[ $base_name ]['thumb_url'] = $thumbnail_url; |
| 117 | |
| 118 | /** |
| 119 | * Checking if there any dependant plugin exists |
| 120 | */ |
| 121 | $depends = tutor_utils()->array_get( 'depend_plugins', $addon ); |
| 122 | $plugins_required = array(); |
| 123 | if ( tutor_utils()->count( $depends ) ) { |
| 124 | foreach ( $depends as $plugin_base => $plugin_name ) { |
| 125 | if ( ! is_plugin_active( $plugin_base ) ) { |
| 126 | $plugins_required[ $plugin_base ] = $plugin_name; |
| 127 | } |
| 128 | } |
| 129 | } |
| 130 | |
| 131 | $depended_plugins = array(); |
| 132 | foreach ( $plugins_required as $required_plugin ) { |
| 133 | array_push( $depended_plugins, $required_plugin ); |
| 134 | } |
| 135 | |
| 136 | $plugins_data[ $base_name ]['plugins_required'] = $depended_plugins; |
| 137 | |
| 138 | // Check if it's notifications. |
| 139 | if ( function_exists( 'tutor_notifications' ) && tutor_notifications()->basename === $base_name ) { |
| 140 | |
| 141 | $required = array(); |
| 142 | version_compare( PHP_VERSION, '7.2.5', '>=' ) ? 0 : $required[] = __( 'PHP 7.2.5 or greater is required', 'tutor' ); |
| 143 | ! is_ssl() ? $required[] = __( 'SSL certificate', 'tutor' ) : 0; |
| 144 | |
| 145 | foreach ( array( 'curl', 'gmp', 'mbstring', 'openssl' ) as $ext ) { |
| 146 | ! extension_loaded( $ext ) ? $required[] = 'PHP extension <strong>' . $ext . '</strong>' : 0; |
| 147 | } |
| 148 | |
| 149 | $plugins_data[ $base_name ]['ext_required'] = $required; |
| 150 | } |
| 151 | } |
| 152 | } |
| 153 | |
| 154 | /** |
| 155 | * Keep same sorting order. |
| 156 | * |
| 157 | * @since 2.2.4 |
| 158 | */ |
| 159 | $free_addon_list = apply_filters( 'tutor_pro_addons_lists_for_display', array() ); |
| 160 | $prepared_addons = array(); |
| 161 | |
| 162 | foreach ( $free_addon_list as $addon_name => $addon ) { |
| 163 | $key = "tutor-pro/addons/{$addon_name}/{$addon_name}.php"; |
| 164 | if ( isset( $plugins_data[ $key ] ) ) { |
| 165 | $prepared_addons[] = $plugins_data[ $key ]; |
| 166 | } |
| 167 | } |
| 168 | |
| 169 | return $prepared_addons; |
| 170 | } |
| 171 | |
| 172 | /** |
| 173 | * Method for enable / disable addons |
| 174 | * |
| 175 | * @since 1.0.0 |
| 176 | * @return void |
| 177 | */ |
| 178 | public function addon_enable_disable() { |
| 179 | |
| 180 | tutor_utils()->checking_nonce(); |
| 181 | |
| 182 | if ( ! current_user_can( 'manage_options' ) ) { |
| 183 | wp_send_json_error( array( 'message' => __( 'Access Denied', 'tutor' ) ) ); |
| 184 | } |
| 185 | |
| 186 | $form_data = json_decode( Input::post( 'addonFieldNames' ) ); |
| 187 | $before_config = self::get_addons_config(); |
| 188 | $addons_config = array(); |
| 189 | |
| 190 | foreach ( $form_data as $addon_field_name => $is_enable ) { |
| 191 | |
| 192 | $before_status = ! isset( $before_config[ $addon_field_name ] ) ? 0 : $before_config[ $addon_field_name ]['is_enable']; |
| 193 | $after_status = $is_enable ? 1 : 0; |
| 194 | |
| 195 | if ( $before_status !== $after_status ) { |
| 196 | do_action( 'tutor_addon_before_enable_disable' ); |
| 197 | if ( $is_enable ) { |
| 198 | do_action( "tutor_addon_before_enable_{$addon_field_name}" ); |
| 199 | do_action( 'tutor_addon_before_enable', $addon_field_name ); |
| 200 | |
| 201 | $addons_config[ $addon_field_name ]['is_enable'] = 1; |
| 202 | update_option( self::OPTION_KEY, $addons_config ); |
| 203 | |
| 204 | do_action( 'tutor_addon_after_enable', $addon_field_name ); |
| 205 | do_action( "tutor_addon_after_enable_{$addon_field_name}" ); |
| 206 | } else { |
| 207 | do_action( "tutor_addon_before_disable_{$addon_field_name}" ); |
| 208 | do_action( 'tutor_addon_before_disable', $addon_field_name ); |
| 209 | |
| 210 | $addons_config[ $addon_field_name ]['is_enable'] = 0; |
| 211 | update_option( self::OPTION_KEY, $addons_config ); |
| 212 | |
| 213 | do_action( 'tutor_addon_after_disable', $addon_field_name ); |
| 214 | do_action( "tutor_addon_after_disable_{$addon_field_name}" ); |
| 215 | } |
| 216 | do_action( 'tutor_addon_after_enable_disable' ); |
| 217 | } else { |
| 218 | $addons_config[ $addon_field_name ]['is_enable'] = $after_status; |
| 219 | update_option( self::OPTION_KEY, $addons_config ); |
| 220 | } |
| 221 | } |
| 222 | |
| 223 | wp_send_json_success(); |
| 224 | } |
| 225 | |
| 226 | /** |
| 227 | * Get tutor addons list |
| 228 | * |
| 229 | * @since 1.0.0 |
| 230 | * @return array |
| 231 | */ |
| 232 | public function addons_lists_to_show() { |
| 233 | $addons = array( |
| 234 | 'course-bundle' => array( |
| 235 | 'name' => __( 'Course Bundle', 'tutor' ), |
| 236 | 'description' => __( 'Group multiple courses to sell together.', 'tutor' ), |
| 237 | ), |
| 238 | 'subscription' => array( |
| 239 | 'name' => __( 'Subscription', 'tutor' ), |
| 240 | 'description' => __( 'Manage subscription', 'tutor' ), |
| 241 | ), |
| 242 | 'social-login' => array( |
| 243 | 'name' => __( 'Social Login', 'tutor' ), |
| 244 | 'description' => __( 'Let users register & login through social network like Facebook, Google, etc.', 'tutor' ), |
| 245 | ), |
| 246 | 'content-drip' => array( |
| 247 | 'name' => __( 'Content Drip', 'tutor' ), |
| 248 | 'description' => 'Unlock lessons by schedule or when students meet a specific condition.', |
| 249 | ), |
| 250 | 'tutor-multi-instructors' => array( |
| 251 | 'name' => __( 'Tutor Multi Instructors', 'tutor' ), |
| 252 | 'description' => 'Collaborate and add multiple instructors to a course.', |
| 253 | ), |
| 254 | 'tutor-assignments' => array( |
| 255 | 'name' => __( 'Tutor Assignments', 'tutor' ), |
| 256 | 'description' => 'Assess student learning with assignments.', |
| 257 | ), |
| 258 | 'tutor-course-preview' => array( |
| 259 | 'name' => __( 'Tutor Course Preview', 'tutor' ), |
| 260 | 'description' => 'Offer free previews of specific lessons before enrollment.', |
| 261 | ), |
| 262 | 'tutor-course-attachments' => array( |
| 263 | 'name' => __( 'Tutor Course Attachments', 'tutor' ), |
| 264 | 'description' => 'Add unlimited attachments/ private files to any Tutor course', |
| 265 | ), |
| 266 | 'google-meet' => array( |
| 267 | 'name' => __( 'Tutor Google Meet Integration', 'tutor' ), |
| 268 | 'description' => __( 'Host live classes with Google Meet, directly from your lesson page.', 'tutor' ), |
| 269 | ), |
| 270 | 'tutor-report' => array( |
| 271 | 'name' => __( 'Tutor Report', 'tutor' ), |
| 272 | 'description' => __( 'Check your course performance through Tutor Report stats.', 'tutor' ), |
| 273 | ), |
| 274 | 'tutor-email' => array( |
| 275 | 'name' => __( 'Email', 'tutor' ), |
| 276 | 'description' => __( 'Send automated and customized emails for various Tutor events.', 'tutor' ), |
| 277 | ), |
| 278 | 'calendar' => array( |
| 279 | 'name' => 'Calendar', |
| 280 | 'description' => __( 'Enable to let students view all your course events in one place.', 'tutor' ), |
| 281 | ), |
| 282 | 'tutor-notifications' => array( |
| 283 | 'name' => 'Notifications', |
| 284 | 'description' => __( 'Keep students and instructors notified of course events on their dashboard.', 'tutor' ), |
| 285 | ), |
| 286 | 'google-classroom' => array( |
| 287 | 'name' => __( 'Google Classroom Integration', 'tutor' ), |
| 288 | 'description' => __( 'Enable to integrate Tutor LMS with Google Classroom.', 'tutor' ), |
| 289 | ), |
| 290 | 'tutor-zoom' => array( |
| 291 | 'name' => __( 'Tutor Zoom Integration', 'tutor' ), |
| 292 | 'description' => __( 'Connect Tutor LMS with Zoom to host live online classes. Students can attend live classes right from the lesson page.', 'tutor' ), |
| 293 | ), |
| 294 | 'quiz-import-export' => array( |
| 295 | 'name' => __( 'Quiz Export/Import', 'tutor' ), |
| 296 | 'description' => __( 'Save time by exporting/importing quiz data with easy options.', 'tutor' ), |
| 297 | ), |
| 298 | 'enrollments' => array( |
| 299 | 'name' => __( 'Enrollment', 'tutor' ), |
| 300 | 'description' => __( 'Enable to manually enroll students in your courses.', 'tutor' ), |
| 301 | ), |
| 302 | 'tutor-certificate' => array( |
| 303 | 'name' => __( 'Tutor Certificate', 'tutor' ), |
| 304 | 'description' => __( 'Enable to award certificates upon course completion.', 'tutor' ), |
| 305 | ), |
| 306 | 'gradebook' => array( |
| 307 | 'name' => __( 'Gradebook', 'tutor' ), |
| 308 | 'description' => __( 'Track student progress with a centralized gradebook.', 'tutor' ), |
| 309 | ), |
| 310 | 'tutor-prerequisites' => array( |
| 311 | 'name' => __( 'Tutor Prerequisites', 'tutor' ), |
| 312 | 'description' => __( 'Set course prerequisites to guide learning paths effectively.', 'tutor' ), |
| 313 | ), |
| 314 | 'buddypress' => array( |
| 315 | 'name' => __( 'BuddyPress', 'tutor' ), |
| 316 | 'description' => __( 'Boost engagement with social features through BuddyPress for Tutor LMS.', 'tutor' ), |
| 317 | ), |
| 318 | 'wc-subscriptions' => array( |
| 319 | 'name' => __( 'WooCommerce Subscriptions', 'tutor' ), |
| 320 | 'description' => __( 'Capture Residual Revenue with Recurring Payments.', 'tutor' ), |
| 321 | ), |
| 322 | 'pmpro' => array( |
| 323 | 'name' => __( 'Paid Memberships Pro', 'tutor' ), |
| 324 | 'description' => __( 'Maximize revenue by selling membership access to all of your courses.', 'tutor' ), |
| 325 | ), |
| 326 | 'restrict-content-pro' => array( |
| 327 | 'name' => __( 'Restrict Content Pro', 'tutor' ), |
| 328 | 'description' => __( 'Enable to manage content access through Restrict Content Pro. ', 'tutor' ), |
| 329 | ), |
| 330 | 'tutor-weglot' => array( |
| 331 | 'name' => 'Weglot', |
| 332 | 'description' => __( 'Translate & manage multilingual courses for global reach with full edit control.', 'tutor' ), |
| 333 | ), |
| 334 | 'tutor-wpml' => array( |
| 335 | 'name' => __( 'WPML Multilingual CMS', 'tutor' ), |
| 336 | 'description' => __( 'Create multilingual courses, lessons, dashboard and more for a global audience.', 'tutor' ), |
| 337 | ), |
| 338 | 'h5p' => array( |
| 339 | 'name' => __( 'H5P Integration', 'tutor' ), |
| 340 | 'description' => __( 'Integrate H5P to add interactivity and engagement to your courses.', 'tutor' ), |
| 341 | ), |
| 342 | ); |
| 343 | |
| 344 | return $addons; |
| 345 | } |
| 346 | } |
| 347 |