| 1 |
<?php |
| 2 |
/** |
| 3 |
* Plugin Name: LearnPress |
| 4 |
* Plugin URI: http://thimpress.com/learnpress |
| 5 |
* Description: LearnPress is a WordPress complete solution for creating a Learning Management System (LMS). It can help you to create courses, lessons and quizzes. |
| 6 |
* Author: ThimPress |
| 7 |
* Version: 4.1.7 |
| 8 |
* Author URI: http://thimpress.com |
| 9 |
* Requires at least: 5.6 |
| 10 |
* Tested up to: 6.0 |
| 11 |
* Requires PHP: 7.0 |
| 12 |
* Text Domain: learnpress |
| 13 |
* Domain Path: /languages/ |
| 14 |
* |
| 15 |
* @package LearnPress |
| 16 |
*/ |
| 17 |
|
| 18 |
/** |
| 19 |
* Prevent loading this file directly |
| 20 |
*/ |
| 21 |
defined( 'ABSPATH' ) || exit(); |
| 22 |
|
| 23 |
if ( ! defined( 'LP_PLUGIN_FILE' ) ) { |
| 24 |
define( 'LP_PLUGIN_FILE', __FILE__ ); |
| 25 |
require_once 'inc/lp-constants.php'; |
| 26 |
} |
| 27 |
|
| 28 |
if ( ! class_exists( 'LearnPress' ) ) { |
| 29 |
/** |
| 30 |
* Class LearnPress |
| 31 |
* |
| 32 |
* Version 3.0.1 |
| 33 |
*/ |
| 34 |
class LearnPress { |
| 35 |
/** |
| 36 |
* Current version of the plugin |
| 37 |
* |
| 38 |
* @var string |
| 39 |
*/ |
| 40 |
public $version = LEARNPRESS_VERSION; |
| 41 |
/** |
| 42 |
* Version database require, use for this LP source |
| 43 |
* |
| 44 |
* @var int |
| 45 |
*/ |
| 46 |
public $db_version = 4; |
| 47 |
|
| 48 |
/** |
| 49 |
* The single instance of the class |
| 50 |
* |
| 51 |
* @var LearnPress object |
| 52 |
*/ |
| 53 |
private static $_instance = null; |
| 54 |
|
| 55 |
/** |
| 56 |
* Store the session class |
| 57 |
* |
| 58 |
* @var LP_Session_Handler |
| 59 |
*/ |
| 60 |
public $session = null; |
| 61 |
|
| 62 |
/** |
| 63 |
* @var LP_Profile |
| 64 |
*/ |
| 65 |
public $profile = null; |
| 66 |
|
| 67 |
/** |
| 68 |
* @var LP_Cart object |
| 69 |
*/ |
| 70 |
public $cart = false; |
| 71 |
|
| 72 |
/** |
| 73 |
* @var LP_Settings |
| 74 |
*/ |
| 75 |
public $settings = null; |
| 76 |
|
| 77 |
/** |
| 78 |
* @var null |
| 79 |
*/ |
| 80 |
public $schedule = null; |
| 81 |
|
| 82 |
/** |
| 83 |
* @var array |
| 84 |
*/ |
| 85 |
public $query_vars = array(); |
| 86 |
|
| 87 |
/** |
| 88 |
* Table prefixes |
| 89 |
* |
| 90 |
* @var array |
| 91 |
*/ |
| 92 |
protected $_table_prefixes = array(); |
| 93 |
|
| 94 |
/** |
| 95 |
* @var null |
| 96 |
*/ |
| 97 |
public $query = null; |
| 98 |
|
| 99 |
/** |
| 100 |
* @var array |
| 101 |
*/ |
| 102 |
public $global = array(); |
| 103 |
|
| 104 |
/** |
| 105 |
* @var LP_Template |
| 106 |
*/ |
| 107 |
public $template = null; |
| 108 |
|
| 109 |
/** |
| 110 |
* @var LP_Core_API |
| 111 |
*/ |
| 112 |
public $api = null; |
| 113 |
|
| 114 |
/** |
| 115 |
* @var LP_Admin_Core_API |
| 116 |
*/ |
| 117 |
public $admin_api = null; |
| 118 |
|
| 119 |
/** |
| 120 |
* @var string |
| 121 |
*/ |
| 122 |
public $thim_core_version_require = '2.0.0'; |
| 123 |
|
| 124 |
/** |
| 125 |
* |
| 126 |
*/ |
| 127 |
public $theme_support = null; |
| 128 |
|
| 129 |
public $gateways = null; |
| 130 |
|
| 131 |
/** |
| 132 |
* LearnPress constructor. |
| 133 |
*/ |
| 134 |
protected function __construct() { |
| 135 |
if ( self::$_instance ) { |
| 136 |
return; |
| 137 |
} |
| 138 |
self::$_instance = $this; |
| 139 |
|
| 140 |
update_option( 'learnpress_version', $this->version ); |
| 141 |
|
| 142 |
// Define constant . |
| 143 |
$this->plugin_defines(); |
| 144 |
|
| 145 |
// define table prefixes . |
| 146 |
$this->define_tables(); |
| 147 |
|
| 148 |
// Include files . |
| 149 |
$this->includes(); |
| 150 |
|
| 151 |
// hooks . |
| 152 |
$this->init_hooks(); |
| 153 |
} |
| 154 |
|
| 155 |
/** |
| 156 |
* Define constant. |
| 157 |
*/ |
| 158 |
protected function plugin_defines() { |
| 159 |
|
| 160 |
} |
| 161 |
|
| 162 |
/** |
| 163 |
* Defines database table names. |
| 164 |
*/ |
| 165 |
public function define_tables() { |
| 166 |
global $wpdb; |
| 167 |
|
| 168 |
$tables = array( |
| 169 |
'sessions', |
| 170 |
'sections', |
| 171 |
'section_items', |
| 172 |
'user_items', |
| 173 |
'user_itemmeta', |
| 174 |
'user_item_results', |
| 175 |
'order_items', |
| 176 |
'order_itemmeta', |
| 177 |
'quiz_questions', |
| 178 |
'question_answers', |
| 179 |
'question_answermeta', |
| 180 |
'review_logs', |
| 181 |
); |
| 182 |
|
| 183 |
foreach ( $tables as $short_name ) { |
| 184 |
$table_name = $wpdb->prefix . LP_TABLE_PREFIX . $short_name; |
| 185 |
$this->_table_prefixes[ 'tbl_' . $short_name ] = $table_name; |
| 186 |
|
| 187 |
$backward_key = 'learnpress_' . $short_name; |
| 188 |
$wpdb->{$backward_key} = $table_name; |
| 189 |
} |
| 190 |
} |
| 191 |
|
| 192 |
/** |
| 193 |
* Includes needed files. |
| 194 |
*/ |
| 195 |
public function includes() { |
| 196 |
// Include required files load anywhere, both frontend and backend. |
| 197 |
$this->include_files_global(); |
| 198 |
|
| 199 |
// include files when LP ready run - after setup success . |
| 200 |
if ( ! LP_Install::instance()->tables_install_done() ) { |
| 201 |
return; |
| 202 |
} |
| 203 |
|
| 204 |
// Include required files Backend. |
| 205 |
$this->include_files_admin(); |
| 206 |
|
| 207 |
// Include required files Frontend. |
| 208 |
$this->include_files_frontend(); |
| 209 |
|
| 210 |
new LP_Query(); |
| 211 |
} |
| 212 |
|
| 213 |
/** |
| 214 |
* load files anywhere, both frontend and backend |
| 215 |
* |
| 216 |
* @return void |
| 217 |
*/ |
| 218 |
private function include_files_global() { |
| 219 |
require_once 'inc/class-lp-multi-language.php'; |
| 220 |
|
| 221 |
// Filter query . |
| 222 |
require_once 'inc/filters/class-lp-filter.php'; |
| 223 |
require_once 'inc/filters/class-lp-post-type-filter.php'; |
| 224 |
require_once 'inc/filters/class-lp-course-filter.php'; |
| 225 |
require_once 'inc/filters/class-lp-order-filter.php'; |
| 226 |
require_once 'inc/filters/class-lp-section-filter.php'; |
| 227 |
require_once 'inc/filters/class-lp-section-items-filter.php'; |
| 228 |
require_once 'inc/filters/class-lp-question-filter.php'; |
| 229 |
require_once 'inc/filters/class-lp-user-items-filter.php'; |
| 230 |
require_once 'inc/filters/class-lp-quiz-questions-filter.php'; |
| 231 |
require_once 'inc/filters/class-lp-question-answers-filter.php'; |
| 232 |
require_once 'inc/filters/class-lp-question-answermeta-filter.php'; |
| 233 |
|
| 234 |
// Query Database . |
| 235 |
require_once 'inc/databases/class-lp-db.php'; |
| 236 |
require_once 'inc/databases/class-lp-order-db.php'; |
| 237 |
require_once 'inc/databases/class-lp-course-db.php'; |
| 238 |
require_once 'inc/databases/class-lp-lesson-db.php'; |
| 239 |
require_once 'inc/databases/class-lp-section-db.php'; |
| 240 |
require_once 'inc/databases/class-lp-section-items-db.php'; |
| 241 |
require_once 'inc/databases/class-lp-quiz-db.php'; |
| 242 |
require_once 'inc/databases/class-lp-quiz-questions-db.php'; |
| 243 |
require_once 'inc/databases/class-lp-question-answers-db.php'; |
| 244 |
require_once 'inc/databases/class-lp-sessions-db.php'; |
| 245 |
require_once 'inc/databases/class-lp-question-db.php'; |
| 246 |
require_once 'inc/databases/class-lp-user-items-db.php'; |
| 247 |
require_once 'inc/databases/class-lp-user-item-results-db.php'; |
| 248 |
|
| 249 |
// Read files config on folder config . |
| 250 |
require_once 'inc/Helper/Config.php'; |
| 251 |
|
| 252 |
// File system . |
| 253 |
require_once 'inc/class-lp-file-system.php'; |
| 254 |
|
| 255 |
// File helper |
| 256 |
require_once 'inc/class-lp-helper.php'; |
| 257 |
|
| 258 |
// Models |
| 259 |
require_once 'inc/models/class-lp-rest-response.php'; |
| 260 |
include_once 'inc/models/steps/class-lp-group-step.php'; |
| 261 |
include_once 'inc/models/steps/class-lp-step.php'; |
| 262 |
require_once 'inc/models/class-lp-course-extra-info-fast-query-model.php'; |
| 263 |
|
| 264 |
// Handle steps. |
| 265 |
require_once 'inc/handle-steps/class-lp-handle-steps.php'; |
| 266 |
require_once 'inc/handle-steps/class-lp-handle-upgrade-db-steps.php'; |
| 267 |
|
| 268 |
// LP Cache |
| 269 |
require_once 'inc/cache/class-lp-cache.php'; |
| 270 |
require_once 'inc/cache/class-lp-courses-cache.php'; |
| 271 |
require_once 'inc/cache/class-lp-course-cache.php'; |
| 272 |
require_once 'inc/cache/class-lp-quiz-cache.php'; |
| 273 |
|
| 274 |
// Background processes. |
| 275 |
require_once 'inc/libraries/wp-background-process/wp-background-processing.php'; |
| 276 |
require_once 'inc/background-process/abstract-lp-async-request.php'; |
| 277 |
require_once 'inc/background-process/class-lp-background-single-course.php'; |
| 278 |
require_once 'inc/background-process/class-lp-background-single-email.php'; |
| 279 |
|
| 280 |
// Assets object |
| 281 |
require_once 'inc/class-lp-asset-key.php'; |
| 282 |
require_once 'inc/abstracts/abstract-assets.php'; |
| 283 |
|
| 284 |
// Debug class |
| 285 |
require_once 'inc/class-lp-debug.php'; |
| 286 |
|
| 287 |
require_once 'inc/class-lp-settings.php'; |
| 288 |
require_once 'inc/abstract-settings.php'; |
| 289 |
require_once 'inc/settings/abstract-settings-page.php'; |
| 290 |
require_once 'inc/settings/class-lp-settings-courses.php'; |
| 291 |
require_once 'inc/class-lp-global.php'; |
| 292 |
require_once 'inc/class-lp-datetime.php'; |
| 293 |
|
| 294 |
// Register custom-post-type and taxonomies . |
| 295 |
require_once 'inc/custom-post-types/abstract.php'; |
| 296 |
require_once 'inc/custom-post-types/course.php'; |
| 297 |
require_once 'inc/custom-post-types/lesson.php'; |
| 298 |
require_once 'inc/custom-post-types/quiz.php'; |
| 299 |
require_once 'inc/custom-post-types/question.php'; |
| 300 |
require_once 'inc/custom-post-types/order.php'; |
| 301 |
|
| 302 |
require_once 'inc/interfaces/interface-curd.php'; |
| 303 |
require_once 'inc/abstracts/abstract-array-access.php'; |
| 304 |
require_once 'inc/abstracts/abstract-object-data.php'; |
| 305 |
require_once 'inc/abstracts/abstract-post-data.php'; |
| 306 |
|
| 307 |
require_once 'inc/curds/class-lp-course-curd.php'; |
| 308 |
require_once 'inc/curds/class-lp-section-curd.php'; |
| 309 |
require_once 'inc/curds/class-lp-lesson-curd.php'; |
| 310 |
require_once 'inc/curds/class-lp-quiz-curd.php'; |
| 311 |
require_once 'inc/curds/class-lp-question-curd.php'; |
| 312 |
require_once 'inc/curds/class-lp-order-curd.php'; |
| 313 |
require_once 'inc/curds/class-lp-user-curd.php'; |
| 314 |
require_once 'inc/curds/class-lp-user-item-curd.php'; |
| 315 |
|
| 316 |
require_once 'inc/course/class-lp-course-item.php'; |
| 317 |
require_once 'inc/question/class-lp-question.php'; |
| 318 |
require_once 'inc/course/class-lp-course-section.php'; |
| 319 |
require_once 'inc/course/class-lp-course-no-required-enroll.php'; |
| 320 |
require_once 'inc/user-item/class-lp-user-item.php'; |
| 321 |
require_once 'inc/user-item/class-lp-user-item-course.php'; |
| 322 |
|
| 323 |
require_once 'inc/lp-deprecated.php'; // Will remove if Eduma and guest update all 4.0.0 |
| 324 |
require_once 'inc/lp-core-functions.php'; |
| 325 |
require_once 'inc/class-lp-autoloader.php'; |
| 326 |
|
| 327 |
require_once 'inc/lp-webhooks.php'; |
| 328 |
require_once 'inc/class-lp-request-handler.php'; |
| 329 |
|
| 330 |
require_once 'inc/admin/helpers/class-lp-plugins-helper.php'; |
| 331 |
|
| 332 |
// Todo: tungnx check those files. |
| 333 |
require_once 'inc/abstracts/abstract-object-query.php'; |
| 334 |
require_once 'inc/class-lp-course-query.php'; |
| 335 |
require_once 'inc/abstracts/abstract-addon.php'; |
| 336 |
require_once 'inc/class-lp-thumbnail-helper.php'; |
| 337 |
require_once 'inc/cache.php'; |
| 338 |
|
| 339 |
// Class handle check db of LP need to upgrade? |
| 340 |
require_once 'inc/admin/class-lp-updater.php'; |
| 341 |
|
| 342 |
require_once 'inc/course/lp-course-functions.php'; |
| 343 |
require_once 'inc/course/abstract-course.php'; |
| 344 |
require_once 'inc/course/class-lp-course.php'; |
| 345 |
//require_once 'inc/course/class-lp-course-utils.php'; |
| 346 |
require_once 'inc/quiz/lp-quiz-functions.php'; |
| 347 |
require_once 'inc/quiz/class-lp-quiz.php'; |
| 348 |
require_once 'inc/lesson/lp-lesson-functions.php'; |
| 349 |
require_once 'inc/order/lp-order-functions.php'; |
| 350 |
require_once 'inc/order/class-lp-order.php'; |
| 351 |
|
| 352 |
require_once 'inc/user/lp-user-functions.php'; |
| 353 |
require_once 'inc/user/class-lp-user-factory.php'; |
| 354 |
require_once 'inc/user/abstract-lp-user.php'; |
| 355 |
require_once 'inc/user/class-lp-user.php'; |
| 356 |
require_once 'inc/user/class-lp-profile.php'; |
| 357 |
require_once 'inc/user-item/class-lp-user-item.php'; |
| 358 |
require_once 'inc/user-item/class-lp-user-item-course.php'; |
| 359 |
require_once 'inc/user-item/class-lp-user-item-quiz.php'; |
| 360 |
require_once 'inc/user-item/class-lp-quiz-results.php'; |
| 361 |
require_once 'inc/class-lp-session-handler.php'; |
| 362 |
|
| 363 |
require_once 'inc/class-lp-shortcodes.php'; |
| 364 |
|
| 365 |
// include template functions . |
| 366 |
require_once 'inc/lp-template-functions.php'; |
| 367 |
require_once 'inc/templates/abstract-template.php'; |
| 368 |
//require_once 'inc/class-lp-template.php'; |
| 369 |
|
| 370 |
// Cart |
| 371 |
require_once 'inc/cart/class-lp-cart.php'; |
| 372 |
require_once 'inc/cart/lp-cart-functions.php'; |
| 373 |
|
| 374 |
// Block Templates |
| 375 |
require_once 'inc/block-template/class-block-until.php'; |
| 376 |
require_once 'inc/block-template/class-block-controller.php'; |
| 377 |
|
| 378 |
// API |
| 379 |
require_once 'inc/abstracts/abstract-rest-api.php'; |
| 380 |
require_once 'inc/abstracts/abstract-rest-controller.php'; |
| 381 |
require_once 'inc/rest-api/class-lp-core-api.php'; |
| 382 |
require_once 'inc/rest-api/class-lp-admin-core-api.php'; |
| 383 |
|
| 384 |
// include_once 'inc/theme-support/class-theme-support-base.php'; |
| 385 |
// include_once 'inc/class-lp-theme-support.php'; |
| 386 |
|
| 387 |
/** Jwt */ |
| 388 |
include_once 'inc/jwt/class-jwt-auth.php'; |
| 389 |
|
| 390 |
require_once 'inc/class-lp-widget.php'; |
| 391 |
require_once 'inc/lp-widget-functions.php'; |
| 392 |
|
| 393 |
// For plugin Elementor |
| 394 |
if ( defined( 'ELEMENTOR_VERSION' ) ) { |
| 395 |
require_once 'inc/external-plugin/elementor/class-lp-elementor.php'; |
| 396 |
} |
| 397 |
|
| 398 |
// TODO: update frontend editor before move to function include_files_admin. |
| 399 |
require_once 'inc/admin/views/meta-boxes/class-lp-meta-box.php'; |
| 400 |
|
| 401 |
require_once 'inc/class-lp-page-controller.php'; |
| 402 |
|
| 403 |
require_once 'inc/gateways/class-lp-gateway-abstract.php'; |
| 404 |
require_once 'inc/gateways/class-lp-gateways.php'; |
| 405 |
} |
| 406 |
|
| 407 |
/** |
| 408 |
* Include file run on backend |
| 409 |
*/ |
| 410 |
private function include_files_admin() { |
| 411 |
if ( ! is_admin() ) { |
| 412 |
return; |
| 413 |
} |
| 414 |
|
| 415 |
require_once 'inc/admin/class-lp-admin-notice.php'; |
| 416 |
|
| 417 |
// File handle install LP |
| 418 |
require_once 'inc/class-lp-install.php'; |
| 419 |
|
| 420 |
// Meta box helper |
| 421 |
require_once 'inc/admin/meta-box/class-lp-meta-box-helper.php'; |
| 422 |
|
| 423 |
require_once 'inc/admin/class-lp-admin.php'; |
| 424 |
// require_once 'inc/admin/settings/abstract-settings-page.php'; |
| 425 |
|
| 426 |
require_once 'inc/admin/class-lp-admin-ajax.php'; |
| 427 |
} |
| 428 |
|
| 429 |
/** |
| 430 |
* Include file run on frontend |
| 431 |
*/ |
| 432 |
private function include_files_frontend() { |
| 433 |
if ( is_admin() ) { |
| 434 |
return; |
| 435 |
} |
| 436 |
|
| 437 |
require_once 'inc/class-lp-assets.php'; |
| 438 |
|
| 439 |
require_once 'inc/course/class-model-user-can-view-course-item.php'; |
| 440 |
|
| 441 |
require_once 'inc/class-lp-ajax.php'; |
| 442 |
} |
| 443 |
|
| 444 |
/** |
| 445 |
* Initial common hooks |
| 446 |
*/ |
| 447 |
public function init_hooks() { |
| 448 |
if ( 0 !== strcmp( LP_PLUGIN_BASENAME, 'learnpress/learnpress.php' ) ) { |
| 449 |
add_action( 'admin_notices', array( $this, 'error' ) ); |
| 450 |
} |
| 451 |
|
| 452 |
// Add links setting|document|addon on plugins page. |
| 453 |
add_filter( 'plugin_action_links_' . LP_PLUGIN_BASENAME, array( $this, 'plugin_links' ) ); |
| 454 |
|
| 455 |
register_activation_hook( LP_PLUGIN_FILE, array( $this, 'on_activate' ) ); |
| 456 |
register_deactivation_hook( LP_PLUGIN_FILE, array( $this, 'on_deactivate' ) ); |
| 457 |
// add_action( 'deactivate_' . LP_PLUGIN_BASENAME, array( $this, 'on_deactivate' ) ); |
| 458 |
|
| 459 |
if ( ! LP_Install::instance()->tables_install_done() ) { |
| 460 |
return; |
| 461 |
} |
| 462 |
|
| 463 |
add_action( 'wp_loaded', array( $this, 'wp_loaded' ), 20 ); |
| 464 |
add_action( 'after_setup_theme', array( $this, 'setup_theme' ) ); |
| 465 |
add_action( 'plugins_loaded', array( $this, 'plugin_loaded' ), - 10 ); |
| 466 |
// add_action( 'init', array( $this, 'wp_init' ), 10 ); |
| 467 |
|
| 468 |
// Check require version thim-core. |
| 469 |
add_action( 'before_thim_core_init', array( $this, 'check_thim_core_version_require' ) ); |
| 470 |
} |
| 471 |
|
| 472 |
/** |
| 473 |
* Add links to Documentation and Extensions in plugin's list of action links |
| 474 |
* |
| 475 |
* @since 4.3.11 |
| 476 |
* |
| 477 |
* @param array $links Array of action links |
| 478 |
* |
| 479 |
* @return array |
| 480 |
*/ |
| 481 |
public function plugin_links( array $links ): array { |
| 482 |
$links[] = sprintf( '<a href="%s">%s</a>', admin_url( 'admin.php?page=learn-press-settings' ), __( 'Settings', 'learnpress' ) ); |
| 483 |
$links[] = sprintf( '<a href="%s" target="_blank">%s</a>', 'https://docspress.thimpress.com/learnpress-4-0/', __( 'Documentation', 'learnpress' ) ); |
| 484 |
$links[] = sprintf( '<a href="%s" target="_blank">%s</a>', get_admin_url() . '/admin.php?page=learn-press-addons', __( 'Add-ons', 'learnpress' ) ); |
| 485 |
|
| 486 |
return $links; |
| 487 |
} |
| 488 |
|
| 489 |
public function error() { |
| 490 |
?> |
| 491 |
<div class="error"> |
| 492 |
<p> |
| 493 |
<?php |
| 494 |
printf( |
| 495 |
__( |
| 496 |
'LearnPress plugin base directory must be <strong>learnpress/learnpres.php</strong> (case sensitive) to ensure all functions work properly and fully operational (currently <strong>%s</strong>)', |
| 497 |
'learnpress' |
| 498 |
), |
| 499 |
LP_PLUGIN_BASENAME |
| 500 |
); |
| 501 |
?> |
| 502 |
</p> |
| 503 |
</div> |
| 504 |
<?php |
| 505 |
} |
| 506 |
|
| 507 |
/** |
| 508 |
* Maybe flush rewrite rules |
| 509 |
*/ |
| 510 |
public function wp_init() { |
| 511 |
/*if ( LP()->session->flush_rewrite_rules ) { |
| 512 |
flush_rewrite_rules(); |
| 513 |
unset( LP()->session->flush_rewrite_rules ); |
| 514 |
}*/ |
| 515 |
} |
| 516 |
|
| 517 |
/** |
| 518 |
* Get base name of plugin from file. |
| 519 |
* |
| 520 |
* @return string |
| 521 |
*/ |
| 522 |
// private function plugin_basename() { |
| 523 |
// return learn_press_plugin_basename( __FILE__ ); |
| 524 |
// } |
| 525 |
|
| 526 |
/** |
| 527 |
* Magic function to get Learnpress data. |
| 528 |
* |
| 529 |
* @param $key |
| 530 |
* |
| 531 |
* @return bool|LP_Checkout|LP_Course|LP_Emails|LP_User|LP_User_Guest|mixed |
| 532 |
* @deprecated since 3.0.0 |
| 533 |
* @editor tungnx |
| 534 |
* @modify 4.1.3.1 - comment |
| 535 |
*/ |
| 536 |
/* |
| 537 |
public function __get( $key ) { |
| 538 |
return false; |
| 539 |
}*/ |
| 540 |
|
| 541 |
/** |
| 542 |
* Trigger this function while activating Learnpress. |
| 543 |
* |
| 544 |
* @since 3.0.0 |
| 545 |
* @version 4.1.4.1 |
| 546 |
*/ |
| 547 |
public function on_activate() { |
| 548 |
LP_Install::instance()->on_activate(); |
| 549 |
// do_action( 'learn-press/activate', $this ); |
| 550 |
} |
| 551 |
|
| 552 |
/** |
| 553 |
* Trigger this function while deactivating Learnpress. |
| 554 |
* |
| 555 |
* $since 3.0.0 |
| 556 |
* |
| 557 |
* @hook learn_press_deactivate |
| 558 |
*/ |
| 559 |
public function on_deactivate() { |
| 560 |
do_action( 'learn-press/deactivate', $this ); |
| 561 |
} |
| 562 |
|
| 563 |
/** |
| 564 |
* Trigger WP loaded actions. |
| 565 |
* |
| 566 |
* @since 3.0.0 |
| 567 |
*/ |
| 568 |
public function wp_loaded() { |
| 569 |
if ( $this->is_request( 'frontend' ) ) { |
| 570 |
$this->gateways = LP_Gateways::instance()->get_available_payment_gateways(); |
| 571 |
} |
| 572 |
} |
| 573 |
|
| 574 |
/** |
| 575 |
* Setup courses thumbnail. |
| 576 |
* |
| 577 |
* @since 3.0.0 |
| 578 |
*/ |
| 579 |
public function setup_theme() { |
| 580 |
if ( ! current_theme_supports( 'post-thumbnails' ) ) { |
| 581 |
add_theme_support( 'post-thumbnails' ); |
| 582 |
} |
| 583 |
add_post_type_support( LP_COURSE_CPT, 'thumbnail' ); |
| 584 |
|
| 585 |
$size = LP_Settings::get_option( |
| 586 |
'course_thumbnail_dimensions', |
| 587 |
array( |
| 588 |
500, |
| 589 |
300, |
| 590 |
) |
| 591 |
); |
| 592 |
|
| 593 |
$size = array_values( (array) $size ); |
| 594 |
|
| 595 |
add_image_size( 'course_thumbnail', $size[0], $size[1], true ); |
| 596 |
} |
| 597 |
|
| 598 |
/** |
| 599 |
* Trigger Learnpress loaded actions. |
| 600 |
* |
| 601 |
* @since 3.0.0 |
| 602 |
* @version 1.0.2 |
| 603 |
* @editor tungnx |
| 604 |
*/ |
| 605 |
public function plugin_loaded() { |
| 606 |
do_action( 'learnpress/hook/before-addons-call-hook-learnpress-ready' ); |
| 607 |
|
| 608 |
// Polylang |
| 609 |
if ( defined( 'POLYLANG_VERSION' ) ) { |
| 610 |
require_once 'inc/external-plugin/polylang/class-lp-polylang.php'; |
| 611 |
LP_Polylang::instance(); |
| 612 |
} |
| 613 |
|
| 614 |
$this->init(); |
| 615 |
|
| 616 |
// Todo: tungnx - remove this code after handle ajax on page learn-press-addons |
| 617 |
// require_once 'inc/background-process/class-lp-background-query-items.php'; |
| 618 |
// require_once 'inc/background-process/class-lp-background-installer.php'; |
| 619 |
|
| 620 |
require_once 'inc/lp-template-hooks.php'; |
| 621 |
|
| 622 |
/** |
| 623 |
* Check version addons valid version require. |
| 624 |
* If not valid will be to deactivate. |
| 625 |
* Reload page, so not affect to hook "learn-press/ready" |
| 626 |
*/ |
| 627 |
$addons_valid = true; |
| 628 |
$plugins = get_option( 'active_plugins' ); |
| 629 |
|
| 630 |
$list_lp_addon_activated = preg_grep( '/^learnpress-.*/i', $plugins ); |
| 631 |
|
| 632 |
// Remove hook deactivate addon assignments v3. |
| 633 |
add_action( |
| 634 |
'deactivate_learnpress-assignments/learnpress-assignments.php', |
| 635 |
array( $this, 'lp_assignment_install' ), |
| 636 |
- 10 |
| 637 |
); |
| 638 |
|
| 639 |
foreach ( $list_lp_addon_activated as $lp_addon ) { |
| 640 |
$lp_addon_info = get_file_data( |
| 641 |
WP_PLUGIN_DIR . '/' . $lp_addon, |
| 642 |
array( |
| 643 |
'Require_LP_Version' => 'Require_LP_Version', |
| 644 |
'Version' => 'Version', |
| 645 |
) |
| 646 |
); |
| 647 |
|
| 648 |
// $lp_addon_info = get_plugin_data( WP_PLUGIN_DIR . '/' . $lp_addon ); |
| 649 |
$lp_addon_version = $lp_addon_info['Version']; |
| 650 |
|
| 651 |
$addon = new Lp_Addon(); |
| 652 |
$addon->version = $lp_addon_version; |
| 653 |
$addon->plugin_base = $lp_addon; |
| 654 |
$addon->require_version = $lp_addon_info['Require_LP_Version']; |
| 655 |
$addon_valid = $addon->check_require_version_addon(); |
| 656 |
|
| 657 |
if ( $addons_valid ) { |
| 658 |
$addon_valid = $addon->check_require_version_lp(); |
| 659 |
} |
| 660 |
|
| 661 |
if ( ! $addon_valid ) { |
| 662 |
$addons_valid = false; |
| 663 |
} |
| 664 |
} |
| 665 |
// End check addons valid. |
| 666 |
|
| 667 |
if ( ! $addons_valid ) { |
| 668 |
return; |
| 669 |
} |
| 670 |
|
| 671 |
// let third parties know that we're ready . |
| 672 |
do_action( 'learn-press/ready' ); |
| 673 |
} |
| 674 |
|
| 675 |
/** |
| 676 |
* Remove hook deactivate addon assignments v3. |
| 677 |
*/ |
| 678 |
public function lp_assignment_install() { |
| 679 |
remove_action( 'deactivate_learnpress-assignments/learnpress-assignments.php', 'lp_assignment_remove' ); |
| 680 |
} |
| 681 |
|
| 682 |
/** |
| 683 |
* Get instance of class LP_Template. |
| 684 |
* |
| 685 |
* @param string $type |
| 686 |
* |
| 687 |
* @return LP_Template_Course|LP_Template_Profile|LP_Template_General|LP_Abstract_Template|LP_Template |
| 688 |
* |
| 689 |
* @throws Exception |
| 690 |
* @since 3.3.0 |
| 691 |
*/ |
| 692 |
public function template( $type = '' ) { |
| 693 |
if ( ! $this->template ) { |
| 694 |
$this->template = LP_Template::instance(); |
| 695 |
} |
| 696 |
|
| 697 |
return isset( $this->template[ $type ] ) ? $this->template[ $type ] : $this->template; |
| 698 |
} |
| 699 |
|
| 700 |
/** |
| 701 |
* Init LearnPress when WP initialises |
| 702 |
*/ |
| 703 |
public function init() { |
| 704 |
$this->api = new LP_Core_API(); |
| 705 |
$this->admin_api = new LP_Admin_Core_API(); |
| 706 |
// $this->theme_support = LP_Theme_Support::instance(); |
| 707 |
|
| 708 |
// $this->view_log(); |
| 709 |
|
| 710 |
$this->get_session(); |
| 711 |
|
| 712 |
$this->settings = $this->settings(); |
| 713 |
|
| 714 |
if ( $this->is_request( 'frontend' ) ) { |
| 715 |
$this->get_cart(); |
| 716 |
} |
| 717 |
|
| 718 |
// Email hook notify |
| 719 |
include_once 'inc/emails/class-lp-email-hooks.php'; |
| 720 |
// Init emails |
| 721 |
LP_Emails::instance(); |
| 722 |
} |
| 723 |
|
| 724 |
/** |
| 725 |
* Get session object instance. |
| 726 |
* |
| 727 |
* @return mixed |
| 728 |
*/ |
| 729 |
public function get_session() { |
| 730 |
if ( ! $this->session ) { |
| 731 |
$this->session = LP_Session_Handler::instance(); |
| 732 |
} |
| 733 |
|
| 734 |
return $this->session; |
| 735 |
} |
| 736 |
|
| 737 |
/** |
| 738 |
* Get settings object instance. |
| 739 |
* |
| 740 |
* @return bool|LP_Settings |
| 741 |
*/ |
| 742 |
public function settings() { |
| 743 |
return LP_Settings::instance(); |
| 744 |
} |
| 745 |
|
| 746 |
/** |
| 747 |
* Get cart object instance for online learning market. |
| 748 |
* |
| 749 |
* @return LP_Cart |
| 750 |
*/ |
| 751 |
public function get_cart() : LP_Cart { |
| 752 |
if ( ! $this->cart ) { |
| 753 |
$this->cart = LP_Cart::instance(); |
| 754 |
} |
| 755 |
|
| 756 |
return $this->cart; |
| 757 |
} |
| 758 |
|
| 759 |
/** |
| 760 |
* Check type of request. |
| 761 |
* |
| 762 |
* @param string $type ajax, frontend or admin. |
| 763 |
* |
| 764 |
* @return bool |
| 765 |
*/ |
| 766 |
public function is_request( $type ) { |
| 767 |
switch ( $type ) { |
| 768 |
case 'admin': |
| 769 |
return is_admin(); |
| 770 |
case 'ajax': |
| 771 |
return defined( 'LP_DOING_AJAX' ); |
| 772 |
case 'cron': |
| 773 |
return defined( 'DOING_CRON' ); |
| 774 |
case 'frontend': |
| 775 |
return ( ! is_admin() || defined( 'LP_DOING_AJAX' ) ) && ! defined( 'DOING_CRON' ); |
| 776 |
default: |
| 777 |
return strtolower( $_SERVER['REQUEST_METHOD'] ) == $type; |
| 778 |
} |
| 779 |
} |
| 780 |
|
| 781 |
/** |
| 782 |
* Get the plugin url. |
| 783 |
* |
| 784 |
* @param string $sub_dir |
| 785 |
* |
| 786 |
* @return string |
| 787 |
*/ |
| 788 |
public function plugin_url( $sub_dir = '' ) { |
| 789 |
return LP_PLUGIN_URL . ( $sub_dir ? "{$sub_dir}" : '' ); |
| 790 |
} |
| 791 |
|
| 792 |
/** |
| 793 |
* Get the plugin path. |
| 794 |
* |
| 795 |
* @param string $sub_dir |
| 796 |
* |
| 797 |
* @return string |
| 798 |
*/ |
| 799 |
public function plugin_path( $sub_dir = '' ) { |
| 800 |
return LP_PLUGIN_PATH . ( $sub_dir ? "{$sub_dir}" : '' ); |
| 801 |
} |
| 802 |
|
| 803 |
/** |
| 804 |
* Get checkout object instance |
| 805 |
* |
| 806 |
* @return LP_Checkout |
| 807 |
*/ |
| 808 |
public function checkout() { |
| 809 |
return LP_Checkout::instance(); |
| 810 |
} |
| 811 |
|
| 812 |
/** |
| 813 |
* Short way to return image file is located in LearnPress directory. |
| 814 |
* |
| 815 |
* @param string |
| 816 |
* |
| 817 |
* @return string |
| 818 |
*/ |
| 819 |
public function image( $file ) { |
| 820 |
if ( ! preg_match( '/.(jpg|png)$/', $file ) ) { |
| 821 |
$file .= '.jpg'; |
| 822 |
} |
| 823 |
|
| 824 |
return $this->plugin_url( "assets/images/{$file}" ); |
| 825 |
} |
| 826 |
|
| 827 |
/** |
| 828 |
* Check require version thim-core |
| 829 |
*/ |
| 830 |
public function check_thim_core_version_require() { |
| 831 |
// Get thim-core info for LP check . |
| 832 |
include_once ABSPATH . 'wp-admin/includes/plugin.php'; |
| 833 |
$thim_core_info = get_file_data( |
| 834 |
WP_PLUGIN_DIR . '/thim-core/thim-core.php', |
| 835 |
array( |
| 836 |
'Name' => 'Plugin Name', |
| 837 |
'Require_LP_Version' => 'Require_LP_Version', |
| 838 |
'Version' => 'Version', |
| 839 |
) |
| 840 |
); |
| 841 |
|
| 842 |
if ( version_compare( $this->thim_core_version_require, $thim_core_info['Version'], '>' ) ) { |
| 843 |
deactivate_plugins( 'thim-core/thim-core.php' ); |
| 844 |
|
| 845 |
if ( isset( $_GET['activate'] ) ) { |
| 846 |
unset( $_GET['activate'] ); |
| 847 |
} |
| 848 |
|
| 849 |
$message = sprintf( |
| 850 |
'%s %s You can download %s. Read guide on %s', |
| 851 |
'LP4 require version Thim-core:', |
| 852 |
$this->thim_core_version_require, |
| 853 |
'<a href="https://thimpresswp.github.io/thim-core/thim-core.zip">latest version</a>', |
| 854 |
'<a href="https://docspress.thimpress.com/upgrade-database-how-to-fix-some-issue/">here</a>' |
| 855 |
); |
| 856 |
?> |
| 857 |
<div class="notice notice-error"> |
| 858 |
<p><?php echo wp_kses_post( $message ); ?></p> |
| 859 |
</div> |
| 860 |
<?php |
| 861 |
die; |
| 862 |
} |
| 863 |
} |
| 864 |
|
| 865 |
/** |
| 866 |
* Main plugin instance. |
| 867 |
* |
| 868 |
* @return LearnPress |
| 869 |
*/ |
| 870 |
public static function instance() { |
| 871 |
if ( is_null( self::$_instance ) ) { |
| 872 |
self::$_instance = new self(); |
| 873 |
} |
| 874 |
|
| 875 |
return self::$_instance; |
| 876 |
} |
| 877 |
|
| 878 |
public function admin_notice_require_addon_version() { |
| 879 |
?> |
| 880 |
<div class="notice notice-error"> |
| 881 |
<p><?php echo( '<strong>LearnPress version ' . LEARNPRESS_VERSION . ' require Addon</strong> version 4.0.0 or higher' ); ?></p> |
| 882 |
</div> |
| 883 |
<?php |
| 884 |
} |
| 885 |
} |
| 886 |
} |
| 887 |
|
| 888 |
/** |
| 889 |
* Short way to load main instance of plugin |
| 890 |
* |
| 891 |
* @return LearnPress |
| 892 |
* @since 1.0 |
| 893 |
* @author thimpress |
| 894 |
*/ |
| 895 |
function LP() { |
| 896 |
return LearnPress::instance(); |
| 897 |
} |
| 898 |
|
| 899 |
/** |
| 900 |
* Done! entry point of the plugin |
| 901 |
* Create new instance of LearnPress and put it to global |
| 902 |
*/ |
| 903 |
$GLOBALS['LearnPress'] = LP(); |
| 904 |
|